How to do it…

  1. Create second-greeting-service.go inside the services directory by executing the command $ cd services && touch second-greeting-service.go.
  2. Copy the following content to second-greeting-service.go:
package main
import
(
"context"
"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 - second 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))
if err := service.Run(); err != nil
{
log.Fatal("error starting service : ", err)
return
}
}

With everything in place, the directory structure should look like the following:

  1. Move to the services directory and run the program with the following command:
$ go run second-greeting-service.go
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.37.20