50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
|
|
sdkconfig "github.com/go-admin-team/go-admin-core/sdk/config"
|
|
)
|
|
|
|
var ExtConfig Extend
|
|
|
|
// Extend 扩展配置
|
|
//
|
|
// extend:
|
|
// demo:
|
|
// name: demo-name
|
|
//
|
|
// 使用方法: config.ExtConfig......即可!!
|
|
type Extend struct {
|
|
AMap AMap // 这里配置对应配置文件的结构即可
|
|
}
|
|
|
|
type AMap struct {
|
|
Key string
|
|
}
|
|
|
|
// ApplyEnvironment replaces tracked defaults with process-local runtime values.
|
|
// Credentials stay outside tracked configuration files. GOAUTO_DB_DRIVER
|
|
// defaults to mysql when GOAUTO_DB_DSN is present.
|
|
func ApplyEnvironment() {
|
|
if port, err := strconv.Atoi(strings.TrimSpace(os.Getenv("GOAUTO_SERVER_PORT"))); err == nil && port >= 1 && port <= 65535 {
|
|
sdkconfig.ApplicationConfig.Port = int64(port)
|
|
}
|
|
dsn := strings.TrimSpace(os.Getenv("GOAUTO_DB_DSN"))
|
|
if dsn == "" {
|
|
return
|
|
}
|
|
driver := strings.TrimSpace(os.Getenv("GOAUTO_DB_DRIVER"))
|
|
if driver == "" {
|
|
driver = "mysql"
|
|
}
|
|
sdkconfig.DatabaseConfig.Driver = driver
|
|
sdkconfig.DatabaseConfig.Source = dsn
|
|
for _, database := range sdkconfig.DatabasesConfig {
|
|
database.Driver = driver
|
|
database.Source = dsn
|
|
}
|
|
}
|