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
+11.8k Golang : GTK Input dialog box examples
+6.3k Unix/Linux : Use netstat to find out IP addresses served by your website server
+21.4k Curl usage examples with Golang
+36.3k Golang : How to split or chunking a file to smaller pieces?
+11.6k Golang : Surveillance with web camera and OpenCV
+10.6k Golang : Flip coin example
+16.5k Golang : Get IP addresses of a domain name
+26.9k Golang : Force your program to run with root permissions
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+22.7k Golang : Set and Get HTTP request headers example
+9.7k Golang : Detect number of active displays and the display's resolution
+8.7k Golang : Find duplicate files with filepath.Walk