Golang flag.Uint() function example

package flag

Uint defines a uint flag with specified name(1st parameter), default value(2nd parameter), and usage string(3rd parameter). The return value is the address of a uint variable that stores the value of the flag.

Golang flag.Uint() function usage example

 package main

 import (
 "flag"
 "fmt"
 "strconv"
 )

 func main() {

 port := flag.Uint("port", 8080, "Port to listen. Default is 8080")
 flag.Parse()

 fmt.Println(flag.Lookup("port")) // print the Flag struct

 fmt.Printf("Port number is %s\n ", strconv.Itoa(int(*port)))

 }

Output :

&{port Port to listen. Default is 8080 8080 8080}

Port number is 8080

Reference :

http://golang.org/pkg/flag/#Uint

Advertisement