Skip to content

Instantly share code, notes, and snippets.

@lcaballero
Created June 15, 2015 05:07
Show Gist options
  • Save lcaballero/d1a2ee97d8c117665c52 to your computer and use it in GitHub Desktop.
Save lcaballero/d1a2ee97d8c117665c52 to your computer and use it in GitHub Desktop.
An example of Go cli usage. Using codegangsta/cli
func main() {
app := cli.NewApp()
app.Name = "cli"
app.Version = "0.0.1"
app.Usage = "Fight the lack of Go knowledge"
app.Commands = []cli.Command {
{
Name: "web",
Aliases: []string{"s"},
Usage: "Start the web server.",
Action: func(c *cli.Context) {
fmt.Println("Starting server")
fmt.Printf("Arg count: %d\n", c.Int("port"))
flag.Set("bind", fmt.Sprintf(":%d", c.Int("port")))
server()
},
Flags: []cli.Flag{
cli.IntFlag{
Name: "port",
Value: 9100,
Usage: "Port for web-server to bind.",
},
},
},
{
Name: "data-server",
Aliases: []string{"d"},
Usage: "Start the data server",
Action: func(c *cli.Context) {
fmt.Println("Starting data server.")
},
},
}
// app.Action = func(c *cli.Context) {
// fmt.Println(toJson(&mem.User{}))
// fmt.Println(toPrettyJson(&mem.User{}))
// }
app.Run(os.Args)
// server()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment