Skip to content

Instantly share code, notes, and snippets.

@asim
Last active February 8, 2020 22:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asim/79d05fd3c44d944093c470e70d094534 to your computer and use it in GitHub Desktop.
Save asim/79d05fd3c44d944093c470e70d094534 to your computer and use it in GitHub Desktop.
A go-micro service
package main
import (
"context"
"log"
pb "github.com/micro/examples/helloworld/proto"
"github.com/micro/go-micro/v2"
)
type Greeter struct{}
func (g *Greeter) Hello(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
rsp.Greeting = "Hello " + req.Name
return nil
}
func main() {
service := micro.NewService(
micro.Name("helloworld"),
)
service.Init()
pb.RegisterGreeterHandler(service.Server(), new(Greeter))
if err := service.Run(); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment