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
+11.7k How to tell if a binary(executable) file or web application is built with Golang?
+30.6k Golang : Remove characters from string example
+14.5k How to automatically restart your crashed Golang server
+8.3k Golang : Count leading or ending zeros(any item of interest) example
+18.4k Golang : How to remove certain lines from a file
+18.1k Golang : Convert IPv4 address to decimal number(base 10) or integer
+20.5k nginx: [emerg] unknown directive "passenger_enabled"
+7.2k Golang : Check if one string(rune) is permutation of another string(rune)
+28.2k Golang : Connect to database (MySQL/MariaDB) server
+11.1k Golang : Fix go.exe is not compatible with the version of Windows you're running
+5.2k Golang : Convert lines of string into list for delete and insert operation
+9.8k Golang : Get current, epoch time and display by year, month and day