Files
bj_power/bj_power_wms/internal/config/config.go
T

59 lines
1.5 KiB
Go
Raw Normal View History

2026-08-28 15:06:01 +08:00
package config
import (
"strconv"
"github.com/zeromicro/go-zero/rest"
)
2026-08-29 15:30:25 +08:00
// PostgresConfig PostgreSQL 连接配置(go-zero 按 json tag + 字段名小写匹配 yaml
2026-08-28 15:06:01 +08:00
type PostgresConfig struct {
2026-08-29 15:30:25 +08:00
Host string `json:",default=127.0.0.1"`
Port int `json:",default=5432"`
User string `json:",default=postgres"`
Password string `json:",default=postgres"`
DBName string `json:",default=bj_power_wms"`
SSLMode string `json:",default=disable"`
2026-08-28 15:06:01 +08:00
}
type AuthConfig struct {
2026-08-29 15:30:25 +08:00
AccessSecret string `json:",default=Hardman_2026"`
AccessExpire int64 `json:",default=1800"`
2026-08-28 15:06:01 +08:00
}
// InternalConfig 项目间内部 API 配置
type InternalConfig struct {
2026-08-29 15:30:25 +08:00
Token string `json:",default=Hardman_2026"` // 写死的项目间 API tokenX-API-TOKEN
}
// MesConfig 下游 MES 服务对接(备料/台账需取工单与 BOM)
type MesConfig struct {
BaseURL string `json:",default=http://127.0.0.1:8888"` // MES 服务地址
Token string `json:",default=Hardman_2026"` // 调 MES 内部接口的 X-API-TOKEN
2026-08-28 15:06:01 +08:00
}
type Config struct {
rest.RestConf
2026-08-29 15:30:25 +08:00
Postgres PostgresConfig
Auth AuthConfig
Internal InternalConfig
Redis RedisConf
Mes MesConfig
}
// RedisConf Redis 连接配置
type RedisConf struct {
Host string `json:",default=127.0.0.1:6379"`
Type string `json:",default=node"`
2026-08-28 15:06:01 +08:00
}
// DSN 返回 PostgreSQL 连接串
func (p PostgresConfig) DSN() string {
return "host=" + p.Host +
" port=" + strconv.Itoa(p.Port) +
" user=" + p.User +
" password=" + p.Password +
" dbname=" + p.DBName +
" sslmode=" + p.SSLMode
}