| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- // subconfigs/service_config.go
- package subconfigs
-
- import (
- "fmt"
- "log"
- )
-
- // ServiceConfig 数据库配置
- type McpServiceConfig struct {
- BaseConfig
- Port int `yaml:"port"`
- ServiceName string `yaml:"service_name"`
- InstanceName string `yaml:"instance_name"`
- ReadTimeout int `yaml:"read_timeout"`
- WriteTimeout int `yaml:"write_timeout"`
- IdleTimeout int `yaml:"idle_timeout"`
- }
-
- // SetDefaults 设置默认值 - 实现 ConfigLoader 接口
- func (c *McpServiceConfig) SetDefaults() {
-
- if c.Port == 0 {
- c.Port = 8080
- }
- if c.IdleTimeout == 0 {
- c.IdleTimeout = 60
- }
- if c.ReadTimeout == 0 {
- c.ReadTimeout = 30
- }
- if c.WriteTimeout == 0 {
- c.WriteTimeout = 30
- }
- }
-
- // Load 从yaml数据加载 - 实现 ConfigLoader 接口
- func (c *McpServiceConfig) Load(data map[string]interface{}) error {
- // 虽然可能不会被直接调用,但为了接口完整性还是要实现
- return c.LoadFromYAML(data, c)
- }
-
- // ========== 业务方法 ==========
-
- // Validate 验证配置(数据库配置)
- func (c *McpServiceConfig) Validate() error {
-
- if c.Port <= 0 || c.Port > 65535 {
- return fmt.Errorf("invalid service port: %d", c.Port)
- }
-
- return nil
- }
-
- // IsConfigured 判断是否已配置(数据库配置)
- func (c *McpServiceConfig) IsConfigured() bool {
-
- if c.Port <= 0 {
- log.Println("⚠️ 警告: 微服务 Port 未配置或无效")
- return false
- }
-
- return true
- }
-
- // 自动注册
- func init() {
- Register("mcpservice", &McpServiceConfig{})
- }
|