mirror of
https://github.com/go-micro/go-micro.git
synced 2025-01-05 10:20:53 +02:00
45 lines
807 B
Go
45 lines
807 B
Go
// Package main
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
hello "github.com/asim/go-micro/examples/v4/greeter/srv/proto/hello"
|
|
"go-micro.dev/v4"
|
|
"go-micro.dev/v4/util/log"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type Say struct{}
|
|
|
|
func (s *Say) Hello(ctx context.Context, req *hello.Request, rsp *hello.Response) error {
|
|
log.Log("Received Say.Hello request")
|
|
rsp.Msg = "Hello " + req.Name
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
go func() {
|
|
for {
|
|
grpc.DialContext(context.TODO(), "127.0.0.1:9091")
|
|
time.Sleep(time.Second)
|
|
}
|
|
}()
|
|
|
|
service := micro.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)
|
|
}
|
|
}
|