Skip to content

Commit

Permalink
fix: Improve configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
LyricTian committed Dec 18, 2023
1 parent 2fcee95 commit 3b9b1b4
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 34 deletions.
4 changes: 2 additions & 2 deletions configs/dev/logging.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Logger]
Debug = true
Level = "debug"
Level = "debug" # debug/info/warn/error/dpanic/panic/fatal
CallerSkip = 1

[Logger.File]
Expand All @@ -23,4 +23,4 @@ DSN = "data/ginadmin.db"
MaxOpenConns = "16"
MaxIdleConns = "4"
MaxLifetime = "86400"
MaxIdleTime = "7200"
MaxIdleTime = "7200"
54 changes: 32 additions & 22 deletions configs/dev/middleware.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@
[Middleware.Recovery]
Skip = 3

[Middleware.Trace]
RequestHeaderKey = "X-Request-Id"
ResponseTraceKey = "X-Trace-Id"

[Middleware.Logger]
MaxOutputRequestBodyLen = 4096 # bytes
MaxOutputResponseBodyLen = 1024 # bytes

[Middleware.TokenAuth]
Enable = true

[Middleware.CopyBody]
MaxContentLen = 134217728 # 128MB

[Middleware.CORS]
Enable = false
AllowOrigins = ["*"]
Expand All @@ -27,23 +13,46 @@ AllowWildcard = true
AllowWebSockets = true
AllowFiles = true

[Middleware.Trace]
RequestHeaderKey = "X-Request-Id"
ResponseTraceKey = "X-Trace-Id"

[Middleware.Logger]
MaxOutputRequestBodyLen = 4096 # bytes
MaxOutputResponseBodyLen = 4096 # bytes

[Middleware.CopyBody]
MaxContentLen = 134217728 # 128MB

[Middleware.Auth]
Disable = false
SkippedPathPrefixes = ["/api/v1/captcha/", "/api/v1/login"]
SigningMethod = "HS512" # HS256/HS384/HS512
SigningKey = "XnEsT0S@" # Secret key
OldSigningKey = "" # Old secret key (For change secret key)
Expired = 86400 # seconds

[Middleware.Auth.Store]
Type = "badger" # badger/redis
Type = "badger" # memory/badger/redis
Delimiter = ":"

[Middleware.Auth.Store.Memory]
CleanupInterval = 60 # seconds

[Middleware.Auth.Store.Badger]
Path = "data/auth"

[Middleware.Auth.Store.Redis]
Addr = ""
Addr = "" # If empty, then use the same configuration as Storage.Cache.Redis
Username = ""
Password = ""
DB = 2

[Middleware.RateLimiter]
Enable = false
MaxRequestsPerIP = 30
MaxRequestsPerUser = 30
Period = 10 # seconds
MaxRequestsPerIP = 1000
MaxRequestsPerUser = 500

[Middleware.RateLimiter.Store]
Type = "memory" # memory/redis
Expand All @@ -53,14 +62,15 @@ Expiration = 3600
CleanupInterval = 60

[Middleware.RateLimiter.Store.Redis]
Addr = ""
Addr = "" # If empty, then use the same configuration as Storage.Cache.Redis
Username = ""
Password = ""
DB = 10

[Middleware.Casbin]
Disable = false
SkippedPathPrefixes = ["/api/v1/captcha/", "/api/v1/login", "/api/v1/current/"]

[Middleware.Static]
SkippedPathPrefixes = ["/api"]
LoadThread = 2
AutoLoadInterval = 3 # seconds
ModelFile = "rbac_model.conf"
GenPolicyFile = "gen_rbac_policy.csv"
44 changes: 37 additions & 7 deletions configs/dev/server.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
[General]
AppName = "ginadmin"
DebugMode = true
PprofAddr = "localhost:6060"
Version = "v10.0.2"
Debug = true
PprofAddr = "" # Pprof monitor address, "localhost:6060"
DisableSwagger = false
DisablePrintConfig = false
MenuFile = "menu.json"
DefaultLoginPwd = "6351623c8cef86fefabfa7da046fc619" # MD5("abc-123")
MenuFile = "menu.json" # Or use "menu_cn.json"
DenyDeleteMenu = false

[General.HTTP]
Addr = ":8040"
ShutdownTimeout = 10
ReadTimeout = 60
WriteTimeout = 60
IdleTimeout = 10
ShutdownTimeout = 10
CertFile = ""
KeyFile = ""

[General.Root]
[General.Root] # Super Administrator Account
ID = "root"
Username = "admin"
Password = "6351623c8cef86fefabfa7da046fc619" # abc-123
Password = "6351623c8cef86fefabfa7da046fc619" # MD5("abc-123")
Name = "Admin"

[Storage]

[Storage.Cache]
Type = "badger" # badger/redis
Type = "badger" # memory/badger/redis
Delimiter = ":"

[Storage.Cache.Memory]
Expand Down Expand Up @@ -54,3 +57,30 @@ MaxOpenConns = 100
MaxIdleConns = 50
TablePrefix = ""
AutoMigrate = true

[Util]

[Util.Captcha]
Length = 4
Width = 400
Height = 160
CacheType = "memory" # memory/redis

[Util.Captcha.Redis]
Addr = "" # If empty, then use the same configuration as Storage.Cache.Redis
Username = ""
Password = ""
DB = 1
KeyPrefix = "captcha:"

[Util.Prometheus]
Enable = false
Port = 9100
BasicUsername = "admin"
BasicPassword = "admin"
LogApis = [] # Log APIs, e.g. ["/api/v1/users"]
LogMethods = [] # Log HTTP methods, e.g. ["GET"]
DefaultCollect = true

[Dictionary]
UserCacheExp = 4 # hours
12 changes: 9 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ type Config struct {

type General struct {
AppName string `default:"ginadmin"`
Version string `default:"v1.0.0"`
Version string `default:"v10.0.2"`
Debug bool
PprofAddr string
DisableSwagger bool
DisablePrintConfig bool
DefaultLoginPwd string `default:"6351623c8cef86fefabfa7da046fc619"` // abc-123
DefaultLoginPwd string `default:"6351623c8cef86fefabfa7da046fc619"` // MD5(abc-123)
WorkDir string // From command arguments
MenuFile string // From schema.Menus (JSON/YAML)
DenyDeleteMenu bool
HTTP struct {
Addr string `default:":8080"`
Addr string `default:":8040"`
ShutdownTimeout int `default:"10"` // seconds
ReadTimeout int `default:"60"` // seconds
WriteTimeout int `default:"60"` // seconds
Expand Down Expand Up @@ -125,6 +125,12 @@ func (c *Config) PreLoad() {
if addr := c.Storage.Cache.Redis.Addr; addr != "" {
username := c.Storage.Cache.Redis.Username
password := c.Storage.Cache.Redis.Password
if c.Util.Captcha.CacheType == "redis" &&
c.Util.Captcha.Redis.Addr == "" {
c.Util.Captcha.Redis.Addr = addr
c.Util.Captcha.Redis.Username = username
c.Util.Captcha.Redis.Password = password
}
if c.Middleware.RateLimiter.Store.Type == "redis" &&
c.Middleware.RateLimiter.Store.Redis.Addr == "" {
c.Middleware.RateLimiter.Store.Redis.Addr = addr
Expand Down

0 comments on commit 3b9b1b4

Please sign in to comment.