Standard library / flag
flag.Set()
Sets a registered flag from text, invoking its parser; returns an error for unknown or invalid values. Expected stdout: '9\n'.
Formal Syntax & Structure
go syntaxgo
func Set(name, value string) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Name of the flag or flag set. |
| value | string | Default value for registration, or text to parse for Set. |
Return Value
error
Parsing or setting error; nil on success.
Working Example
Example Snippetgo
package main
import ( "flag" "fmt")
func check(e error) { if e != nil { panic(e) }}
func main() { v := flag.Int("x", 0, "value") _ = v flag.Parse() check(flag.Set("x", "9")) fmt.Println(*v)}