setup generation

This commit is contained in:
Hazel Noack 2025-06-30 15:26:22 +02:00
parent 06845ed750
commit 5acfd28ccc
4 changed files with 84 additions and 0 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module gitea.elara.ws/Hazel/go-words
go 1.24.2

View File

@ -0,0 +1,12 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2025-06-30 15:25:49.978118211 +0200 CEST m=+0.000535670
// using data from
// /usr/shared/dictionary/words
package dictionary
var Words = []string{
"foo",
"bar",
"baz",
}

56
internal/gen.go Normal file
View File

@ -0,0 +1,56 @@
//go:build ignore
package main
import (
"fmt"
"log"
"os"
"text/template"
"time"
)
const Path = "/usr/shared/dictionary/words"
func main() {
fmt.Println("Generate")
f, err := os.Create("internal/dictionary/words.go")
die(err)
defer f.Close()
packageTemplate.Execute(f, struct {
Timestamp time.Time
Path string
Words []string
}{
Timestamp: time.Now(),
Path: Path,
Words: []string{
"foo",
"bar",
"baz",
},
})
}
func die(err error) {
if err != nil {
log.Fatal(err)
}
}
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 }}
}
`))

13
main.go Normal file
View File

@ -0,0 +1,13 @@
package main
import (
"fmt"
"gitea.elara.ws/Hazel/go-words/internal/dictionary"
)
//go:generate go run internal/gen.go
func main() {
fmt.Println(dictionary.Foo)
}