MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / main

Function main

main.go:34–160  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32var indexPage []byte
33
34func main() {
35
36 err := InitResources()
37 if err != nil {
38 common.FatalLog("failed to initialize resources: " + err.Error())
39 return
40 }
41
42 common.SysLog("MIX API " + common.Version + " started")
43 if os.Getenv("GIN_MODE") != "debug" {
44 gin.SetMode(gin.ReleaseMode)
45 }
46 if common.DebugEnabled {
47 common.SysLog("running in debug mode")
48 }
49
50 defer func() {
51 err := model.CloseDB()
52 if err != nil {
53 common.FatalLog("failed to close database: " + err.Error())
54 }
55 }()
56
57 if common.RedisEnabled {
58 // for compatibility with old versions
59 common.MemoryCacheEnabled = true
60 }
61 if common.MemoryCacheEnabled {
62 common.SysLog("memory cache enabled")
63 common.SysError(fmt.Sprintf("sync frequency: %d seconds", common.SyncFrequency))
64
65 // Add panic recovery and retry for InitChannelCache
66 func() {
67 defer func() {
68 if r := recover(); r != nil {
69 common.SysError(fmt.Sprintf("InitChannelCache panic: %v, retrying once", r))
70 // Retry once
71 _, _, fixErr := model.FixAbility()
72 if fixErr != nil {
73 common.FatalLog(fmt.Sprintf("InitChannelCache failed: %s", fixErr.Error()))
74 }
75 }
76 }()
77 model.InitChannelCache()
78 }()
79
80 go model.SyncChannelCache(common.SyncFrequency)
81 }
82
83 // 热更新配置
84 go model.SyncOptions(common.SyncFrequency)
85
86 // 数据看板
87 go model.UpdateQuotaData()
88
89 if os.Getenv("CHANNEL_UPDATE_FREQUENCY") != "" {
90 frequency, err := strconv.Atoi(os.Getenv("CHANNEL_UPDATE_FREQUENCY"))
91 if err != nil {

Callers

nothing calls this directly

Calls 15

FatalLogFunction · 0.92
SysLogFunction · 0.92
CloseDBFunction · 0.92
SysErrorFunction · 0.92
FixAbilityFunction · 0.92
InitChannelCacheFunction · 0.92
SyncChannelCacheFunction · 0.92
SyncOptionsFunction · 0.92
UpdateQuotaDataFunction · 0.92
UpdateMidjourneyTaskBulkFunction · 0.92

Tested by

no test coverage detected