feat(*): go 后端项目脚手架
This commit is contained in:
76
pkg/config/types.go
Normal file
76
pkg/config/types.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/zhilv666/navsite/pkg/common"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Debug bool `mapstructure:"debug"`
|
||||
Port int `mapstructure:"port"`
|
||||
}
|
||||
|
||||
type Log struct {
|
||||
Level string `mapstructure:"level"`
|
||||
Filepath string `mapstructure:"filepath"`
|
||||
MaxSizeMB int `mapstructure:"max_size_mb"` // 单个日志文件最大(MB)
|
||||
MaxAgeDay int `mapstructure:"max_age_day"` // 日志文件最大保存天数
|
||||
Backups int `mapstructure:"backups"` // 保留的旧文件个数
|
||||
Compress bool `mapstructure:"compress"` // 是否压缩
|
||||
}
|
||||
|
||||
type Database struct {
|
||||
Driver string `mapstructure:"driver"`
|
||||
User string `mapstructure:"user"`
|
||||
Password string `mapstructure:"password"`
|
||||
Host string `mapstructure:"host"`
|
||||
Port int `mapstructure:"port"`
|
||||
DbName string `mapstructure:"db_name"`
|
||||
SqliteDbPath string `mapstructure:"sqlite_db_path"`
|
||||
}
|
||||
|
||||
type JWT struct {
|
||||
SecretKey string `mapstructure:"secret_key"`
|
||||
ExpireDurationHour time.Duration `mapstructure:"expire_duration_hour"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Server Server `mapstructure:"server"`
|
||||
Log Log `mapstructure:"log"`
|
||||
Database Database `mapstructure:"database"`
|
||||
JWT JWT `mapstructure:"jwt"`
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
logPath := filepath.Join("data", "log.log")
|
||||
dbPath := filepath.Join("data", "sqlite.db")
|
||||
return &Config{
|
||||
Server: Server{
|
||||
Debug: true,
|
||||
Port: 8080,
|
||||
},
|
||||
Log: Log{
|
||||
Level: "debug",
|
||||
Filepath: logPath,
|
||||
MaxSizeMB: 10,
|
||||
MaxAgeDay: 7,
|
||||
Backups: 3,
|
||||
Compress: true,
|
||||
},
|
||||
Database: Database{
|
||||
Driver: "sqlite",
|
||||
User: "",
|
||||
Password: "",
|
||||
Host: "",
|
||||
Port: 0,
|
||||
DbName: "",
|
||||
SqliteDbPath: dbPath,
|
||||
},
|
||||
JWT: JWT{
|
||||
SecretKey: common.Rand(16),
|
||||
ExpireDurationHour: 24,
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user