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
+36.3k Golang : How to split or chunking a file to smaller pieces?
+13.7k Golang : Activate web camera and broadcast out base64 encoded images
+16.5k Golang : File path independent of Operating System
+6.6k Golang : Totalize or add-up an array or slice example
+12.2k Golang : Split strings into command line arguments
+7.1k Golang : A simple forex opportunities scanner
+19.9k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+10k Golang : Get escape characters \u form from unicode characters
+19.1k Mac OSX : Homebrew and Golang
+15k Golang : Search folders for file recursively with wildcard support
+6.6k Golang : How to determine if request or crawl is from Google robots
+8.3k Golang : Check if integer is power of four example