https://github.com/kostyay/protoc-gen-go-access-modifiers
This is a POC for a go protoc plugin that adds access modifiers to proto fields and methods
https://github.com/kostyay/protoc-gen-go-access-modifiers
grpc grpc-golang protoc protocol-buffers
Last synced: about 2 months ago
JSON representation
This is a POC for a go protoc plugin that adds access modifiers to proto fields and methods
- Host: GitHub
- URL: https://github.com/kostyay/protoc-gen-go-access-modifiers
- Owner: kostyay
- License: mit
- Created: 2023-03-31T20:27:17.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-01T21:05:32.000Z (about 2 years ago)
- Last Synced: 2025-02-04T14:36:44.529Z (4 months ago)
- Topics: grpc, grpc-golang, protoc, protocol-buffers
- Language: Go
- Homepage:
- Size: 37.1 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
protoc-gen-go-access-modifiers
======================__This is a proof of concept plugin__ for protoc that generates Go code.
It introduces the notion of access modifiers for message fields and methods.
For message fields it allows defining them as private and generates a `AsPublic()` method that empties the private fields into a public struct.
It is provided as a part of my blog post on gRPC API gateways.
This is not the final version of the plugin, but it is a good starting point for getting the idea how to use it.
In addition to the plugin you will find a gRPC client middleware strips private fields off incoming client responses.
# Usage
```bash
go install github.com/kostyay/protoc-gen-go-access-modifiers@latest
```Add to `buf.gen.yaml`:
```yaml
plugins:
- name: protoc-gen-go-access-modifiers
out: .
opt: paths=source_relative
```To mark a field as private, add the `(access.v1.fo).private = true` option to the field:
```proto
import "access/v1/access.proto";message PrivateMessage {
string public_field = 1;
string private_field = 2 [(access.v1.fo).private = true];
}
```To mark a method as private, add the `(access.v1.mo).private = true` option to the method:
```proto
import "access/v1/access.proto";service PrivateService {
rpc PublicMethod(PublicRequest) returns (PublicResponse) {}
rpc PrivateMethod(PrivateRequest) returns (PrivateResponse) {
option (access.v1.mo).private = true;
}
}
```