package service import ( "fmt" "gitlab.alibaba-inc.com/pai_biz_arch/pairec/recconf" ) var scenes = make(map[string]*Scene) func GetSence(sceneId string) (*Scene, error) { scene, ok := scenes[sceneId] if !ok { return nil, fmt.Errorf("Scene:not found, SenceId:%s", sceneId) } return scene, nil } func Load(conf *recconf.RecommendConfig) { for sceneId, categoryConfs := range conf.SceneConfs { scene := NewScene(sceneId) // scene.Init(sceneConf) for categoryName, categoryConf := range categoryConfs { // if _, ok := conf.CategoryConfs[categoryName]; !ok { // panic(fmt.Sprintf("category name not found, name:%s", categoryName)) // } category := NewCategory(categoryName) category.Init(categoryConf) scene.AddCategory(categoryName, category) } scenes[sceneId] = scene } } type Scene struct { SceneId string Categories map[string]*Category } func NewScene(senceId string) *Scene { scene := Scene{SceneId: senceId} scene.Categories = make(map[string]*Category) return &scene } func (s *Scene) Init(config recconf.SceneConfig) { } func (s *Scene) AddCategory(name string, category *Category) { s.Categories[name] = category } func (s *Scene) GetCategory(name string) (*Category, error) { category, ok := s.Categories[name] if !ok { return s.Categories["default_category"], nil } return category, nil }