Golang flag.Args() function examples
package flag
Args returns the non-flag command-line arguments.
Golang flag.Args() function usage examples
Example 1:
func main() {
flag.Parse()
if len(flag.Args()) < 3 {
fmt.Println("Usage: hello_world [-port portnumber] [-write] servername bucketname key")
}
}
Example 2:
for _, name := range flag.Args() {
// Is it a directory?
fi, err := os.Stat(name)
if err != nil {
fmt.Printf("error walking tree: %s", err)
continue
}
if fi.IsDir() {
dirs = true
} else {
files = true
}
}
Reference :
Advertisement
Something interesting
Tutorials
+5k Python : Convert(cast) bytes to string example
+24.1k Golang : Upload to S3 with official aws-sdk-go package
+21.1k Golang : For loop continue,break and range
+9.3k Golang : Temperatures conversion example
+13.4k Golang : Increment string example
+8.9k Golang : Sort lines of text example
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+30.5k Get client IP Address in Go
+11.6k Golang : Fuzzy string search or approximate string matching example
+6k Golang : Experimenting with the Rejang script
+19.2k Golang : Delete item from slice based on index/key position
+17k Golang : How to save log messages to file?