qoder生成项目
This commit is contained in:
57
config/config.go
Normal file
57
config/config.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Database DatabaseConfig
|
||||
Server ServerConfig
|
||||
App AppConfig
|
||||
}
|
||||
|
||||
type DatabaseConfig struct {
|
||||
Driver string
|
||||
DSN string
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
Port int
|
||||
Mode string
|
||||
}
|
||||
|
||||
type AppConfig struct {
|
||||
Name string
|
||||
Description string
|
||||
Author string
|
||||
Theme string
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
port, _ := strconv.Atoi(getEnv("SERVER_PORT", "8080"))
|
||||
|
||||
return &Config{
|
||||
Database: DatabaseConfig{
|
||||
Driver: getEnv("DB_DRIVER", "sqlite"),
|
||||
DSN: getEnv("DB_DSN", "goblog.db"),
|
||||
},
|
||||
Server: ServerConfig{
|
||||
Port: port,
|
||||
Mode: getEnv("GIN_MODE", "debug"),
|
||||
},
|
||||
App: AppConfig{
|
||||
Name: getEnv("APP_NAME", "GoBlog"),
|
||||
Description: getEnv("APP_DESC", "一个简洁的个人博客"),
|
||||
Author: getEnv("APP_AUTHOR", "Admin"),
|
||||
Theme: getEnv("APP_THEME", "default"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func getEnv(key, defaultValue string) string {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
return value
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
Reference in New Issue
Block a user