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
| Name | Type | Description |
|---|---|---|
| p | *uint | Pointer to storage updated during parsing. |
| name | string | Name of the flag or flag set. |
| value | uint | Default value for registration, or text to parse for Set. |
| usage | string | Help 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)}