package main import ( "flag" "fmt" ) func main() { var count int fs := flag.NewFlagSet("count", flag.ContinueOnError) fs.IntVar(&count, "c", 0, "set the count value") fs.Parse(os.Args[1:]) fmt.Println("Count value is:", count) }
package main import ( "flag" "fmt" ) func main() { var age int fs := flag.NewFlagSet("age", flag.ContinueOnError) fs.IntVar(&age, "a", 0, "set the age value") fs.Parse(os.Args[1:]) if age >= 18 { fmt.Println("You are an adult") } else { fmt.Println("You are a minor") } }In this example, the program uses the FlagSet Int type to parse a command line argument "-a" and set the age variable to the value passed in by the user. The program then checks if the age is greater than or equal to 18 and prints a corresponding message to the console. Overall, the flag package library in Go provides an easy-to-use interface for parsing command line arguments and setting variables with different data types, including integers.