Golang flag.IntVar() function example
package flag
IntVar defines an int flag with specified name (2nd parameter) , default value (3rd parameter), and usage string (4th parameter). The argument p (1st parameter) points to an int variable in which to store the value of the flag.
Golang flag.IntVar() function usage example
package main
import (
"flag"
"fmt"
)
var portnum int
func main() {
flag.IntVar(&portnum, "port", 8080, "The port number to serve HTTP.")
fmt.Println(flag.Lookup("port")) // print Flag struct
fmt.Println("port number : ", portnum)
}
Output :
&{port The port number to serve HTTP. 8080 8080}
port number : 8080
Reference :
Advertisement
Something interesting
Tutorials
+22.2k Golang : Securing password with salt
+11.5k Golang : Generate DSA private, public key and PEM files example
+13.4k Golang : Read from buffered reader until specific number of bytes
+13.8k Golang : Gin framework accept query string by post request example
+35.3k Golang : Strip slashes from string example
+10.8k Android Studio : Checkbox for user to select options example
+10.6k Golang : Allow Cross-Origin Resource Sharing request
+5.9k Golang : Generate multiplication table from an integer example
+7.9k Golang : Get today's weekday name and calculate target day distance example
+7.8k Golang : Scan files for certain pattern and rename part of the files
+8.5k Golang : How to check if input string is a word?
+15.2k Golang : Accurate and reliable decimal calculations