Skip to content

Commit 4bf8570

Browse files
committed
Use proto2 Enum helper instead of toPointer
My bad.
1 parent 26836d7 commit 4bf8570

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

legacy/translate.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func translateRules(rules protoreflect.Message) *pv.FieldConstraints {
7070
if msgRules.Get(msgDesc.Fields().ByName("required")).Bool() {
7171
constraints.Required = proto.Bool(true)
7272
} else if msgRules.Get(msgDesc.Fields().ByName("skip")).Bool() {
73-
constraints.Ignore = toPointer(pv.Ignore_IGNORE_ALWAYS)
73+
constraints.Ignore = pv.Ignore_IGNORE_ALWAYS.Enum()
7474
}
7575
}
7676

@@ -105,7 +105,7 @@ func translateRule(
105105
return true
106106
} else if pgvDesc.Name() == "ignore_empty" && pgvDesc.Kind() == protoreflect.BoolKind && value.Bool() {
107107
// old `ignore_empty` fields on the type rules need to be lifted to the top level
108-
constraints.Ignore = toPointer(pv.Ignore_IGNORE_IF_UNPOPULATED)
108+
constraints.Ignore = pv.Ignore_IGNORE_IF_UNPOPULATED.Enum()
109109
return true
110110
}
111111

@@ -144,7 +144,3 @@ func translateRule(
144144
}
145145
return true
146146
}
147-
148-
func toPointer[T any](value T) *T {
149-
return &value
150-
}

legacy/translate_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func TestTranslateFieldOptions(t *testing.T) {
113113
msg: &examplev1.LegacySkipped{},
114114
field: "x",
115115
ex: &validate.FieldConstraints{
116-
Ignore: toPointer(validate.Ignore_IGNORE_ALWAYS),
116+
Ignore: validate.Ignore_IGNORE_ALWAYS.Enum(),
117117
},
118118
},
119119
{
@@ -200,7 +200,7 @@ func TestTranslateFieldOptions(t *testing.T) {
200200
msg: &examplev1.LegacyIgnoreEmpty{},
201201
field: "x",
202202
ex: &validate.FieldConstraints{
203-
Ignore: toPointer(validate.Ignore_IGNORE_IF_UNPOPULATED),
203+
Ignore: validate.Ignore_IGNORE_IF_UNPOPULATED.Enum(),
204204
Type: &validate.FieldConstraints_Int32{
205205
Int32: &validate.Int32Rules{
206206
GreaterThan: &validate.Int32Rules_Gt{

0 commit comments

Comments
 (0)