frostfs-api-go/util/protogen/internal_gengo/getter.go
Evgenii Stratonikov 03759317ef
Some checks failed
DCO action / DCO (pull_request) Failing after 2m20s
Tests and linters / Tests (1.19) (pull_request) Successful in 2m43s
Tests and linters / Tests (1.20) (pull_request) Successful in 2m50s
Tests and linters / Tests with -race (pull_request) Successful in 3m7s
Tests and linters / Lint (pull_request) Failing after 3m53s
protogen: Initial implementation
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-08-06 16:56:37 +03:00

14 lines
480 B
Go

package internal_gengo
import "google.golang.org/protobuf/compiler/protogen"
func emitGetterSetter(g *protogen.GeneratedFile, typeName string, fieldName string, fieldType string, defaultValue string) {
g.P("func (x *", typeName, ") Get", fieldName, "() ", fieldType, " {")
g.P("if x != nil { return x.", fieldName, "}")
g.P("return ", defaultValue)
g.P("}")
g.P("func (x *", typeName, ") Set", fieldName, "(v ", fieldType, ") {")
g.P("x.", fieldName, " = v")
g.P("}")
}