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