zhangzengfei
2025-02-11 c7ec5e7a2762eb9cd2c9d2a23fc1de4677161a30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package models
 
import (
    "fmt"
 
    "model-engine/db"
)
 
type Model interface {
    Init(task *db.ModelTask) error
    Run() error
    KeepAlive() error
    Shutdown() error
}
 
var modelRegistry = map[string]func() Model{
    "gather":           func() Model { return &GatherModel{} },
    "disappear":        func() Model { return &DisappearModel{} },
    "location":         func() Model { return &LocationModel{} },
    "night":            func() Model { return &nightModel{} },
    "accessRegularity": func() Model { return &RegularityModel{} },
    // 添加其他模型
}
 
func GetModel(modelID string) (Model, error) {
    if factory, exists := modelRegistry[modelID]; exists {
        return factory(), nil
    }
    return nil, fmt.Errorf("model %s not found", modelID)
}