-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgenerator.go
54 lines (49 loc) · 1.34 KB
/
generator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// +build ignore
package main
import (
fun "github.com/DylanMeeus/hasgo/functions"
"io/ioutil"
"os"
"strings"
"text/template"
)
var packageTemplate = template.Must(template.New("").
Parse("// Code generated by go generate; DO NOT EDIT.\n" +
"package main\n" +
"\n" +
"var hasgoTemplates = map[string]string{\n" +
"{{ range $fn, $file := . }}" +
"\t\"{{ $fn }}\": `{{ $file }}`,\n" +
"{{ end }}" +
"}\n"))
var domainTemplate = template.Must(template.New("").
Parse("\n" +
"const (\n ForNumbers = \"ForNumbers\"\nForStrings = \"ForStrings\"\n" +
"ForStructs = \"ForStructs\"\n)\n" +
"var funcDomains = map[string][]string{\n" +
"{{ range $fn, $arr := . }}" +
"\t\"{{ $fn }}\": []string{ {{ range $index, $dom := $arr }}" +
" {{if $index}} ,{{end}} {{$dom}} {{end}} },\n" +
"{{ end }}" +
"}\n"))
// generate the templates that will be used for hasgo
func main() {
data := map[string]string{}
for k := range fun.Templates() {
content, err := ioutil.ReadFile("./functions/" + k)
// remove the package statement..
parts := strings.Split(string(content), "\n")
sanitized := strings.Join(parts[1:], "\n")
if err != nil {
panic(err)
}
data[k] = sanitized
}
f, err := os.Create("template.go")
if err != nil {
panic(err)
}
defer f.Close()
packageTemplate.Execute(f, data)
domainTemplate.Execute(f, fun.Templates())
}