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

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"log"
     6  
     7  	pb "github.com/micro/go-micro/examples/helloworld/proto"
     8  	"github.com/micro/go-micro/v2"
     9  )
    10  
    11  type Greeter struct{}
    12  
    13  func (g *Greeter) Hello(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
    14  	rsp.Greeting = "Hello " + req.Name
    15  	return nil
    16  }
    17  
    18  func main() {
    19  	service := micro.NewService(
    20  		micro.Name("helloworld"),
    21  	)
    22  
    23  	service.Init()
    24  
    25  	pb.RegisterGreeterHandler(service.Server(), new(Greeter))
    26  
    27  	if err := service.Run(); err != nil {
    28  		log.Fatal(err)
    29  	}
    30  }