mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 12:32:21 +00:00
32 lines
528 B
Go
32 lines
528 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
hs "ch4.4-1/helloservice"
|
|
)
|
|
|
|
type HelloServiceImpl struct{}
|
|
|
|
func (p *HelloServiceImpl) Hello(
|
|
ctx context.Context, args *hs.String,
|
|
) (*hs.String, error) {
|
|
reply := &hs.String{Value: "hello:" + args.GetValue()}
|
|
return reply, nil
|
|
}
|
|
|
|
func main() {
|
|
grpcServer := grpc.NewServer()
|
|
hs.RegisterHelloServiceServer(grpcServer, new(HelloServiceImpl))
|
|
|
|
lis, err := net.Listen("tcp", ":1234")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
grpcServer.Serve(lis)
|
|
}
|