Skip to content

Commit

Permalink
feat: valdate resource name upon unmarshalling
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Apr 11, 2024
1 parent d7df62c commit 505461a
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 17 deletions.
9 changes: 8 additions & 1 deletion cmd/protoc-gen-go-aip/internal/genaip/resourcename.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (r resourceNameCodeGenerator) generateUnmarshalStringMethod(
})
g.P()
g.P("func (n *", typeName, ") UnmarshalString(name string) error {")
g.P("return ", resourcenameSscan, "(")
g.P("err := ", resourcenameSscan, "(")
g.P("name,")
g.P(strconv.Quote(pattern), ",")
var sc resourcename.Scanner
Expand All @@ -340,6 +340,13 @@ func (r resourceNameCodeGenerator) generateUnmarshalStringMethod(
}
}
g.P(")")
g.P("if err != nil {")
g.P("return err")
g.P("}")
g.P("if err := n.Validate(); err != nil {")
g.P("return err")
g.P("}")
g.P("return nil")
g.P("}")
return nil
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion proto/gen/einride/example/freight/v1/shipment_aip.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion proto/gen/einride/example/freight/v1/shipper_aip.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion proto/gen/einride/example/freight/v1/site_aip.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 505461a

Please sign in to comment.