O'Reilly logo

Go Web Development Cookbook by Arpit Aggarwal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it…

  1. Create first-greeting-service.go inside the services directory by executing the command $ mkdir services && cd services && touch first-greeting-service.go.
  2. Copy the following content to first-greeting-service.go:
package mainimport (  "log"  "time"  hello "../proto"  "github.com/micro/go-micro")type Say struct{}func (s *Say) Hello(ctx context.Context, req *hello.Request, rsp *hello.Response) error {  log.Print("Received Say.Hello request - first greeting service")  rsp.Msg = "Hello " + req.Name  return nil}func main() {  service := micro.NewService  (    micro.Name("go.micro.service.greeter"),    micro.RegisterTTL(time.Second*30),    micro.RegisterInterval(time.Second*10),  )  service.Init() hello.RegisterSayHandler(service.Server(), new(Say)) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required