30 lines
597 B
Go
Raw Permalink Normal View History

2021-01-16 16:08:05 +08:00
package echo
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
pb "github.com/esinio/geco/gen/proto/echo/v1"
)
type Service struct {
2021-01-16 16:28:32 +08:00
pb.UnimplementedEchoServiceServer
}
func NewService() *Service {
return &Service{}
2021-01-16 16:08:05 +08:00
}
func (s *Service) Echo(ctx context.Context, req *pb.StringMessage) (*pb.StringMessage, error) {
if req.Value == "" {
return nil, status.Errorf(codes.Unimplemented, "value is empty")
}
return &pb.StringMessage{
Value: req.Value,
Timestamp: timestamppb.Now(),
}, nil
}