30 lines
597 B
Go
30 lines
597 B
Go
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 {
|
|
pb.UnimplementedEchoServiceServer
|
|
}
|
|
|
|
func NewService() *Service {
|
|
return &Service{}
|
|
}
|
|
|
|
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
|
|
}
|