This commit is contained in:
tcq 2024-01-30 16:07:42 +08:00
parent e0cee7bdd4
commit 1ced5eb275
5 changed files with 36 additions and 1957 deletions

View File

@ -3,7 +3,7 @@ package main
import ( import (
"context" "context"
"flag" "flag"
helloworld "github.com/helloworlde/grpc-gateway/proto/api" pb "github.com/helloworlde/grpc-gateway/proto/api"
_ "github.com/mbobakov/grpc-consul-resolver" _ "github.com/mbobakov/grpc-consul-resolver"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
@ -49,11 +49,11 @@ func run() error {
} }
defer conn.Close() defer conn.Close()
c := helloworld.NewHelloServiceClient(conn) c := pb.NewHelloServiceClient(conn)
// Contact the server and print out its response. // Contact the server and print out its response.
r, err := c.Hello(ctx, &helloworld.HelloMessage{ r, err := c.Hello(ctx, &pb.HelloMessage{
Message: defaultName, Message: defaultName,
}) })
if err != nil { if err != nil {

28
go.mod
View File

@ -1,9 +1,8 @@
module github.com/helloworlde/grpc-gateway module github.com/helloworlde/grpc-gateway
go 1.15 go 1.21
require ( require (
github.com/golang/protobuf v1.5.3
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3
github.com/hashicorp/consul/api v1.27.0 github.com/hashicorp/consul/api v1.27.0
github.com/mbobakov/grpc-consul-resolver v1.5.3 github.com/mbobakov/grpc-consul-resolver v1.5.3
@ -11,3 +10,28 @@ require (
google.golang.org/grpc v1.54.0 google.golang.org/grpc v1.54.0
google.golang.org/protobuf v1.30.0 google.golang.org/protobuf v1.30.0
) )
require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/go-playground/form v3.1.4+incompatible // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.13.0 // indirect
)

1949
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,6 @@
package main package main
import ( import "github.com/helloworlde/grpc-gateway/server"
"github.com/helloworlde/grpc-gateway/server"
)
func main() { func main() {
go server.StartGrpcServer() go server.StartGrpcServer()

View File

@ -7,6 +7,12 @@ import (
) )
type HelloService struct { type HelloService struct {
pb.UnimplementedHelloServiceServer
}
// mustEmbedUnimplementedHelloServiceServer implements grpc_gateway.HelloServiceServer.
func (*HelloService) mustEmbedUnimplementedHelloServiceServer() {
panic("unimplemented")
} }
func (h *HelloService) Hello(ctx context.Context, message *pb.HelloMessage) (*pb.HelloResponse, error) { func (h *HelloService) Hello(ctx context.Context, message *pb.HelloMessage) (*pb.HelloResponse, error) {