Compare commits

...

2 commits

Author SHA1 Message Date
4bf5698418 Enforce coding style in generated dns_rr.ts
All checks were successful
continuous-integration/drone/push Build is passing
2026-02-14 19:20:49 +07:00
7427ed7270 Remove last generation date from generated files for build reproducibility 2026-02-14 19:13:09 +07:00
4 changed files with 486 additions and 505 deletions

View file

@ -1,6 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by tools/gen_dns_type_mapping.go
// Last generation: Sun Jan 11 21:36:57 +07 2026
package usecase

View file

@ -31,7 +31,6 @@ import (
"sort"
"strings"
"text/template"
"time"
"github.com/miekg/dns"
)
@ -82,15 +81,8 @@ func main() {
})
}
// For reproducible builds, use SOURCE_DATE_EPOCH if set
timestamp := time.Now()
if epoch := os.Getenv("SOURCE_DATE_EPOCH"); epoch != "" {
timestamp = time.Unix(0, 0)
}
tmpl := template.Must(template.New("dns_types").Parse(`// Code generated by go generate; DO NOT EDIT.
// This file was generated by tools/gen_dns_type_mapping.go
// Last generation: {{.Timestamp}}
package usecase
@ -118,11 +110,9 @@ func (ssu *serviceSpecsUsecase) getRRType(t reflect.Type) uint16 {
`))
data := struct {
Timestamp string
Types []DNSType
Types []DNSType
}{
Timestamp: timestamp.Format(time.UnixDate),
Types: dnsTypes,
Types: dnsTypes,
}
if err := tmpl.Execute(fd, data); err != nil {

View file

@ -33,7 +33,6 @@ import (
"slices"
"sort"
"strings"
"time"
"github.com/miekg/dns"
)
@ -71,11 +70,11 @@ func getRrtype(fd io.Writer) {
return %d;
`, strings.ToUpper(rr), strings.ToLower(rr), ty)
}
fmt.Fprint(fd, " default:\n throw(\"Unknown rrtype \" + input);\n }\n")
fmt.Fprint(fd, " default:\n throw \"Unknown rrtype \" + input;\n }\n")
}
func newRR(fd io.Writer) {
fmt.Fprint(fd, " const rec = { Hdr: {Name: dn, Rrtype: rrtype, Class: 1, Ttl: 3600} } as dnsRR;\n\n")
fmt.Fprint(fd, " const rec = { Hdr: { Name: dn, Rrtype: rrtype, Class: 1, Ttl: 3600 } } as dnsRR;\n\n")
fmt.Fprint(fd, " switch (rrtype) {\n")
for _, ty := range getSortedTypes() {
rr, ok := dns.TypeToRR[ty]
@ -99,7 +98,7 @@ func newRR(fd io.Writer) {
if t.Field(i).Name == "Hdr" {
continue
}
fmt.Fprintf(fd, " rec.%s = ", t.Field(i).Name)
fmt.Fprintf(fd, " rec.%s = ", t.Field(i).Name)
// Check if this type maps to string in TypeScript (same logic as toTSType)
if t.Field(i).Type.Name() == "[]string" || t.Field(i).Type.Name() == "IP" || t.Field(i).Name == "Txt" {
fmt.Fprint(fd, `""`)
@ -112,7 +111,7 @@ func newRR(fd io.Writer) {
}
fmt.Fprint(fd, ";\n")
}
fmt.Fprint(fd, " return rec;\n")
fmt.Fprint(fd, " return rec;\n")
}
fmt.Fprint(fd, " default: return rec;\n }\n")
}
@ -356,16 +355,10 @@ func main() {
}
defer fd.Close()
// For reproducible builds, use SOURCE_DATE_EPOCH if set
timestamp := time.Now()
if epoch := os.Getenv("SOURCE_DATE_EPOCH"); epoch != "" {
// SOURCE_DATE_EPOCH is used for reproducible builds
timestamp = time.Unix(0, 0)
}
fmt.Fprint(fd, "// This file is generated by go generate\n// Last generation: "+timestamp.Format(time.UnixDate)+"\n\n")
fmt.Fprint(fd, "// This file is generated by go generate\n\n")
fmt.Fprintln(fd, "export interface SVCBKeyValue {};\n")
fmt.Fprintln(fd, "export interface EDNS0 {};\n")
fmt.Fprintln(fd, "export interface SVCBKeyValue {}\n")
fmt.Fprintln(fd, "export interface EDNS0 {}\n")
// Helper function to quote strings containing special DNS characters
fmt.Fprintln(fd, "// Helper function to quote strings containing special DNS characters (spaces, quotes, semicolons, parentheses)")
@ -379,7 +372,7 @@ func main() {
// dnsRR
fmt.Fprint(fd, "export interface dnsRR {\n")
dnsrr(fd)
fmt.Fprint(fd, "};\n\n")
fmt.Fprint(fd, "}\n\n")
// dnsType
for _, ty := range getSortedTypes() {
@ -397,8 +390,8 @@ func main() {
t = t.Field(0).Type
}
fmt.Fprint(fd, toTSType(t, 0))
fmt.Fprintf(fd, ";\n\n")
fmt.Fprint(fd, " ", toTSType(t, 0))
fmt.Fprintf(fd, "\n\n")
}
// dnsResource
@ -423,30 +416,30 @@ func main() {
fmt.Fprintf(fd, " %s?: dnsType%s;\n", strings.Replace(strings.ToLower(dns.TypeToString[ty]), "-", "_", -1), strings.Replace(dns.TypeToString[ty], "-", "_", -1))
}
}
fmt.Fprint(fd, "};\n\n")
fmt.Fprint(fd, "}\n\n")
// getRrtype
fmt.Fprint(fd, "export function getRrtype(input: string): number {\n")
getRrtype(fd)
fmt.Fprint(fd, "};\n\n")
fmt.Fprint(fd, "}\n\n")
// newRR
fmt.Fprint(fd, "export function newRR(dn: string, rrtype: number): dnsRR {\n")
newRR(fd)
fmt.Fprint(fd, "};\n\n")
fmt.Fprint(fd, "}\n\n")
// nsrrtype
fmt.Fprint(fd, "export function nsrrtype(input: number | string): string {\n")
nsrrtype(fd)
fmt.Fprint(fd, "};\n\n")
fmt.Fprint(fd, "}\n\n")
// rdatatostr
fmt.Fprint(fd, "export function rdatatostr(rr: dnsRR): string {\n")
rdatatostr(fd)
fmt.Fprint(fd, "};\n\n")
fmt.Fprint(fd, "}\n\n")
// rdataFields
fmt.Fprint(fd, "export function rdatafields(input: number | string): Array<string> {\n")
rdataFields(fd)
fmt.Fprint(fd, "};\n\n")
fmt.Fprint(fd, "}\n\n")
}

File diff suppressed because it is too large Load diff