Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ func main() {
panic("could not determine underlying type for enum")
}

visited := make(map[string]bool, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucvankessel this no longer implements the PR title

for i := range enumValues{
if visited[enumValues[i].Value] == true{
panic("no duplicate values allowed in enum")
} else {
visited[enumValues[i].Value] = true
}
}

templates, err := template.New("").
Funcs(TemplateFunctions). // Custom functions
ParseFS(templates, "templates/*.tmpl")
Expand Down
4 changes: 4 additions & 0 deletions templates/enum.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ func ({{ $lt }} {{ $t }}) String() string {
switch {{ $lt }} {
{{- range $index, $enum := $.EnumValues }}
case {{ $enum.Name }}:
{{- if eq $.BaseType "string" }}
return {{ $enum.Value }}
{{- else }}
return "{{ stringer $enum.Name }}"
{{- end }}
{{- end }}
default:
{{- if $default := $.EnumDefaultValue }}
return {{ $default }}.String()
Expand Down