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 122ed75 commit 1a8c18f
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 17 deletions.
6 changes: 5 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,10 @@ func (r resourceNameCodeGenerator) generateUnmarshalStringMethod(
}
}
g.P(")")
g.P("if err != nil {")
g.P("return err")
g.P("}")
g.P("return n.Validate()")
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.

6 changes: 5 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.

6 changes: 5 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.

6 changes: 5 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 1a8c18f

Please sign in to comment.