draft
This commit is contained in:
parent
5acfd28ccc
commit
a0826cd68d
@ -6,33 +6,59 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
const Path = "/usr/shared/dictionary/words"
|
||||
const Directory = "/usr/shared/dictionary/words"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Generate")
|
||||
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
|
||||
|
||||
f, err := os.Create("internal/dictionary/words.go")
|
||||
die(err)
|
||||
defer f.Close()
|
||||
var {{ .VarName }} = []string{
|
||||
{{- range .Words }}
|
||||
{{ printf "%q" . }},
|
||||
{{- end }}
|
||||
}
|
||||
`))
|
||||
|
||||
packageTemplate.Execute(f, struct {
|
||||
type templateData struct {
|
||||
Timestamp time.Time
|
||||
Path string
|
||||
Words []string
|
||||
}{
|
||||
Timestamp: time.Now(),
|
||||
Path: Path,
|
||||
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) {
|
||||
@ -41,16 +67,4 @@ func die(err error) {
|
||||
}
|
||||
}
|
||||
|
||||
var packageTemplate = 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 Words = []string{
|
||||
{{- range .Words }}
|
||||
{{ printf "%q" . }},
|
||||
{{- end }}
|
||||
}
|
||||
`))
|
||||
var packageTemplate = template.Must(template.New("").Parse())
|
||||
|
Loading…
x
Reference in New Issue
Block a user