MCPcopy Create free account
hub / github.com/AudDMusic/RedditBot / loadConfig

Function loadConfig

main.go:1148–1169  ·  view source on GitHub ↗
(file string)

Source from the content-addressed store, hash-verified

1146}
1147
1148func loadConfig(file string) (*BotConfig, error) {
1149 var cfg BotConfig
1150 f, err := os.Open(file)
1151 if err != nil {
1152 return nil, err
1153 }
1154 j, err := ioutil.ReadAll(f)
1155 if err != nil {
1156 return nil, err
1157 }
1158 err = json.Unmarshal(j, &cfg)
1159 if err != nil {
1160 return nil, err
1161 }
1162 if stringInSlice(cfg.Triggers, "") {
1163 return nil, fmt.Errorf("got a config with an empty string in the triggers")
1164 }
1165 if stringInSlice(cfg.AntiTriggers, "") {
1166 return nil, fmt.Errorf("got a config with an empty string in the anti-triggers")
1167 }
1168 return &cfg, nil
1169}
1170
1171func WatchChanges(filename string, updated chan struct{}, l *rate.Limiter) {
1172 watcher, err := fsnotify.NewWatcher()

Callers 1

mainFunction · 0.85

Calls 1

stringInSliceFunction · 0.85

Tested by

no test coverage detected