github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/cmdutil/network_flags.go (about) 1 package cmdutil 2 3 import "net" 4 5 // NetworkAddressFlag represents a network address in host:port format. 6 type NetworkAddressFlag struct { 7 Address string 8 Host string 9 Port string 10 Specified bool 11 } 12 13 // Set implements flag.Value.Set 14 func (na *NetworkAddressFlag) Set(v string) error { 15 host, port, err := net.SplitHostPort(v) 16 if err != nil { 17 na.Host = v 18 na.Port = "0" 19 } else { 20 na.Host = host 21 na.Port = port 22 } 23 na.Address = v 24 na.Specified = true 25 return nil 26 } 27 28 // String implements flag.Value.String 29 func (na *NetworkAddressFlag) String() string { 30 return na.Address 31 } 32 33 // Get implements flag.Value.Get 34 func (na *NetworkAddressFlag) Get() interface{} { 35 return na.String() 36 }