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
+15.9k Golang : Get file permission
+9.1k Golang : Intercept and compare HTTP response code example
+12.7k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+10.9k Golang : Sieve of Eratosthenes algorithm
+7.9k Swift : Convert (cast) String to Float
+8.2k Golang : Add build version and other information in executables
+8.7k Golang : Find duplicate files with filepath.Walk
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+13.5k Golang : Read XML elements data with xml.CharData example
+12k Golang : Decompress zlib file example
+7.5k Golang : How to stop user from directly running an executable file?
+18.5k Golang : Example for RSA package functions