-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.go
More file actions
51 lines (42 loc) · 993 Bytes
/
common.go
File metadata and controls
51 lines (42 loc) · 993 Bytes
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
package codegen
import (
"embed"
"io/fs"
"text/template"
"github.com/bmatcuk/doublestar/v4"
networks "github.com/streamingfast/firehose-networks"
)
//go:embed common-templates/*
var commonTemplatesFS embed.FS
var commonTemplates *template.Template
func init() {
var err error
commonTemplates, err = parseCommonTemplates()
if err != nil {
panic(err)
}
}
func IsValidChain(input string) bool {
return networks.GetSubstreamsRegistry().Find(input) != nil
}
func MarkdownEscape(s string) string {
return "```\n" + s + "\n```\n"
}
func parseCommonTemplates() (*template.Template, error) {
t := template.New("").Funcs(templateFuncs)
filenames, err := doublestar.Glob(commonTemplatesFS, "**/*.gotmpl")
if err != nil {
return nil, err
}
for _, filename := range filenames {
b, err := fs.ReadFile(commonTemplatesFS, filename)
if err != nil {
return nil, err
}
_, err = t.New(filename).Parse(string(b))
if err != nil {
return nil, err
}
}
return t, nil
}