github.com/micro/go-micro/examples@v0.0.0-20210105173217-bf4ab679e18b/greeter/cli/main.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	hello "github.com/micro/go-micro/examples/greeter/srv/proto/hello"
     8  	"github.com/micro/go-micro/v2"
     9  )
    10  
    11  func main() {
    12  	// create a new service
    13  	service := micro.NewService()
    14  
    15  	// parse command line flags
    16  	service.Init()
    17  
    18  	// Use the generated client stub
    19  	cl := hello.NewSayService("go.micro.srv.greeter", service.Client())
    20  
    21  	// Make request
    22  	rsp, err := cl.Hello(context.Background(), &hello.Request{
    23  		Name: "John",
    24  	})
    25  	if err != nil {
    26  		fmt.Println(err)
    27  		return
    28  	}
    29  
    30  	fmt.Println(rsp.Msg)
    31  }