Skip to content

Commit 427695e

Browse files
committed
CHANGELOG, README: update for (go.field).embed
1 parent 2d10f6f commit 427695e

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
44

55
## [Unreleased]
66

7+
### Added
8+
- [#65](https://github.com/alta/protopatch/pull/56): embedded message fields. Set `(go.field).embed = true` to embed a message field in the generated Go struct. The resulting field will be a pointer to and sharing a name with the generated Go struct.
9+
710
### Updated
811
- github.com/envoyproxy/protoc-gen-validate v0.6.0 → v0.6.1 (reverted breaking API change)
912
- golang.org/x/tools v0.1.0 → v0.1.6
1013
- google.golang.org/protobuf v1.26.0 → v1.27.1
14+
1115
## [v0.3.4] — 2021-04-23
1216

1317
### Updated
@@ -22,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2226
- golang.org/x/tools v0.0.0-20201223225330-bdbb3c917f0b → v0.1.0
2327
- google.golang.org/protobuf v1.25.0 → v1.26.0
2428
- protoc v3.14.0 → v3.15.6
29+
2530
## [v0.3.2] — 2021-03-12
2631

2732
### Fixed

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,53 @@ message ToDo {
9090
}
9191
```
9292

93+
### Embedded Fields
94+
95+
A message field can be embedded in the generated [Go struct](https://golang.org/ref/spec#Struct_types) with the `(go.field).embed` option. This only works for message fields, and will not work for oneof fields or basic types.
96+
97+
```proto
98+
import "patch/go.proto";
99+
100+
message A {
101+
B b = 1 [(go.field).embed = true];
102+
}
103+
104+
message B {
105+
string value = 1;
106+
}
107+
```
108+
109+
The resulting Go struct will partially have the form:
110+
111+
```go
112+
type A struct {
113+
*B
114+
}
115+
116+
type B struct {
117+
Value string
118+
}
119+
120+
var a A
121+
a.Value = "value" // This works because B is embedded in A
122+
```
123+
124+
#### Alternate Syntax
125+
126+
Multiple options can be grouped together with a message bounded by `{}`:
127+
128+
```proto
129+
import "patch/go.proto";
130+
131+
message A {
132+
B b = 1 [(go.field) = {embed: true}];
133+
}
134+
135+
message B {
136+
string value = 1;
137+
}
138+
```
139+
93140
### Linting
94141

95142
Protopatch can automatically “lint” generated names into something resembling [idiomatic Go style](https://golang.org/doc/effective_go.html#names). This feature should be considered *unstable*, and the names it generates are subject to change as this feature evolves.

0 commit comments

Comments
 (0)