2017-06-05 14:59:43 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2018-05-24 11:48:14 +00:00
|
|
|
"context"
|
|
|
|
|
2017-06-05 14:59:43 +00:00
|
|
|
"github.com/golang/glog"
|
2018-05-24 11:48:14 +00:00
|
|
|
examples "github.com/grpc-ecosystem/grpc-gateway/examples/proto/examplepb"
|
2017-06-05 14:59:43 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/metadata"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Implements of EchoServiceServer
|
|
|
|
|
|
|
|
type echoServer struct{}
|
|
|
|
|
|
|
|
func newEchoServer() examples.EchoServiceServer {
|
|
|
|
return new(echoServer)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *echoServer) Echo(ctx context.Context, msg *examples.SimpleMessage) (*examples.SimpleMessage, error) {
|
|
|
|
glog.Info(msg)
|
|
|
|
return msg, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *echoServer) EchoBody(ctx context.Context, msg *examples.SimpleMessage) (*examples.SimpleMessage, error) {
|
|
|
|
glog.Info(msg)
|
|
|
|
grpc.SendHeader(ctx, metadata.New(map[string]string{
|
|
|
|
"foo": "foo1",
|
|
|
|
"bar": "bar1",
|
|
|
|
}))
|
|
|
|
grpc.SetTrailer(ctx, metadata.New(map[string]string{
|
|
|
|
"foo": "foo2",
|
|
|
|
"bar": "bar2",
|
|
|
|
}))
|
|
|
|
return msg, nil
|
|
|
|
}
|
2018-05-24 11:48:14 +00:00
|
|
|
|
|
|
|
func (s *echoServer) EchoDelete(ctx context.Context, msg *examples.SimpleMessage) (*examples.SimpleMessage, error) {
|
|
|
|
glog.Info(msg)
|
|
|
|
return msg, nil
|
|
|
|
}
|