// Initialises the config map and tries to fill it with values from the given // JSON formated file. The function should not be called within Run because it // is not thread save. // It returns an error if the file can not be opened or the JSON has a wrong // format. func (self *ModuleApi) InitConfig(filename string) error { self.Config = make(map[string]interface{}) self.config_filename = self.state.ServerName + "/" + filename config.CreateConfigPath(self.state.ServerName) return config.LoadFromFile(self.config_filename, self) }
func main() { conf := &Config{} if err := config.LoadFromFile(CONFIG_FILE, conf); err != nil { conf.Config = make([]Server, 1) conf.Config[0].Name = "dev-urandom" conf.Config[0].Address = "dev-urandom.eu" conf.Config[0].Port = "6697" conf.Config[0].SSLConfig.UseSSL = true conf.Config[0].SSLConfig.SkipVerify = false if err = config.SaveToFile(CONFIG_FILE, conf); err != nil { panic("Cant create config file") } } if len(conf.Config) == 0 { panic("No server given") } wgr := &sync.WaitGroup{} for i := range conf.Config { wgr.Add(1) go func(server *Server) { defer wgr.Done() mhandler := handler.NewModuleHandler(server.Name, server.Address) if err := mhandler.LoadModules(); err != nil { panic(fmt.Sprintf("Can't load modules: %v", err)) } evt := irc.NewIRCHandler(mhandler) evt.SetServer(fmt.Sprintf("%v:%v", server.Address, server.Port), &server.SSLConfig) evt.HandleIRConn() }(&conf.Config[i]) } wgr.Wait() log.Println("All connections are gone; I'll better kill myself") }