093511bbdd
- 移除 database/middleware 等复杂模块,先聚焦核心功能 - docker_logs:封装 docker logs --tail N <container> - 修复 go.mod 版本为 1.24 匹配 Docker 构建镜像 - Dockerfile 改用 alpine + docker-cli,避免 scratch 无 shell 问题 - docker-compose.yml 简化为单服务定义 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
35 lines
710 B
Go
35 lines
710 B
Go
package config
|
|
|
|
import (
|
|
"log/slog"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type Config struct {
|
|
Transport string `mapstructure:"transport"` // stdio | sse
|
|
}
|
|
|
|
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")
|
|
|
|
// 配置文件不存在不算错误,直接用默认值 + 环境变量
|
|
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
|
|
}
|