Пример #1
0
func (self *ModuleApi) SetConfigValue(key string, value interface{}) error {
	self.mutex.Lock()
	defer self.mutex.Unlock()

	self.Config[key] = value

	if err := config.SaveToFile(self.config_filename, self); err != nil {
		delete(self.Config, key)
		return err
	}

	return nil
}
Пример #2
0
// Delete a config value from the config
// Returns an error if the value can not be deleted
func (self *ModuleApi) DeleteConfigValue(key string) error {
	self.mutex.Lock()
	defer self.mutex.Unlock()

	value, ok := self.Config[key]
	if !ok {
		return nil
	}

	delete(self.Config, key)
	if err := config.SaveToFile(self.config_filename, self); err != nil {
		self.Config[key] = value
		return err
	}

	return nil
}
Пример #3
0
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")
}