Standard library / flag
flag.String()
Registers a flag on the default command line. String value; the shell must preserve spaces as part of one argument. Run with arguments: ["-x=hello world"]. Expected stdout: 'hello world\n'.
Formal Syntax & Structure
go syntaxgo
func String(name string, value string, usage string) *stringParameters & 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. |
| usage | string | Help text describing the flag. |
Return Value
*string
Registers a flag on the default command line.
Working Example
Example Snippetgo
package main
import ( "flag" "fmt")
func main() { v := flag.String("x", "default", "value"); flag.Parse(); fmt.Println(*v) }