Skip to content

Commit 8444a7d

Browse files
docs: update CLAUDE.md with protoc-gen-go-client documentation
- Add client generator to project overview - Document plugin structure and core components - Add HTTP client code examples with functional options pattern - Document per-call options for request customization Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 09a2fc5 commit 8444a7d

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

CLAUDE.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
This is `sebuf`, a specialized Go protobuf toolkit for building HTTP APIs. It consists of two complementary protoc plugins that together enable modern, type-safe API development:
7+
This is `sebuf`, a specialized Go protobuf toolkit for building HTTP APIs. It consists of three complementary protoc plugins that together enable modern, type-safe API development:
88

99
- **`protoc-gen-go-http`**: Generates HTTP handlers, routing, request/response binding, and automatic validation
10+
- **`protoc-gen-go-client`**: Generates type-safe HTTP clients with functional options pattern
1011
- **`protoc-gen-openapiv3`**: Creates comprehensive OpenAPI v3.1 specifications
1112

1213
The toolkit enables developers to build HTTP APIs directly from protobuf definitions without gRPC dependencies, targeting web and mobile API development with built-in request validation.
@@ -17,19 +18,22 @@ The project follows a clean Go protoc plugin architecture with separated concern
1718

1819
### Plugin Structure
1920
- **cmd/protoc-gen-go-http/**: HTTP handler generator entry point
21+
- **cmd/protoc-gen-go-client/**: HTTP client generator entry point
2022
- **cmd/protoc-gen-openapiv3/**: OpenAPI specification generator entry point
2123
- **internal/httpgen/**: HTTP handler generation logic, annotations, and header validation middleware
24+
- **internal/clientgen/**: HTTP client generation logic and annotations
2225
- **internal/openapiv3/**: OpenAPI generation logic, type mapping, and header parameter generation
2326
- **proto/sebuf/http/**: HTTP annotation definitions including headers.proto for header validation
2427
- **scripts/**: Test automation and build scripts
2528

2629
### Core Components
2730

2831
1. **HTTP Handler Generator** (`internal/httpgen/generator.go:22`): Generates HTTP handlers, request binding, routing configuration, automatic body validation, and header validation middleware
29-
2. **OpenAPI Generator** (`internal/openapiv3/generator.go:53`): Creates comprehensive OpenAPI v3.1 specifications from protobuf definitions with full header parameter support, generating one file per service for better organization
30-
3. **HTTP Annotations** (`proto/sebuf/http/annotations.proto`): Custom protobuf extensions for HTTP configuration
31-
4. **Header Validation** (`proto/sebuf/http/headers.proto`): Protobuf definitions for service and method-level header validation
32-
5. **Validation System**: Automatic request body validation via buf.validate/protovalidate and header validation middleware
32+
2. **HTTP Client Generator** (`internal/clientgen/generator.go:13`): Generates type-safe HTTP clients with functional options pattern, automatic request/response marshaling, and error handling
33+
3. **OpenAPI Generator** (`internal/openapiv3/generator.go:53`): Creates comprehensive OpenAPI v3.1 specifications from protobuf definitions with full header parameter support, generating one file per service for better organization
34+
4. **HTTP Annotations** (`proto/sebuf/http/annotations.proto`): Custom protobuf extensions for HTTP configuration
35+
5. **Header Validation** (`proto/sebuf/http/headers.proto`): Protobuf definitions for service and method-level header validation
36+
6. **Validation System**: Automatic request body validation via buf.validate/protovalidate and header validation middleware
3337

3438
### Generated Output Examples
3539

@@ -44,6 +48,27 @@ type UserServiceServer interface {
4448
func RegisterUserServiceServer(server UserServiceServer, opts ...ServerOption) error
4549
```
4650

51+
**HTTP Clients** - Type-safe HTTP client with functional options:
52+
```go
53+
// UserServiceClient is the client API for UserService
54+
type UserServiceClient interface {
55+
CreateUser(ctx context.Context, req *CreateUserRequest, opts ...UserServiceCallOption) (*User, error)
56+
}
57+
58+
// Create a client with options
59+
client := NewUserServiceClient(
60+
"http://localhost:8080",
61+
WithUserServiceHTTPClient(&http.Client{Timeout: 30 * time.Second}),
62+
WithUserServiceAPIKey("your-api-key"), // From service_headers annotation
63+
)
64+
65+
// Make requests with per-call options
66+
user, err := client.CreateUser(ctx, req,
67+
WithUserServiceHeader("X-Request-ID", "req-123"),
68+
WithUserServiceCallContentType(ContentTypeProto),
69+
)
70+
```
71+
4772
**OpenAPI Specifications** - Comprehensive API documentation (one file per service):
4873
```yaml
4974
# UserService.openapi.yaml

0 commit comments

Comments
 (0)