Skip to content

Commit

Permalink
templates/goshared: Avoid redundant whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
rvolosatovs committed Feb 25, 2019
1 parent 4bafc87 commit f5dfc51
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions templates/goshared/msg.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package goshared

const msgTpl = `
{{ if disabled . -}}
{{ cmt "ValidateFields is disabled for " (msgTyp .) ". This method will always return nil." }}
{{- else -}}
{{ cmt "ValidateFields checks the field values on " (msgTyp .) " with the rules defined in the proto definition for this message. If any rules are violated, an error is returned." }}
{{- end -}}
{{ if disabled . }}
{{- cmt "ValidateFields is disabled for " (msgTyp .) ". This method will always return nil." -}}
{{ else }}
{{- cmt "ValidateFields checks the field values on " (msgTyp .) " with the rules defined in the proto definition for this message. If any rules are violated, an error is returned." -}}
{{ end -}}
func (m {{ (msgTyp .).Pointer }}) ValidateFields(paths ...string) error {
{{ if disabled . -}}
return nil
{{ else -}}
{{- else -}}
{{ if .Fields -}}
if m == nil { return nil }
Expand All @@ -20,37 +20,37 @@ func (m {{ (msgTyp .).Pointer }}) ValidateFields(paths ...string) error {
for name, subs := range _processPaths(append(paths[:0:0], paths...)) {
_ = subs
switch name {
{{ range .NonOneOfFields }}
{{ range .NonOneOfFields -}}
case "{{ .Name }}":
{{ render (context .) }}
{{ end }}
{{ end -}}
{{ range .OneOfs }}
{{ range .OneOfs -}}
case "{{ .Name }}":
if len(subs) == 0 {
subs = []string{
{{ range .Fields }}
{{ range .Fields -}}
"{{ .Name }}",
{{ end }}
{{- end }}
}
}
for name, subs := range _processPaths(subs) {
_ = subs
switch name {
{{ range .Fields }}
{{ range .Fields -}}
case "{{ .Name }}":
{{ render (context .) }}
{{ end }}
{{ end -}}
{{ if required . }}
default:
return {{ errname .Message }}{
field: {{ .Name }},
reason: "value is required",
}
{{ end }}
{{ end -}}
}
}
{{ end }}
{{ end -}}
default:
return {{ errname . }} {
field: name,
Expand All @@ -59,13 +59,13 @@ func (m {{ (msgTyp .).Pointer }}) ValidateFields(paths ...string) error {
}
}
return nil
{{else -}}
{{ else -}}
if len(paths) > 0 {
return fmt.Errorf("message {{ msgTyp . }} has no fields, but paths %s were specified", paths)
}
return nil
{{end -}}
{{ end -}}
{{ end -}}
{{- end -}}
}
{{ if needs . "hostname" }}{{ template "hostname" . }}{{ end }}
Expand Down

0 comments on commit f5dfc51

Please sign in to comment.