示例#1
0
文件: loader.go 项目: yilee/mane
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
	}
}
示例#2
0
文件: loader.go 项目: yilee/mane
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
	}
}
示例#3
0
文件: loader.go 项目: yilee/mane
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)
}