暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mcp_config.go 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // subconfigs/service_config.go
  2. package subconfigs
  3. import (
  4. "fmt"
  5. "log"
  6. )
  7. // ServiceConfig 数据库配置
  8. type McpServiceConfig struct {
  9. BaseConfig
  10. Port int `yaml:"port"`
  11. ServiceName string `yaml:"service_name"`
  12. InstanceName string `yaml:"instance_name"`
  13. ReadTimeout int `yaml:"read_timeout"`
  14. WriteTimeout int `yaml:"write_timeout"`
  15. IdleTimeout int `yaml:"idle_timeout"`
  16. }
  17. // SetDefaults 设置默认值 - 实现 ConfigLoader 接口
  18. func (c *McpServiceConfig) SetDefaults() {
  19. if c.Port == 0 {
  20. c.Port = 8080
  21. }
  22. if c.IdleTimeout == 0 {
  23. c.IdleTimeout = 60
  24. }
  25. if c.ReadTimeout == 0 {
  26. c.ReadTimeout = 30
  27. }
  28. if c.WriteTimeout == 0 {
  29. c.WriteTimeout = 30
  30. }
  31. }
  32. // Load 从yaml数据加载 - 实现 ConfigLoader 接口
  33. func (c *McpServiceConfig) Load(data map[string]interface{}) error {
  34. // 虽然可能不会被直接调用,但为了接口完整性还是要实现
  35. return c.LoadFromYAML(data, c)
  36. }
  37. // ========== 业务方法 ==========
  38. // Validate 验证配置(数据库配置)
  39. func (c *McpServiceConfig) Validate() error {
  40. if c.Port <= 0 || c.Port > 65535 {
  41. return fmt.Errorf("invalid service port: %d", c.Port)
  42. }
  43. return nil
  44. }
  45. // IsConfigured 判断是否已配置(数据库配置)
  46. func (c *McpServiceConfig) IsConfigured() bool {
  47. if c.Port <= 0 {
  48. log.Println("⚠️ 警告: 微服务 Port 未配置或无效")
  49. return false
  50. }
  51. return true
  52. }
  53. // 自动注册
  54. func init() {
  55. Register("mcpservice", &McpServiceConfig{})
  56. }