photoprism/internal/maps/gen.go
Eng Zer Jun 44f7700c0c
Enable module graph pruning and deprecate io/ioutil (#1600)
* Backend: Enable Go module graph pruning and lazy module loading

This commit applies the changes by running `go mod tidy -go=1.17` to
enable module graph pruning and lazy module loading supported by Go 1.17
or higher.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

* Backend: Move from io/ioutil to io and os package

The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-10-06 07:10:50 +02:00

60 lines
936 B
Go

//go:build ignore
// +build ignore
// This generates countries.go by running "go generate"
package main
import (
"encoding/json"
"os"
"strings"
"text/template"
)
type Country struct {
Code string
Name string
}
var countries []Country
func main() {
rawData, err := os.ReadFile("./countries.json")
if err != nil {
panic(err)
}
err = json.Unmarshal(rawData, &countries)
if err != nil {
panic(err)
}
f, err := os.Create("countries.go")
if err != nil {
panic(err)
}
defer f.Close()
for i, v := range countries {
countries[i].Code = strings.ToLower(v.Code)
}
packageTemplate.Execute(f, struct {
Countries []Country
}{
Countries: countries,
})
}
var packageTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT.
package maps
var CountryNames = map[string]string{
{{- range .Countries }}
{{ printf "%q" .Code }}: {{ printf "%q" .Name }},
{{- end }}
}`))