1.路徑src\server\server.go
2.啟動服務:
package server
import (
"context"
v1 "goWebGin/api/proto/v1"
"google.golang.org/grpc"
"log"
"net"
"os"
)
func RunServer(ctx context.Context, v1Api v1.ToDoServiceServer, port string) error {
listen, err := net.Listen("tcp", ":"+port)
if err != nil {
return err
}
server := grpc.NewServer()
v1.RegisterToDoServiceServer(server, v1Api)
c := make(chan os.Signal, 1)
go func() {
for range c {
log.Println("shutting down gRPC server..")
server.GracefulStop()
<-ctx.Done()
return
}
}()
log.Println("starting gRPC server...")
return server.Serve(listen)
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結