Skip to content

Latest commit

 

History

History
79 lines (53 loc) · 1.59 KB

README.md

File metadata and controls

79 lines (53 loc) · 1.59 KB

proto-go-setter

Add setters for generated message fields. Supports scalar values (string, int32, etc) and maps with primitive types for both key and value.

This is an often-requested feature for protoc-gen-go that won't be added to the core generator. See:

Example

The simplest option is to just generate a setter for a single field.

syntax = "proto3";

import "github.com/confluentinc/proto-go-setter/setter.proto";

message Person {
  string id = 1;
  string name = 2 [(setter.include)=true];
}

Alternatively, you may want to generate setters for all fields in a message, or all fields except a single field.

syntax = "proto3";

import "github.com/confluentinc/proto-go-setter/setter.proto";

message Person {
  option (setter.all_fields) = true;

  string id = 1 [(setter.exclude)=true];
  string name = 2;
}

Lastly, you may want to generate setters for everything in a file.

syntax = "proto3";

import "github.com/confluentinc/proto-go-setter/setter.proto";

option (setter.all_messages) = true;

message Person {
  string id = 1 [(setter.exclude)=true];
  string name = 2;
}

You'd generate the setters code by running

$ protoc --setter_out=. person.proto

All three examples above would result in person_setter.go containing

func (t *Person) SetName(name string) {
	t.Name = name
}

LICENSE

MIT