@@ -3,11 +3,15 @@ package clone
3
3
import (
4
4
"bytes"
5
5
"errors"
6
+ "strings"
6
7
"text/template"
7
8
8
9
pgs "github.com/lyft/protoc-gen-star"
9
10
)
10
11
12
+ // packages that use k8s/gogo and require DeepCopy because they do not support proto.Clone or Reflect
13
+ var gogoPackagesParamName = "gogo_packages"
14
+
11
15
type Value struct {
12
16
Name string
13
17
TargetName string
@@ -38,8 +42,13 @@ func (fns goSharedFuncs) render(field pgs.Field) (string, error) {
38
42
case pgs .StringT :
39
43
tpl = template .Must (fns .tpl .New ("string" ).Parse (stringTpl ))
40
44
case pgs .MessageT :
41
- tpl = template .Must (fns .tpl .New ("message" ).Parse (messageTpl ))
42
45
typeName = fns .typeName (field )
46
+ packageName := fns .fieldPackageName (field )
47
+ if fns .contains (strings .Split (fns .Params ().Str (gogoPackagesParamName ), "|" ), packageName ) {
48
+ tpl = template .Must (fns .tpl .New ("message" ).Parse (messageGogoTpl ))
49
+ } else {
50
+ tpl = template .Must (fns .tpl .New ("message" ).Parse (messageTpl ))
51
+ }
43
52
default :
44
53
return "" , errors .New ("unknown type" )
45
54
}
@@ -158,8 +167,13 @@ func (fns goSharedFuncs) simpleRender(
158
167
case pgs .StringT :
159
168
tpl = template .Must (fns .tpl .New ("string" ).Parse (stringTpl ))
160
169
case pgs .MessageT :
161
- tpl = template .Must (fns .tpl .New ("message" ).Parse (messageTpl ))
162
170
typeName = fns .entityTypeName (field , typeElem )
171
+ packageName := fns .fieldPackageName (field )
172
+ if fns .contains (strings .Split (fns .Params ().Str (gogoPackagesParamName ), "|" ), packageName ) {
173
+ tpl = template .Must (fns .tpl .New ("message" ).Parse (messageGogoTpl ))
174
+ } else {
175
+ tpl = template .Must (fns .tpl .New ("message" ).Parse (messageTpl ))
176
+ }
163
177
default :
164
178
return "" , errors .New ("unknown type" )
165
179
}
0 commit comments