LoadProtonTemplates parses YAML template docs and builds a Scanner.
(yamlDocs [][]byte)
| 26 | |
| 27 | // LoadProtonTemplates parses YAML template docs and builds a Scanner. |
| 28 | func 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. |
| 63 | func AppendProtonTemplates(yamlDocs [][]byte) error { |