36 lines
691 B
Go
36 lines
691 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"log"
|
||
|
|
||
|
"github.com/micro/go-micro"
|
||
|
"github.com/micro/go-micro/service/grpc"
|
||
|
hello "github.com/micro/go-micro/service/grpc/examples/greeter/server/proto/hello"
|
||
|
)
|
||
|
|
||
|
type Say struct{}
|
||
|
|
||
|
func (s *Say) Hello(ctx context.Context, req *hello.Request, rsp *hello.Response) error {
|
||
|
log.Print("Received Say.Hello request")
|
||
|
rsp.Msg = "Hello " + req.Name
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
service := grpc.NewService(
|
||
|
micro.Name("go.micro.srv.greeter"),
|
||
|
)
|
||
|
|
||
|
// optionally setup command line usage
|
||
|
service.Init()
|
||
|
|
||
|
// Register Handlers
|
||
|
hello.RegisterSayHandler(service.Server(), new(Say))
|
||
|
|
||
|
// Run server
|
||
|
if err := service.Run(); err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
}
|