write base server
This commit is contained in:
45
gen/gen.go
Normal file
45
gen/gen.go
Normal file
@@ -0,0 +1,45 @@
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
const tmpl = `// Code generated by gen/gen.go — DO NOT EDIT
|
||||
package main
|
||||
|
||||
import (
|
||||
{{- range .}}
|
||||
_ "{{.}}"
|
||||
{{- end}}
|
||||
)
|
||||
`
|
||||
|
||||
func main() {
|
||||
var packages []string
|
||||
moduleName := "bdgrp_go"
|
||||
|
||||
filepath.WalkDir("routes", func(path string, d os.DirEntry, err error) error {
|
||||
if err != nil || !d.IsDir() || path == "routes" {
|
||||
return nil
|
||||
}
|
||||
|
||||
entries, _ := os.ReadDir(path)
|
||||
for _, e := range entries {
|
||||
if !e.IsDir() && strings.HasSuffix(e.Name(), ".go") {
|
||||
pkg := moduleName + "/" + filepath.ToSlash(path)
|
||||
packages = append(packages, pkg)
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
f, _ := os.Create("routes_gen.go")
|
||||
defer f.Close()
|
||||
template.Must(template.New("").Parse(tmpl)).Execute(f, packages)
|
||||
}
|
||||
Reference in New Issue
Block a user