github.com/cloudreve/Cloudreve/v3@v3.0.0-20240224133659-3edb00a6484c/bootstrap/init.go (about) 1 package bootstrap 2 3 import ( 4 model "github.com/cloudreve/Cloudreve/v3/models" 5 "github.com/cloudreve/Cloudreve/v3/models/scripts" 6 "github.com/cloudreve/Cloudreve/v3/pkg/aria2" 7 "github.com/cloudreve/Cloudreve/v3/pkg/auth" 8 "github.com/cloudreve/Cloudreve/v3/pkg/cache" 9 "github.com/cloudreve/Cloudreve/v3/pkg/cluster" 10 "github.com/cloudreve/Cloudreve/v3/pkg/conf" 11 "github.com/cloudreve/Cloudreve/v3/pkg/crontab" 12 "github.com/cloudreve/Cloudreve/v3/pkg/email" 13 "github.com/cloudreve/Cloudreve/v3/pkg/mq" 14 "github.com/cloudreve/Cloudreve/v3/pkg/task" 15 "github.com/cloudreve/Cloudreve/v3/pkg/wopi" 16 "github.com/gin-gonic/gin" 17 "io/fs" 18 "path/filepath" 19 ) 20 21 // Init 初始化启动 22 func Init(path string, statics fs.FS) { 23 InitApplication() 24 conf.Init(path) 25 // Debug 关闭时,切换为生产模式 26 if !conf.SystemConfig.Debug { 27 gin.SetMode(gin.ReleaseMode) 28 } 29 30 dependencies := []struct { 31 mode string 32 factory func() 33 }{ 34 { 35 "both", 36 func() { 37 scripts.Init() 38 }, 39 }, 40 { 41 "both", 42 func() { 43 cache.Init() 44 }, 45 }, 46 { 47 "slave", 48 func() { 49 model.InitSlaveDefaults() 50 }, 51 }, 52 { 53 "slave", 54 func() { 55 cache.InitSlaveOverwrites() 56 }, 57 }, 58 { 59 "master", 60 func() { 61 model.Init() 62 }, 63 }, 64 { 65 "both", 66 func() { 67 cache.Restore(filepath.Join(model.GetSettingByName("temp_path"), cache.DefaultCacheFile)) 68 }, 69 }, 70 { 71 "both", 72 func() { 73 task.Init() 74 }, 75 }, 76 { 77 "master", 78 func() { 79 cluster.Init() 80 }, 81 }, 82 { 83 "master", 84 func() { 85 aria2.Init(false, cluster.Default, mq.GlobalMQ) 86 }, 87 }, 88 { 89 "master", 90 func() { 91 email.Init() 92 }, 93 }, 94 { 95 "master", 96 func() { 97 crontab.Init() 98 }, 99 }, 100 { 101 "master", 102 func() { 103 InitStatic(statics) 104 }, 105 }, 106 { 107 "slave", 108 func() { 109 cluster.InitController() 110 }, 111 }, 112 { 113 "both", 114 func() { 115 auth.Init() 116 }, 117 }, 118 { 119 "master", 120 func() { 121 wopi.Init() 122 }, 123 }, 124 } 125 126 for _, dependency := range dependencies { 127 if dependency.mode == conf.SystemConfig.Mode || dependency.mode == "both" { 128 dependency.factory() 129 } 130 } 131 132 }