Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove glog dependency #3652

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ With `protoc` (just the grpc-gateway stubs):

```sh
protoc -I . --grpc-gateway_out ./gen/go \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
--grpc-gateway_opt generate_unbound_methods=true \
your/service/v1/your_service.proto
Expand Down Expand Up @@ -300,7 +299,6 @@ Here's what a `protoc` execution might look like:

```sh
protoc -I . --grpc-gateway_out ./gen/go \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
your/service/v1/your_service.proto
```
Expand Down Expand Up @@ -340,7 +338,6 @@ With `protoc` (just the grpc-gateway stubs):

```sh
protoc -I . --grpc-gateway_out ./gen/go \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
--grpc-gateway_opt grpc_api_configuration=path/to/config.yaml \
--grpc-gateway_opt standalone=true \
Expand All @@ -357,10 +354,10 @@ import (
"flag"
"net/http"

"github.com/golang/glog"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/grpclog"

gw "github.com/yourorg/yourrepo/proto/gen/go/your/service/v1/your_service" // Update
)
Expand Down Expand Up @@ -391,10 +388,9 @@ func run() error {

func main() {
flag.Parse()
defer glog.Flush()

if err := run(); err != nil {
glog.Fatal(err)
grpclog.Fatal(err)
}
}
```
Expand Down Expand Up @@ -439,7 +435,6 @@ With `protoc` (just the swagger file):

```sh
protoc -I . --openapiv2_out ./gen/openapiv2 \
--openapiv2_opt logtostderr=true \
your/service/v1/your_service.proto
```

Expand Down Expand Up @@ -532,19 +527,15 @@ through `protoc` using one of 2 patterns:
- as part of the `--<tool_suffix>_out` `protoc` parameter: `--<tool_suffix>_out=<flags>:<path>`

```sh
--grpc-gateway_out=logtostderr=true,repeated_path_param_separator=ssv:.
--openapiv2_out=logtostderr=true,repeated_path_param_separator=ssv:.
--grpc-gateway_out=repeated_path_param_separator=ssv:.
--openapiv2_out=repeated_path_param_separator=ssv:.
```

- using additional `--<tool_suffix>_opt` parameters: `--<tool_suffix>_opt=<flag>[,<flag>]*`

```sh
--grpc-gateway_opt logtostderr=true,repeated_path_param_separator=ssv
# or separately
--grpc-gateway_opt logtostderr=true --grpc-gateway_opt repeated_path_param_separator=ssv
--openapiv2_opt logtostderr=true,repeated_path_param_separator=ssv
# or separately
--openapiv2_opt logtostderr=true --openapiv2_opt repeated_path_param_separator=ssv
--grpc-gateway_opt repeated_path_param_separator=ssv
--openapiv2_opt repeated_path_param_separator=ssv
```

## More examples
Expand Down
5 changes: 2 additions & 3 deletions docs/docs/development/installation_for_cygwin.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ This will probably fail with a similar output to this:
To fix this you need to run the `go get -u -v` commands and look for all lines starting with `# cd .;`. Copy and paste these lines into your shell and change the clone destination directories.

git clone https://github.com/grpc-ecosystem/grpc-gateway $(cygpath -u $GOPATH)/src/github.com/grpc-ecosystem/grpc-gateway
git clone https://github.com/golang/glog $(cygpath -u $GOPATH)/src/github.com/golang/glog
git clone https://github.com/golang/protobuf $(cygpath -u $GOPATH)/src/github.com/golang/protobuf
git clone https://github.com/google/go-genproto $(cygpath -u $GOPATH)/src/google.golang.org/genproto

Expand All @@ -67,8 +66,8 @@ Follow the [instructions](https://github.com/grpc-ecosystem/grpc-gateway#usage)
Adjust steps 3, 5 and 7 like this. `protoc` expects native Windows paths.

protoc -I. -I$(cygpath -w /usr/local/include) -I${GOPATH}/src --go_out=. --go-grpc_out=. ./path/to/your_service.proto
protoc -I. -I$(cygpath -w /usr/local/include) -I${GOPATH}/src --grpc-gateway_out=logtostderr=true:. ./path/to/your_service.proto
protoc -I. -I$(cygpath -w /usr/local/include) -I${GOPATH}/src --openapiv2_out=logtostderr=true:. ./path/to/your_service.proto
protoc -I. -I$(cygpath -w /usr/local/include) -I${GOPATH}/src ./path/to/your_service.proto
protoc -I. -I$(cygpath -w /usr/local/include) -I${GOPATH}/src ./path/to/your_service.proto

Then `cd` into the directory where your entry-point `main.go` file is located and run:

Expand Down
3 changes: 1 addition & 2 deletions docs/docs/mapping/customizing_openapi_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ Example of a bash script with the `use_go_templates` flag set to true:
```sh
$ protoc -I. \
--go_out . --go-grpc_out . \
--grpc-gateway_out . --grpc-gateway_opt logtostderr=true \
--grpc-gateway_out . \
--openapiv2_out . \
--openapiv2_opt logtostderr=true \
--openapiv2_opt use_go_templates=true \
path/to/my/proto/v1/myproto.proto
```
Expand Down
2 changes: 0 additions & 2 deletions docs/docs/mapping/grpc_api_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ It will generate a stub file with path `./gen/go/your/service/v1/your_service.pb
```sh
protoc -I . \
--grpc-gateway_out ./gen/go \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
--grpc-gateway_opt grpc_api_configuration=path/to/your_service.yaml \
your/service/v1/your_service.proto
Expand All @@ -107,7 +106,6 @@ It will generate a stub file with path `./gen/go/your/service/v1/your_service.pb
```
protoc -I . \
--grpc-gateway_out ./gen/go \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
--grpc-gateway_opt standalone=true \
--grpc-gateway_opt grpc_api_configuration=path/to/your_service.yaml \
Expand Down
6 changes: 2 additions & 4 deletions examples/internal/browser/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ gulp.task('gateway', shell.task([
]));

gulp.task('serve-server', ['server'], function () {
let server = child.spawn('bin/example-server', [
'--logtostderr',
], { stdio: 'inherit' });
let server = child.spawn('bin/example-server', [], { stdio: 'inherit' });
process.on('exit', function () {
server.kill();
});
});

gulp.task('serve-gateway', ['gateway', 'serve-server'], function () {
let gw = child.spawn('bin/example-gw', [
'--logtostderr', '--openapi_dir', path.join(__dirname, "../proto/examplepb"),
'--openapi_dir', path.join(__dirname, "../proto/examplepb"),
], { stdio: 'inherit' });
process.on('exit', function () {
gw.kill();
Expand Down
2 changes: 1 addition & 1 deletion examples/internal/cmd/example-gateway-server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//examples/internal/gateway",
"@com_github_golang_glog//:glog",
"@org_golang_google_grpc//grpclog",
],
)

Expand Down
5 changes: 2 additions & 3 deletions examples/internal/cmd/example-gateway-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"context"
"flag"

"github.com/golang/glog"
"github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/gateway"
"google.golang.org/grpc/grpclog"
)

var (
Expand All @@ -20,7 +20,6 @@ var (

func main() {
flag.Parse()
defer glog.Flush()

ctx := context.Background()
opts := gateway.Options{
Expand All @@ -32,6 +31,6 @@ func main() {
OpenAPIDir: *openAPIDir,
}
if err := gateway.Run(ctx, opts); err != nil {
glog.Fatal(err)
grpclog.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion examples/internal/cmd/example-grpc-server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_library(
importpath = "github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/cmd/example-grpc-server",
deps = [
"//examples/internal/server",
"@com_github_golang_glog//:glog",
"@org_golang_google_grpc//grpclog",
],
)

Expand Down
5 changes: 2 additions & 3 deletions examples/internal/cmd/example-grpc-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"context"
"flag"

"github.com/golang/glog"
"github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/server"
"google.golang.org/grpc/grpclog"
)

var (
Expand All @@ -19,10 +19,9 @@ var (

func main() {
flag.Parse()
defer glog.Flush()

ctx := context.Background()
if err := server.Run(ctx, *network, *addr); err != nil {
glog.Fatal(err)
grpclog.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion examples/internal/gateway/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ go_library(
"//examples/internal/proto/examplepb",
"//examples/internal/proto/standalone",
"//runtime",
"@com_github_golang_glog//:glog",
"@org_golang_google_genproto_googleapis_rpc//errdetails",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//connectivity",
"@org_golang_google_grpc//credentials/insecure",
"@org_golang_google_grpc//grpclog",
],
)

Expand Down
8 changes: 4 additions & 4 deletions examples/internal/gateway/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import (
"path"
"strings"

"github.com/golang/glog"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/grpclog"
)

// openAPIServer returns OpenAPI specification files located under "/openapiv2/"
func openAPIServer(dir string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if !strings.HasSuffix(r.URL.Path, ".swagger.json") {
glog.Errorf("Not Found: %s", r.URL.Path)
grpclog.Errorf("Not Found: %s", r.URL.Path)
http.NotFound(w, r)
return
}

glog.Infof("Serving %s", r.URL.Path)
grpclog.Infof("Serving %s", r.URL.Path)
p := strings.TrimPrefix(r.URL.Path, "/openapiv2/")
p = path.Join(dir, p)
http.ServeFile(w, r, p)
Expand Down Expand Up @@ -50,7 +50,7 @@ func preflightHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Headers", strings.Join(headers, ","))
methods := []string{"GET", "HEAD", "POST", "PUT", "DELETE"}
w.Header().Set("Access-Control-Allow-Methods", strings.Join(methods, ","))
glog.Infof("preflight request for %s", r.URL.Path)
grpclog.Infof("Preflight request for %s", r.URL.Path)
}

// healthzServer returns a simple health handler which returns ok.
Expand Down
12 changes: 6 additions & 6 deletions examples/internal/gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"net/http"

"github.com/golang/glog"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc/grpclog"
)

// Endpoint describes a gRPC endpoint
Expand Down Expand Up @@ -42,7 +42,7 @@ func Run(ctx context.Context, opts Options) error {
go func() {
<-ctx.Done()
if err := conn.Close(); err != nil {
glog.Errorf("Failed to close a client connection to the gRPC server: %v", err)
grpclog.Errorf("Failed to close a client connection to the gRPC server: %v", err)
}
}()

Expand All @@ -62,15 +62,15 @@ func Run(ctx context.Context, opts Options) error {
}
go func() {
<-ctx.Done()
glog.Infof("Shutting down the http server")
grpclog.Infof("Shutting down the http server")
if err := s.Shutdown(context.Background()); err != nil {
glog.Errorf("Failed to shutdown http server: %v", err)
grpclog.Errorf("Failed to shutdown http server: %v", err)
}
}()

glog.Infof("Starting listening at %s", opts.Addr)
grpclog.Infof("Starting listening at %s", opts.Addr)
if err := s.ListenAndServe(); err != http.ErrServerClosed {
glog.Errorf("Failed to listen and serve: %v", err)
grpclog.Errorf("Failed to listen and serve: %v", err)
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion examples/internal/integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ go_test(
"//examples/internal/proto/sub",
"//examples/internal/server",
"//runtime",
"@com_github_golang_glog//:glog",
"@com_github_google_go_cmp//cmp",
"@com_github_rogpeppe_fastuuid//:fastuuid",
"@org_golang_google_genproto_googleapis_rpc//status",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//grpclog",
"@org_golang_google_protobuf//encoding/protojson",
"@org_golang_google_protobuf//proto",
"@org_golang_google_protobuf//testing/protocmp",
Expand Down
9 changes: 4 additions & 5 deletions examples/internal/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"testing"
"time"

"github.com/golang/glog"
"github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/gateway"
server "github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/server"
"github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/server"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc/grpclog"
)

var (
Expand Down Expand Up @@ -42,7 +42,7 @@ func waitForGateway(ctx context.Context, port uint16) error {
return nil
}

glog.Infof("Waiting for localhost:%d to get ready", port)
grpclog.Infof("Waiting for localhost:%d to get ready", port)
select {
case <-ctx.Done():
return err
Expand Down Expand Up @@ -75,7 +75,6 @@ func runServers(ctx context.Context) <-chan error {

func TestMain(m *testing.M) {
flag.Parse()
defer glog.Flush()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -84,7 +83,7 @@ func TestMain(m *testing.M) {
ch := make(chan int, 1)
go func() {
if err := waitForGateway(ctx, 8088); err != nil {
glog.Errorf("waitForGateway(ctx, 8088) failed with %v; want success", err)
grpclog.Errorf("waitForGateway(ctx, 8088) failed with %v; want success", err)
}
ch <- m.Run()
}()
Expand Down
2 changes: 1 addition & 1 deletion examples/internal/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ go_library(
"//examples/internal/proto/sub",
"//examples/internal/proto/sub2",
"//runtime",
"@com_github_golang_glog//:glog",
"@com_github_rogpeppe_fastuuid//:fastuuid",
"@org_golang_google_genproto_googleapis_api//httpbody",
"@org_golang_google_genproto_googleapis_rpc//errdetails",
"@org_golang_google_genproto_googleapis_rpc//status",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//grpclog",
"@org_golang_google_grpc//metadata",
"@org_golang_google_grpc//status",
"@org_golang_google_protobuf//proto",
Expand Down
Loading
Loading