Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config code refactor #388

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions modules/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@ import (
"gopkg.in/yaml.v2"
)

type Env string

func (env Env) Valid() bool {
return env == EnvLocal || env == EnvTest || env == EnvProd
}

const (
// EnvTest is a const value of test environment.
EnvTest Env = "test"
EnvTest = "test"
// EnvLocal is a const value of local environment.
EnvLocal Env = "local"
EnvLocal = "local"
// EnvProd is a const value of production environment.
EnvProd Env = "prod"
EnvProd = "prod"
)

// Config type is the global config of goAdmin. It will be
Expand Down Expand Up @@ -84,7 +78,7 @@ type Config struct {
Debug bool `json:"debug,omitempty" yaml:"debug,omitempty" ini:"debug,omitempty"`

// Env is the environment,which maybe local,test,prod.
Env Env `json:"env,omitempty" yaml:"env,omitempty" ini:"env,omitempty"`
Env string `json:"env,omitempty" yaml:"env,omitempty" ini:"env,omitempty"`

// Info log path.
InfoLogPath string `json:"info_log,omitempty" yaml:"info_log,omitempty" ini:"info_log,omitempty"`
Expand Down Expand Up @@ -641,9 +635,7 @@ func SetDefault(cfg *Config) *Config {
cfg.AssetRootPath = utils.SetDefault(cfg.AssetRootPath, "", "./public/")
cfg.AssetRootPath = filepath.ToSlash(cfg.AssetRootPath)
cfg.FileUploadEngine.Name = utils.SetDefault(cfg.FileUploadEngine.Name, "", "local")
if !cfg.Env.Valid() {
Copy link
Collaborator

@chenhg5 chenhg5 Jan 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lyouthzzz 可以加个 InValid() 的api。更易读一些。

cfg.Env = EnvProd
}
cfg.Env = utils.SetDefault(cfg.Env, "", EnvProd)
if cfg.SessionLifeTime == 0 {
// default two hours
cfg.SessionLifeTime = 7200
Expand Down