843024d7da
- Dockerfile 设置 GOPROXY=https://goproxy.cn,direct 解决国内网络问题 - 新增 addr 配置项,支持自定义端口,默认 :8080 - docker-compose 端口改为 ${OPS_MCP_PORT:-9090} - 移除 EXPOSE 指令(端口通过 compose 管理) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
36 lines
744 B
Go
36 lines
744 B
Go
package config
|
|
|
|
import (
|
|
"log/slog"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type Config struct {
|
|
Transport string `mapstructure:"transport"` // stdio | sse
|
|
Addr string `mapstructure:"addr"` // 监听地址,默认 :8080
|
|
}
|
|
|
|
func Load() (*Config, error) {
|
|
v := viper.New()
|
|
v.SetConfigName("config")
|
|
v.SetConfigType("yaml")
|
|
v.AddConfigPath("./config")
|
|
v.AddConfigPath(".")
|
|
v.AddConfigPath("/config")
|
|
v.SetEnvPrefix("OPS_MCP")
|
|
v.AutomaticEnv()
|
|
v.SetDefault("transport", "stdio")
|
|
v.SetDefault("addr", ":8080")
|
|
|
|
if err := v.ReadInConfig(); err != nil {
|
|
slog.Warn("no config file found, using defaults and env vars", "err", err)
|
|
}
|
|
|
|
cfg := &Config{}
|
|
if err := v.Unmarshal(cfg); err != nil {
|
|
return nil, err
|
|
}
|
|
return cfg, nil
|
|
}
|