Skip to content

Commit 385de4a

Browse files
committed
Add version-specific reflection API toggle for echo-grpc
Add DISABLE_REFLECTION_V1 and DISABLE_REFLECTION_V1ALPHA environment variables to allow selective disabling of gRPC reflection API versions. This enables testing client compatibility with different reflection protocol versions. Changes: - Add DisableReflectionV1 and DisableReflectionV1Alpha config fields - Update RegisterReflection to support version-specific registration - Skip reflection registration entirely when both versions are disabled - Document new environment variables in API reference
1 parent 8df25bd commit 385de4a

File tree

13 files changed

+53
-36
lines changed

13 files changed

+53
-36
lines changed

echo-grpc/config.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ import (
77
)
88

99
type Config struct {
10-
Host string
11-
Port string
12-
ReflectionIncludeDeps bool
10+
Host string
11+
Port string
12+
ReflectionIncludeDeps bool
13+
DisableReflectionV1 bool
14+
DisableReflectionV1Alpha bool
1315
}
1416

1517
func LoadConfig() *Config {
1618
// Load .env file if exists (ignore error if not found)
1719
_ = godotenv.Load()
1820

1921
return &Config{
20-
Host: getEnv("HOST", "0.0.0.0"),
21-
Port: getEnv("PORT", "50051"),
22-
ReflectionIncludeDeps: getEnvBool("REFLECTION_INCLUDE_DEPENDENCIES", false),
22+
Host: getEnv("HOST", "0.0.0.0"),
23+
Port: getEnv("PORT", "50051"),
24+
ReflectionIncludeDeps: getEnvBool("REFLECTION_INCLUDE_DEPENDENCIES", false),
25+
DisableReflectionV1: getEnvBool("DISABLE_REFLECTION_V1", false),
26+
DisableReflectionV1Alpha: getEnvBool("DISABLE_REFLECTION_V1ALPHA", false),
2327
}
2428
}
2529

echo-grpc/docs/api.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ grpcurl -plaintext -d '{"service": ""}' \
605605

606606
## Server Reflection
607607

608-
The server supports gRPC server reflection for service discovery.
608+
The server supports gRPC server reflection for service discovery (both v1 and v1alpha versions).
609609

610610
```bash
611611
# List all services
@@ -618,6 +618,14 @@ grpcurl -plaintext localhost:50051 describe echo.v1.Echo
618618
grpcurl -plaintext localhost:50051 describe echo.v1.EchoRequest
619619
```
620620

621+
### Environment Variables
622+
623+
- `REFLECTION_INCLUDE_DEPENDENCIES` (default: `false`) - Include transitive dependencies in reflection responses
624+
- `DISABLE_REFLECTION_V1` (default: `false`) - Disable gRPC reflection v1 API
625+
- `DISABLE_REFLECTION_V1ALPHA` (default: `false`) - Disable gRPC reflection v1alpha API
626+
627+
These flags allow testing client compatibility with different reflection API versions.
628+
621629
## Metadata
622630

623631
Request metadata is echoed back in the `metadata` field of every response. Custom metadata can be sent using grpcurl's `-H` flag:

echo-grpc/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func main() {
3030
healthpb.RegisterHealthServer(s, healthServer)
3131

3232
// Enable server reflection (v1 and v1alpha)
33-
server.RegisterReflection(s, cfg.ReflectionIncludeDeps)
33+
server.RegisterReflection(s, cfg.ReflectionIncludeDeps, cfg.DisableReflectionV1, cfg.DisableReflectionV1Alpha)
3434

3535
log.Printf("Starting server on %s", cfg.Addr())
3636
if err := s.Serve(lis); err != nil {

echo-grpc/proto/echo.pb.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

echo-grpc/proto/echo_deadline.pb.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

echo-grpc/proto/echo_errors.pb.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

echo-grpc/proto/echo_grpc.pb.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

echo-grpc/proto/echo_metadata.pb.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

echo-grpc/proto/echo_payload.pb.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

echo-grpc/proto/echo_response.pb.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)