Skip to content

Commit

Permalink
feat: update default grpc.DialOption
Browse files Browse the repository at this point in the history
  • Loading branch information
daheige committed May 15, 2022
1 parent 5e2b800 commit 170e3f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
9 changes: 7 additions & 2 deletions example/clients/go/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"os"

"github.com/daheige/gmicro/v2/example/clients/go/pb"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

const (
Expand All @@ -26,7 +26,12 @@ heige@daheige client % go run client.go daheige123

func main() {
// Set up a connection to the server.
conn, err := grpc.Dial(address, grpc.WithInsecure())
// please note the following settings
// Deprecated: use WithTransportCredentials and insecure.NewCredentials()
// instead. Will be supported throughout 1.x.
// conn, err := grpc.Dial(address, grpc.WithInsecure())
// so use grpc.WithTransportCredentials(insecure.NewCredentials()) as default grpc.DialOption
conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand Down
15 changes: 12 additions & 3 deletions micro.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"golang.org/x/net/http2/h2c"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -163,7 +164,11 @@ func NewService(opts ...Option) *Service {

// default dial option is using insecure connection
if len(s.gRPCDialOptions) == 0 {
s.gRPCDialOptions = append(s.gRPCDialOptions, grpc.WithInsecure())
// Deprecated: use WithTransportCredentials and insecure.NewCredentials()
// instead. Will be supported throughout 1.x.
// s.gRPCDialOptions = append(s.gRPCDialOptions, grpc.WithInsecure())
// so use grpc.WithTransportCredentials(insecure.NewCredentials()) as default grpc.DialOption
s.gRPCDialOptions = append(s.gRPCDialOptions, grpc.WithTransportCredentials(insecure.NewCredentials()))
}

// install prometheus interceptor
Expand Down Expand Up @@ -545,7 +550,11 @@ func NewServiceWithoutGateway(opts ...Option) *Service {

// default dial option is using insecure connection
if len(s.gRPCDialOptions) == 0 {
s.gRPCDialOptions = append(s.gRPCDialOptions, grpc.WithInsecure())
// Deprecated: use WithTransportCredentials and insecure.NewCredentials()
// instead. Will be supported throughout 1.x.
// s.gRPCDialOptions = append(s.gRPCDialOptions, grpc.WithInsecure())
// so use grpc.WithTransportCredentials(insecure.NewCredentials()) as default grpc.DialOption
s.gRPCDialOptions = append(s.gRPCDialOptions, grpc.WithTransportCredentials(insecure.NewCredentials()))
}

// install prometheus interceptor
Expand Down Expand Up @@ -633,7 +642,7 @@ func (s *Service) StopGRPCWithoutGateway() {
}

// ServeFile serves a file
func (s *Service) ServeFile(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
func (s *Service) ServeFile(w http.ResponseWriter, r *http.Request, _ map[string]string) {
dir := s.staticDir
if s.staticDir == "" {
dir, _ = os.Getwd()
Expand Down

0 comments on commit 170e3f8

Please sign in to comment.