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
import (
hs "ch4-04/01/helloservice"
"context"
"fmt"
"google.golang.org/grpc"
"log"
"fmt"
."github.com/advanced-go-programming-book-code/ch4/s04/e01grpc/helloservice"
"context"
)
func main() {
@ -15,8 +15,8 @@ func main() {
}
defer conn.Close()
client := NewHelloServiceClient(conn)
reply, err := client.Hello(context.Background(), &String{Value: "hello"})
client := hs.NewHelloServiceClient(conn)
reply, err := client.Hello(context.Background(), &hs.String{Value: "hello"})
if err != nil {
log.Fatal(err)
}

View File

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

Binary file not shown.