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 :
Advertisement
Something interesting
Tutorials
+12.8k Golang : Convert int(year) to time.Time type
+16k Golang : Get sub string example
+10.6k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+11.7k Golang : Gorilla web tool kit secure cookie example
+9.7k Random number generation with crypto/rand in Go
+38.1k Golang : Read a text file and replace certain words
+9.6k Golang : Quadratic example
+7.2k Golang : Use modern ciphers only in secure connection
+20.6k Nginx + FastCGI + Go Setup.
+4.8k PHP : Extract part of a string starting from the middle
+7.9k Golang : Trim everything onward after a word
+12.6k Golang : Get absolute path to binary for os.Exec function with exec.LookPath