foo test service
This commit is contained in:
48
services/foo/handler/foo.go
Normal file
48
services/foo/handler/foo.go
Normal file
@ -0,0 +1,48 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/micro/go-micro/util/log"
|
||||
|
||||
foo "foo/proto/foo"
|
||||
)
|
||||
|
||||
type Foo struct{}
|
||||
|
||||
// Call is a single request handler called via client.Call or the generated client code
|
||||
func (e *Foo) Call(ctx context.Context, req *foo.Request, rsp *foo.Response) error {
|
||||
log.Log("Received Foo.Call request")
|
||||
rsp.Msg = "Hello " + req.Name
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stream is a server side stream handler called via client.Stream or the generated client code
|
||||
func (e *Foo) Stream(ctx context.Context, req *foo.StreamingRequest, stream foo.Foo_StreamStream) error {
|
||||
log.Logf("Received Foo.Stream request with count: %d", req.Count)
|
||||
|
||||
for i := 0; i < int(req.Count); i++ {
|
||||
log.Logf("Responding: %d", i)
|
||||
if err := stream.Send(&foo.StreamingResponse{
|
||||
Count: int64(i),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PingPong is a bidirectional stream handler called via client.Stream or the generated client code
|
||||
func (e *Foo) PingPong(ctx context.Context, stream foo.Foo_PingPongStream) error {
|
||||
for {
|
||||
req, err := stream.Recv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Logf("Got ping %v", req.Stroke)
|
||||
if err := stream.Send(&foo.Pong{Stroke: req.Stroke}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user