Golang flag.Value type examples
package flag
Value is the interface to the dynamic value stored in a flag. (The default value is represented as a string.)
If a Value has an IsBoolFlag() bool method returning true, the command-line parser makes -name equivalent to -name=true rather than using the next command-line argument.
Golang flag.Value type usage examples
func lookupStringSlice(name string, set *flag.FlagSet) []string {
f := set.Lookup(name)
if f != nil {
return (f.Value.(*StringSlice)).Value()
}
return nil
}
func lookupIntSlice(name string, set *flag.FlagSet) []int {
f := set.Lookup(name)
if f != nil {
return (f.Value.(*IntSlice)).Value()
}
return nil
}
func lookupGeneric(name string, set *flag.FlagSet) interface{} {
f := set.Lookup(name)
if f != nil {
return f.Value
}
return nil
}
func lookupBool(name string, set *flag.FlagSet) bool {
f := set.Lookup(name)
if f != nil {
val, err := strconv.ParseBool(f.Value.String())
if err != nil {
return false
}
return val
}
return false
}
Reference :
Advertisement
Something interesting
Tutorials
+10.2k Golang : Bcrypting password
+7.6k Javascript : Push notifications to browser with Push.js
+13k Golang : Calculate elapsed years or months since a date
+16.3k Golang : convert string or integer to big.Int type
+19.2k Golang : Execute shell command
+4.6k JavaScript : Rounding number to decimal formats to display currency
+15.9k Golang : Get file permission
+16.8k Golang : read gzipped http response
+30.9k error: trying to remove "yum", which is protected
+7.6k SSL : How to check if current certificate is sha1 or sha2 from command line
+10.4k Golang : Meaning of omitempty in struct's field tag
+28.6k Get file path of temporary file in Go