71 lines
1.1 KiB
Go
71 lines
1.1 KiB
Go
//go:build ignore
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
"text/template"
|
|
"time"
|
|
)
|
|
|
|
const Directory = "/usr/shared/dictionary/words"
|
|
|
|
var wordsTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT.
|
|
// This file was generated by robots at
|
|
// {{ .Timestamp }}
|
|
// using data from
|
|
// {{ .Path }}
|
|
package dictionary
|
|
|
|
var {{ .VarName }} = []string{
|
|
{{- range .Words }}
|
|
{{ printf "%q" . }},
|
|
{{- end }}
|
|
}
|
|
`))
|
|
|
|
type templateData struct {
|
|
Timestamp time.Time
|
|
Path string
|
|
Words []string
|
|
VarName string
|
|
}
|
|
|
|
func generateFile(name string) {
|
|
lowerName := strings.ToLower(name)
|
|
|
|
words := []string{
|
|
"foo",
|
|
"bar",
|
|
"baz",
|
|
}
|
|
Path := Directory + lowerName
|
|
|
|
f, err := os.Create("internal/dictionary/" + lowerName + ".go")
|
|
die(err)
|
|
defer f.Close()
|
|
|
|
wordsTemplate.Execute(f, templateData{
|
|
Timestamp: time.Now(),
|
|
Path: Path,
|
|
Words: words,
|
|
VarName: strings.Title(name),
|
|
})
|
|
}
|
|
|
|
func main() {
|
|
fmt.Println("Generate")
|
|
generateFile("words")
|
|
}
|
|
|
|
func die(err error) {
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
var packageTemplate = template.Must(template.New("").Parse())
|