Golang flag.Lookup() function example

package flag

Lookup returns the Flag structure of the named command-line flag, returning nil if none exists.

Golang flag.Lookup() function usage example

 package main

 import (
 "flag"
 "fmt"
 )

 func main() {

 verbose := flag.String("verbose", "on", "Turn verbose mode on or off.")
 flag.Parse()

 fmt.Println(flag.Lookup("verbose")) // print the Flag struct

 fmt.Println(*verbose)

 }

Output :

&{verbose Turn verbose mode on or off. on on}

on

Reference :

http://golang.org/pkg/flag/#Lookup

Advertisement