mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-28 23:42:21 +00:00
add ch4-04/01
This commit is contained in:
parent
832102eda6
commit
4b4ad1420c
BIN
vendor/ch4-04/01/client/client
vendored
BIN
vendor/ch4-04/01/client/client
vendored
Binary file not shown.
@ -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,10 +15,10 @@ 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)
|
||||
}
|
||||
fmt.Println(reply.GetValue())
|
||||
}
|
||||
}
|
@ -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 {
|
BIN
vendor/ch4-04/01/server/server
vendored
BIN
vendor/ch4-04/01/server/server
vendored
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user