Created
December 16, 2020 01:21
-
-
Save brianpgerson/1204f10476a1e655605480c547bf743c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"net" | |
pb "envoy_example/protos" | |
"google.golang.org/grpc" | |
) | |
type server struct { | |
pb.UnimplementedHelloServiceServer | |
} | |
func (*server) Hello(ctx context.Context, request *pb.HelloRequest) (*pb.HelloResponse, error) { | |
name := request.Name | |
response := &pb.HelloResponse{Greeting: "Hello " + name} | |
return response, nil | |
} | |
func main() { | |
address := "0.0.0.0:5050" | |
lis, err := net.Listen("tcp", address) | |
if err != nil { | |
log.Fatalf("Backend Error %v", err) | |
} | |
fmt.Printf("Server is listening on %v ...", address) | |
s := grpc.NewServer() | |
pb.RegisterHelloServiceServer(s, &server{}) | |
s.Serve(lis) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment