import ( "flag" "fmt" ) func main() { fs := flag.NewFlagSet("example", flag.ExitOnError) // Define the boolean flag var opt bool fs.BoolVar(&opt, "opt", false, "an optional flag") // Parse the command-line flags fs.Parse([]string{"-opt"}) // Use the flag value fmt.Println(opt) // Output: true }In this example, we create a new FlagSet with the name "example" and an exit-on-error behavior. We then define a boolean flag called "opt" with a default value of false and a usage message. We then parse the command-line arguments, which in this case consists of just the "-opt" flag. Finally, we print the value of the "opt" flag, which is true because it was set on the command line. The go flag package is part of the Go standard library.