Func: use `--skip-conf` arg to skip conf init part

Applicable to the use of environment variables completely, no need to configure through `conf.ini` in the container.
pull/1475/head
AH-dark 3 years ago
parent 50c3100afb
commit bb8e5ca487
No known key found for this signature in database
GPG Key ID: 73D3D212EB75AB80

@ -12,17 +12,30 @@ import (
"github.com/cloudreve/Cloudreve/v3/pkg/email"
"github.com/cloudreve/Cloudreve/v3/pkg/mq"
"github.com/cloudreve/Cloudreve/v3/pkg/task"
"github.com/cloudreve/Cloudreve/v3/pkg/util"
"github.com/gin-gonic/gin"
"io/fs"
)
// Init 初始化启动
func Init(path string, statics fs.FS) {
func Init(path string, skipConfig bool, statics fs.FS) {
InitApplication()
conf.Init(path)
// 加载配置文件
if !skipConfig {
conf.Init(path)
}
// Debug 关闭时,切换为生产模式
if !conf.SystemConfig.Debug {
util.Level = util.LevelInformational
util.GloablLogger = nil
util.Log()
gin.SetMode(gin.ReleaseMode)
if skipConfig {
util.Log().Warning("配置文件加载已取消,将使用环境变量或默认配置")
}
}
dependencies := []struct {

@ -24,9 +24,10 @@ import (
)
var (
isEject bool
confPath string
scriptName string
isEject bool
skipConfGenerate bool
confPath string
scriptName string
)
//go:embed assets.zip
@ -38,13 +39,14 @@ func init() {
flag.StringVar(&confPath, "c", util.RelativePath("conf.ini"), "配置文件路径")
flag.BoolVar(&isEject, "eject", false, "导出内置静态资源")
flag.StringVar(&scriptName, "database-script", "", "运行内置数据库助手脚本")
flag.BoolVar(&skipConfGenerate, "skip-conf", false, "跳过配置文件生成")
flag.Parse()
staticFS = archiver.ArchiveFS{
Stream: io.NewSectionReader(strings.NewReader(staticZip), 0, int64(len(staticZip))),
Format: archiver.Zip{},
}
bootstrap.Init(confPath, staticFS)
bootstrap.Init(confPath, skipConfGenerate, staticFS)
}
func main() {

@ -1,6 +1,8 @@
package middleware
import (
"strconv"
"github.com/cloudreve/Cloudreve/v3/pkg/conf"
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
"github.com/cloudreve/Cloudreve/v3/pkg/util"
@ -8,7 +10,6 @@ import (
"github.com/gin-contrib/sessions/memstore"
"github.com/gin-contrib/sessions/redis"
"github.com/gin-gonic/gin"
"strconv"
)
// Store session存储

@ -123,14 +123,6 @@ func Init(path string) {
for _, key := range cfg.Section("OptionOverwrite").Keys() {
OptionOverwrite[key.Name()] = key.Value()
}
// 重设log等级
if !SystemConfig.Debug {
util.Level = util.LevelInformational
util.GloablLogger = nil
util.Log()
}
}
// mapSection 将配置文件的 Section 映射到结构体上

Loading…
Cancel
Save