package asaModels import ( "errors" "net" ) type PacketTracerTCP struct { Input string `json:"input"` SourceIP string `json:"src-ip"` SourcePort int `json:"src-port" binding:"required"` DestIP string `json:"dest-ip"` DestPort int `json:"dest-port" binding:"required"` Detailed bool `json:"detailed"` XML bool `json:"XML"` } func addE(e *string, s string) { if *e != "" { *e = *e + "\n" } *e = *e + s } func (p *PacketTracerTCP) Valid() error { e := new(string) if p.Input == "" { *e = "input field is required; defines input interface for packet-tracer" } sip := net.ParseIP(p.SourceIP) if sip == nil { addE(e, "src-ip field is not a valid IP address") } if p.SourcePort < 0 || p.SourcePort > 65535 { addE(e, "src-port must be >= 0 && < 65535") } dip := net.ParseIP(p.DestIP) if dip == nil { addE(e, "dest-ip field is not a valid IP address") } if p.DestPort < 0 || p.DestPort > 65535 { addE(e, "dest-port must be >= 0 && < 65535") } if *e != "" { return errors.New(*e) } return nil }