1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-03-17 20:28:06 +02:00

52 lines
1.1 KiB
Go
Raw Normal View History

2020-12-26 15:17:20 +00:00
package main
import (
"fmt"
"os"
"github.com/asim/go-micro/v3"
"github.com/urfave/cli/v2"
2020-12-26 15:17:20 +00:00
)
func main() {
service := micro.NewService(
// Add runtime flags
// We could do this below too
micro.Flags(
&cli.StringFlag{
Name: "string_flag",
Usage: "This is a string flag",
},
&cli.IntFlag{
Name: "int_flag",
Usage: "This is an int flag",
},
&cli.BoolFlag{
Name: "bool_flag",
Usage: "This is a bool flag",
},
),
)
// Init will parse the command line flags. Any flags set will
// override the above settings. Options defined here will
// override anything set on the command line.
service.Init(
// Add runtime action
// We could actually do this above
micro.Action(func(c *cli.Context) error {
fmt.Printf("The string flag is: %s\n", c.String("string_flag"))
fmt.Printf("The int flag is: %d\n", c.Int("int_flag"))
fmt.Printf("The bool flag is: %t\n", c.Bool("bool_flag"))
// let's just exit because
os.Exit(0)
return nil
}),
)
// Run the server
if err := service.Run(); err != nil {
fmt.Println(err)
}
}