1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-29 08:12:21 +00:00

add ch4-04/01

This commit is contained in:
sfw 2018-08-12 18:36:55 +08:00
parent 832102eda6
commit 4b4ad1420c
4 changed files with 14 additions and 12 deletions

Binary file not shown.

View File

@ -1,11 +1,11 @@
package main package main
import ( import (
hs "ch4-04/01/helloservice"
"context"
"fmt"
"google.golang.org/grpc" "google.golang.org/grpc"
"log" "log"
"fmt"
."github.com/advanced-go-programming-book-code/ch4/s04/e01grpc/helloservice"
"context"
) )
func main() { func main() {
@ -15,10 +15,10 @@ func main() {
} }
defer conn.Close() defer conn.Close()
client := NewHelloServiceClient(conn) client := hs.NewHelloServiceClient(conn)
reply, err := client.Hello(context.Background(), &String{Value: "hello"}) reply, err := client.Hello(context.Background(), &hs.String{Value: "hello"})
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Println(reply.GetValue()) fmt.Println(reply.GetValue())
} }

View File

@ -2,24 +2,26 @@ package main
import ( import (
"context" "context"
"net"
"log" "log"
."github.com/advanced-go-programming-book-code/ch4/s04/e01grpc/helloservice" "net"
"google.golang.org/grpc" "google.golang.org/grpc"
hs "ch4-04/01/helloservice"
) )
type HelloServiceImpl struct{} type HelloServiceImpl struct{}
func (p *HelloServiceImpl) Hello( func (p *HelloServiceImpl) Hello(
ctx context.Context, args *String, ctx context.Context, args *hs.String,
) (*String, error) { ) (*hs.String, error) {
reply := &String{Value: "hello:" + args.GetValue()} reply := &hs.String{Value: "hello:" + args.GetValue()}
return reply, nil return reply, nil
} }
func main() { func main() {
grpcServer := grpc.NewServer() grpcServer := grpc.NewServer()
RegisterHelloServiceServer(grpcServer, new(HelloServiceImpl)) hs.RegisterHelloServiceServer(grpcServer, new(HelloServiceImpl))
lis, err := net.Listen("tcp", ":1234") lis, err := net.Listen("tcp", ":1234")
if err != nil { if err != nil {

Binary file not shown.