-
Notifications
You must be signed in to change notification settings - Fork 52
/
module_config.go
47 lines (41 loc) · 959 Bytes
/
module_config.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
package config
import (
"io/ioutil"
"log"
"github.com/k0kubun/pp"
yaml "gopkg.in/yaml.v2"
)
type ModuleConfig struct {
Name string
Description string
Author string
Icon string
Thumbnail string
Template TemplateConfig
Credentials []string `yaml:"requiredCredentials"`
Prompts []Prompt `yaml:"parameters"`
}
type Prompt struct {
Field string `yaml:"field,omitempty"`
Label string
Options []string `yaml:"options,omitempty"`
Execute string `yaml:"execute,omitempty"`
}
type TemplateConfig struct {
StrictMode bool
Delimiters []string
Output string
}
func LoadModuleConfig(filePath string) *ModuleConfig {
config := &ModuleConfig{}
data, err := ioutil.ReadFile(filePath)
if err != nil {
log.Panicf("failed to read config: %v", err)
}
err = yaml.Unmarshal(data, &config)
if err != nil {
log.Panicf("failed to parse config: %v", err)
}
pp.Println("Module Config:", config)
return config
}