Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Last active April 29, 2019 19:46
Show Gist options
  • Select an option

  • Save KamilLelonek/88b8aded9ce84d7a1a50692d7a13b3e7 to your computer and use it in GitHub Desktop.

Select an option

Save KamilLelonek/88b8aded9ce84d7a1a50692d7a13b3e7 to your computer and use it in GitHub Desktop.
const port = ":50051"
type gravatarService struct{}
func (s *gravatarService) Generate(ctx context.Context, in *pb.GravatarRequest) (*pb.GravatarResponse, error) {
log.Printf("Received email %v with size %v", in.Email, in.Size)
return &pb.GravatarResponse{Url: gravatar(in.Email, in.Size)}, nil
}
func main() {
lis, err := net.Listen("tcp", port)
if err != nil {
log.Fatalf("Failed to listen on port: %v", err)
}
server := grpc.NewServer()
pb.RegisterGravatarServiceServer(server, &gravatarService{})
if err := server.Serve(lis); err != nil {
log.Fatal(errors.Wrap(err, "Failed to start server!"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment