Exemple #1
0
func loadTemplate() {
	var templates []t.SMSTemplate
	existed := mongodb.Exec(CollSMSTemplate, func(c *mgo.Collection) error {
		return c.Find(nil).Sort("-timestamp").All(&templates)
	})
	if !existed || len(templates) == 0 {
		panic(ErrLoadTemplateFailed)
	}
	for _, template := range templates {
		LoadedTemplates[template.Name] = template
	}
}
Exemple #2
0
func loadCategory() {
	var categories []t.SMSCategory
	existed := mongodb.Exec(CollSMSCategory, func(c *mgo.Collection) error {
		return c.Find(nil).Sort("-timestamp").All(&categories)
	})
	if !existed || len(categories) == 0 {
		panic(ErrLoadCategoryFailed)
	}
	for _, category := range categories {
		LoadedChannels[category.Name] = category.Channel
		LoadedCategories[category.Name] = category
	}
}
Exemple #3
0
func loadStrategy() {
	var strategies []f.Strategy
	existed := mongodb.Exec(CollSMSStrategy, func(c *mgo.Collection) error {
		return c.Find(nil).All(&strategies)
	})
	if !existed || len(strategies) == 0 {
		panic(ErrLoadStrategyFailed)
	}
	for _, strategy := range strategies {
		//FIXME only return enabled strategy?
		if !strategy.Enabled {
			continue
		}
		existing, ok := LoadedStrategies[strategy.Type]
		if !ok {
			LoadedStrategies[strategy.Type] = []f.Strategy{strategy}
		} else {
			LoadedStrategies[strategy.Type] = append(existing, strategy)
		}
	}
	f.Apply(LoadedStrategies)
}