package main import ( "fmt" "strings" "context" "github.com/micro/go-micro/v2" proto "github.com/micro/go-micro/v2/agent/proto" ) type Command struct{} // Help returns the command usage func (c *Command) Help(ctx context.Context, req *proto.HelpRequest, rsp *proto.HelpResponse) error { rsp.Usage = "command" rsp.Description = "This is an example bot command as a micro service" return nil } // Exec executes the command func (c *Command) Exec(ctx context.Context, req *proto.ExecRequest, rsp *proto.ExecResponse) error { rsp.Result = []byte(strings.Join(req.Args, " ")) // rsp.Error could be set to return an error instead // the function error would only be used for service level issues return nil } func main() { service := micro.NewService( micro.Name("go.micro.bot.command"), ) service.Init() proto.RegisterCommandHandler(service.Server(), new(Command)) if err := service.Run(); err != nil { fmt.Println(err) } }