//go:build ignore

// string_generate generates zstring.go which houses the Handler strings slice.

package main

import (
	"bytes"
	"html/template"
	"log"
	"strings"

	"codeberg.org/miekg/dns/cmd/atomdns/internal/generate"
)

const hdr = `
// Code generated by "go run string_generate.go"; DO NOT EDIT.

package dnsserver

`

var funcmap = template.FuncMap{
	"tolower": strings.ToLower,
}

var Strings = template.Must(template.New("strings").Funcs(funcmap).Parse(`
// Handlers is a slices of handler names.
var Handlers = []string{
{{range .}} "{{tolower .}}",
{{end}}
}

`))

const out = "zstring.go"

func main() {
	handlers, err := generate.Handlers("../../handlers")
	if err != nil {
		log.Fatal(err)
	}
	source := &bytes.Buffer{}
	source.WriteString(hdr)

	if err := Strings.Execute(source, handlers); err != nil {
		log.Fatalf("Failed to generate %s: %v", out, err)
	}

	generate.Write(source, out)
}
