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
+8.1k Golang : Multiplexer with net/http and map
+7.4k Linux : How to fix Brother HL-1110 printing blank page problem
+30.5k Golang : Generate random string
+7.8k Golang : Lock executable to a specific machine with unique hash of the machine
+3.6k Java : Get FX sentiment from website example
+9.1k Golang : Get curl -I or head data from URL example
+9.8k Golang : Qt get screen resolution and display on center example
+15.3k Golang : How to get Unix file descriptor for console and file
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+16k Golang : Read large file with bufio.Scanner cause token too long error
+5.3k Golang : Get FX sentiment from website example