1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-01-23 17:53:05 +02:00

40 lines
731 B
Go
Raw Normal View History

2020-12-26 15:17:20 +00:00
package main
import (
"context"
"fmt"
2020-12-26 15:21:29 +00:00
proto "github.com/micro/go-micro/examples/service/proto"
2020-12-26 15:17:20 +00:00
"github.com/micro/go-micro/v2"
"github.com/micro/go-micro/v2/metadata"
)
type Greeter struct{}
func (g *Greeter) Hello(ctx context.Context, req *proto.Request, rsp *proto.Response) error {
md, _ := metadata.FromContext(ctx)
// local ip of service
fmt.Println("local ip is", md["Local"])
// remote ip of caller
fmt.Println("remote ip is", md["Remote"])
rsp.Greeting = "Hello " + req.Name
return nil
}
func main() {
service := micro.NewService(
micro.Name("greeter"),
)
service.Init()
proto.RegisterGreeterHandler(service.Server(), new(Greeter))
if err := service.Run(); err != nil {
fmt.Println(err)
}
}