MCPcopy Create free account
hub / github.com/chainreactors/spray / LoadProtonTemplates

Function LoadProtonTemplates

pkg/proton.go:28–60  ·  view source on GitHub ↗

LoadProtonTemplates parses YAML template docs and builds a Scanner.

(yamlDocs [][]byte)

Source from the content-addressed store, hash-verified

26
27// LoadProtonTemplates parses YAML template docs and builds a Scanner.
28func LoadProtonTemplates(yamlDocs [][]byte) error {
29 protonMu.Lock()
30 defer protonMu.Unlock()
31
32 protonTemplates = nil
33 protonTemplateMap = make(map[string]*protonTmpl.Template)
34 protonTagMap = make(map[string][]string)
35
36 opts := &protocols.ExecuterOptions{Options: &protocols.Options{}}
37
38 for _, doc := range yamlDocs {
39 var tmpl protonTmpl.Template
40 if err := yaml.Unmarshal(doc, &tmpl); err != nil {
41 continue
42 }
43 if len(tmpl.RequestsFile) == 0 {
44 continue
45 }
46 if err := tmpl.Compile(opts); err != nil {
47 continue
48 }
49 protonTemplates = append(protonTemplates, &tmpl)
50 protonTemplateMap[tmpl.Id] = &tmpl
51 for _, tag := range tmpl.GetTags() {
52 tag = strings.TrimSpace(tag)
53 protonTagMap[tag] = append(protonTagMap[tag], tmpl.Id)
54 }
55
56 }
57
58 rebuildScanner()
59 return nil
60}
61
62// AppendProtonTemplates parses YAML template docs and appends to the existing set.
63func AppendProtonTemplates(yamlDocs [][]byte) error {

Callers 3

LoadProtonRulesFunction · 0.85
mustLoadTemplatesFunction · 0.85

Calls 1

rebuildScannerFunction · 0.85

Tested by 1

mustLoadTemplatesFunction · 0.68