Standard library / flag

flag.FlagSet.UintVar()

Registers a flag on an independent FlagSet. Binds existing uint storage rather than returning a pointer. Unsigned machine-width integer; negative values are invalid. Run with arguments: ["-x=7"]. Expected stdout: '7\n'.

Formal Syntax & Structure

go syntaxgo
func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string)

Parameters & Attributes

NameTypeDescription
p*uintPointer to storage updated during parsing.
namestringName of the flag or flag set.
valueuintDefault value for registration, or text to parse for Set.
usagestringHelp text describing the flag.

Working Example

Example Snippetgo
package main
import (  "flag"  "fmt"  "os")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  f := flag.NewFlagSet("demo", flag.ContinueOnError)  var v uint  f.UintVar(&v, "x", 3, "value")  check(f.Parse(os.Args[1:]))  fmt.Println(v)}
Go Reference