Golang flag.FlagSet.Lookup() function example

package flag

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

Golang flag.FlagSet.Lookup() function usage example

 package main

 import (
 "flag"
 "fmt"
 )

 func main() {

 flagSet := flag.NewFlagSet("check", flag.ExitOnError)

 var boostvalue float64

 flagSet.Float64Var(&boostvalue, "throttle", 0.2, "Value to boost current throttle [default :0.2]")

 fmt.Println(flagSet.Lookup("throttle"))  // <-- here

 }

Output :

&{throttle Value to boost current throttle [default :0.2] 0.2 0.2}

Reference :

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

  See also : Golang flag.Lookup() function example

Advertisement