Stop embedding a build tag in a template string for 'go vet'

This commit is contained in:
Hajime Hoshi 2016-05-14 00:36:41 +09:00
parent 16ddb8b0d2
commit 003e3e741e

View File

@ -109,7 +109,7 @@ const uiKeysGlfwTmpl = `{{.License}}
// {{.Notice}} // {{.Notice}}
// +build !js {{.BuildTag}}
package ui package ui
@ -133,7 +133,7 @@ const uiKeysJSTmpl = `{{.License}}
// {{.Notice}} // {{.Notice}}
// +build js {{.BuildTag}}
package ui package ui
@ -258,10 +258,20 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
// The build tag can't be included in the templates because of `go vet`.
// Pass the build tag and extract this in the template to make `go vet` happy.
buildTag := ""
switch path {
case "internal/ui/keys_glfw.go":
buildTag = "// +build !js"
case "internal/ui/keys_js.go":
buildTag = "// +build js"
}
// NOTE: According to godoc, maps are automatically sorted by key. // NOTE: According to godoc, maps are automatically sorted by key.
if err := tmpl.Execute(f, map[string]interface{}{ if err := tmpl.Execute(f, map[string]interface{}{
"License": license, "License": license,
"Notice": notice, "Notice": notice,
"BuildTag": buildTag,
"KeyCodeToName": keyCodeToName, "KeyCodeToName": keyCodeToName,
"Codes": codes, "Codes": codes,
"KeyNames": names, "KeyNames": names,