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 greeting-api.go inside the api directory by executing the command $ mkdir api && cd api && touch greeting-api.go.
  2. Copy the following content to greeting-api.go:
package mainimport (  "context"  "encoding/json"  "log"  "strings"  hello "../proto"  "github.com/micro/go-micro"  api "github.com/micro/micro/api/proto")type Say struct {  Client hello.SayClient}func (s *Say) Hello(ctx context.Context, req *api.Request, rsp *api.Response) error {  log.Print("Received Say.Hello request - Micro Greeter API")  name, ok := req.Get["name"]  if ok   {    response, err := s.Client.Hello    (      ctx, &hello.Request      {        Name: strings.Join(name.Values, " "),      }    )    if err != nil     {      return err    }    message, _ := json.Marshal    (      map[string]string      { "message": response.Msg, ...

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