Skip to content

Commit

Permalink
Generate enum types with Contains() and Values() receiver methods
Browse files Browse the repository at this point in the history
Reference: aws#3441

Allows consumers to easily handle operations with all elements of API enumeration types.
  • Loading branch information
bflad committed Jul 25, 2020
1 parent 4c5b59f commit 1399db1
Show file tree
Hide file tree
Showing 205 changed files with 78,634 additions and 64 deletions.
23 changes: 23 additions & 0 deletions private/model/api/shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,29 @@ const (
{{ end }}
)
// {{ $.ShapeName }} is an enum
type {{ $.ShapeName }} struct{}
// Contains returns whether the {{ $.ShapeName }} enum includes the element
func (enum {{ $.ShapeName }}) Contains(element string) bool {
for _, v := range enum.Values() {
if v == element {
return true
}
}
return false
}
// Values returns all elements of the {{ $.ShapeName }} enum
func (enum {{ $.ShapeName }}) Values() []string {
return []string{
{{ range $index, $elem := $.Enum -}}
{{ index $.EnumConsts $index }},
{{ end }}
}
}
`))

// GoCode returns the rendered Go code for the Shape.
Expand Down
210 changes: 210 additions & 0 deletions service/accessanalyzer/api.go

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

Loading

0 comments on commit 1399db1

Please sign in to comment.