di

package
v0.0.0-...-5901162 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 61 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalConfig = &Config{}

GlobalConfig 全局配置实例

View Source
var GlobalExternalConfig = &ExternalConfig{}
View Source
var ServiceSet = wire.NewSet(service4.NewClusterService, service4.NewDeploymentService, service4.NewNamespaceService, service4.NewSvcService, service4.NewNodeService, service4.NewTaintService, service4.NewYamlTaskService, service4.NewYamlTemplateService, service4.NewDaemonSetService, service4.NewEventService, service4.NewStatefulSetService, service4.NewServiceAccountService, service4.NewRoleService, service4.NewClusterRoleService, service4.NewRoleBindingService, service4.NewClusterRoleBindingService, service4.NewIngressService, service4.NewPodService, service4.NewConfigMapService, service4.NewSecretService, service4.NewPVService, service4.NewPVCService, service2.NewUserService, service.NewApiService, service.NewRoleService, service.NewAuditService, service.NewSystemService, alert2.NewAlertManagerEventService, alert2.NewAlertManagerOnDutyService, alert2.NewAlertManagerPoolService, alert2.NewAlertManagerRecordService, alert2.NewAlertManagerRuleService, alert2.NewAlertManagerSendService, scrape2.NewPrometheusScrapeService, scrape2.NewPrometheusPoolService, config2.NewMonitorConfigService, service3.NewNotAuthService, service5.NewFormDesignService, service5.NewInstanceService, service5.NewInstanceFlowService, service5.NewInstanceCommentService, service5.NewWorkorderInstanceTimeLineService, service5.NewWorkorderTemplateService, service5.NewWorkorderProcessService, service5.NewCategoryGroupService, service5.NewWorkorderNotificationService, service6.NewTreeNodeService, service6.NewTreeLocalService)

Functions

func CheckDBHealth

func CheckDBHealth(db *gorm.DB) error

func InitAsynqClient

func InitAsynqClient() *asynq.Client

func InitAsynqServer

func InitAsynqServer() *asynq.Server

func InitDB

func InitDB() *gorm.DB

func InitGinServer

func InitGinServer(
	m []gin.HandlerFunc,
	userHdl *userApi.UserHandler,
	authApiHdl *systemApi.ApiHandler,
	authRoleHdl *systemApi.RoleHandler,
	systemHdl *systemApi.SystemHandler,
	notAuthHdl *notAuthHandler.NotAuthHandler,
	k8sClusterHdl *k8sApi.K8sClusterHandler,
	k8sDeploymentHdl *k8sApi.K8sDeploymentHandler,
	k8sNamespaceHdl *k8sApi.K8sNamespaceHandler,
	k8sNodeHdl *k8sApi.K8sNodeHandler,
	k8sSvcHdl *k8sApi.K8sSvcHandler,
	k8sYamlTaskHdl *k8sApi.K8sYamlTaskHandler,
	k8sYamlTemplateHdl *k8sApi.K8sYamlTemplateHandler,
	k8sDaemonSetHdl *k8sApi.K8sDaemonSetHandler,
	k8sEventHdl *k8sApi.K8sEventHandler,
	k8sStatefulSetHdl *k8sApi.K8sStatefulSetHandler,
	k8sServiceAccountHdl *k8sApi.K8sServiceAccountHandler,
	roleHdl *k8sApi.K8sRoleHandler,
	clusterRoleHdl *k8sApi.K8sClusterRoleHandler,
	roleBindingHdl *k8sApi.K8sRoleBindingHandler,
	clusterRoleBindingHdl *k8sApi.K8sClusterRoleBindingHandler,

	alertEventHdl *prometheusApi.AlertEventHandler,
	alertPoolHdl *prometheusApi.AlertPoolHandler,
	alertRuleHdl *prometheusApi.AlertRuleHandler,
	monitorConfigHdl *prometheusApi.MonitorConfigHandler,
	onDutyGroupHdl *prometheusApi.OnDutyGroupHandler,
	recordRuleHdl *prometheusApi.RecordRuleHandler,
	scrapePoolHdl *prometheusApi.ScrapePoolHandler,
	scrapeJobHdl *prometheusApi.ScrapeJobHandler,
	sendGroupHdl *prometheusApi.SendGroupHandler,
	auditHdl *systemApi.AuditHandler,
	formDesignHdl *workorderApi.FormDesignHandler,
	processHdl *workorderApi.WorkorderProcessHandler,
	templateHdl *workorderApi.TemplateHandler,
	instanceHdl *workorderApi.InstanceHandler,
	instanceFlowHdl *workorderApi.InstanceFlowHandler,
	instanceCommentHdl *workorderApi.InstanceCommentHandler,
	categoryHdl *workorderApi.CategoryGroupHandler,
	instanceTimeLineHdl *workorderApi.InstanceTimeLineHandler,
	treeNodeHdl *resourceApi.TreeNodeHandler,
	treeLocalHdl *resourceApi.TreeLocalHandler,
	notificationHdl *workorderApi.NotificationHandler,
	ingressHdl *k8sApi.K8sIngressHandler,
	k8sPodHdl *k8sApi.K8sPodHandler,
) *gin.Engine

InitGinServer 初始化web服务

func InitLogger

func InitLogger() *zap.Logger

InitLogger 将日志输出到./logs/cloudops-{日期}.log,并同时输出到控制台

func InitMiddlewares

func InitMiddlewares(ih ijwt.Handler, l *zap.Logger, roleSvc service.RoleService, auditSvc service.AuditService) []gin.HandlerFunc

InitMiddlewares 初始化中间件

func InitNotificationConfig

func InitNotificationConfig() notification.NotificationConfig

InitNotificationConfig 初始化通知配置

func InitNotificationManager

func InitNotificationManager(config notification.NotificationConfig, asynqClient *asynq.Client, logger *zap.Logger) *notification.Manager

InitNotificationManager 初始化通知管理器

func InitRedis

func InitRedis() redis.Cmdable

func InitScheduler

func InitScheduler() *asynq.Scheduler

func InitTables

func InitTables(db *gorm.DB) error

func InitTrans

func InitTrans() error

InitTrans 初始化中文翻译器

func InitViper

func InitViper() error

InitViper 初始化viper配置,支持环境变量优先级:环境变量 > 配置文件 > 默认值

func InitWebHookViper

func InitWebHookViper()

func IsDBAvailable

func IsDBAvailable(db *gorm.DB) bool

Types

type AliyunConfig

type AliyunConfig struct {
	AccessKeyID     string `env:"ALIYUN_ACCESS_KEY_ID" default:""`
	AccessKeySecret string `env:"ALIYUN_ACCESS_KEY_SECRET" default:""`
}

AliyunConfig 阿里云配置(来自环境变量)

type Cmd

type Cmd struct {
	Server    *gin.Engine
	Bootstrap startup.ApplicationBootstrap
	Cron      cron.CronManager
}

func ProvideCmd

func ProvideCmd() *Cmd

type Config

type Config struct {
	Server       ServerConfig       `mapstructure:"server"`
	Log          LogConfig          `mapstructure:"log"`
	JWT          JWTConfig          `mapstructure:"jwt"`
	Redis        RedisConfig        `mapstructure:"redis"`
	MySQL        MySQLConfig        `mapstructure:"mysql"`
	Tree         TreeConfig         `mapstructure:"tree"`
	K8s          K8sConfig          `mapstructure:"k8s"`
	Prometheus   PrometheusConfig   `mapstructure:"prometheus"`
	Mock         MockConfig         `mapstructure:"mock"`
	Notification NotificationConfig `mapstructure:"notification"`
	Webhook      WebhookConfig      `mapstructure:"webhook"`
}

Config 应用配置结构体

type EmailConfig

type EmailConfig struct {
	Enabled       bool   `mapstructure:"enabled" env:"NOTIFICATION_EMAIL_ENABLED" default:"false"`
	SMTPHost      string `mapstructure:"smtp_host" env:"NOTIFICATION_EMAIL_SMTP_HOST" default:"smtp.gmail.com"`
	SMTPPort      int    `mapstructure:"smtp_port" env:"NOTIFICATION_EMAIL_SMTP_PORT" default:"587"`
	Username      string `mapstructure:"username" env:"NOTIFICATION_EMAIL_USERNAME" default:""`
	Password      string `mapstructure:"password" env:"NOTIFICATION_EMAIL_PASSWORD" default:""`
	FromName      string `mapstructure:"from_name" env:"NOTIFICATION_EMAIL_FROM_NAME" default:"AI-CloudOps"`
	MaxRetries    int    `mapstructure:"max_retries" env:"NOTIFICATION_EMAIL_MAX_RETRIES" default:"3"`
	RetryInterval string `mapstructure:"retry_interval" env:"NOTIFICATION_EMAIL_RETRY_INTERVAL" default:"5m"`
	Timeout       string `mapstructure:"timeout" env:"NOTIFICATION_EMAIL_TIMEOUT" default:"30s"`
	UseTLS        bool   `mapstructure:"use_tls" env:"NOTIFICATION_EMAIL_USE_TLS" default:"true"`
}

EmailConfig 邮箱配置

func (*EmailConfig) GetChannelName

func (c *EmailConfig) GetChannelName() string

GetChannelName 获取邮件渠道名称

func (*EmailConfig) GetFromName

func (c *EmailConfig) GetFromName() string

GetFromName 获取邮件发件人显示名称

func (*EmailConfig) GetMaxRetries

func (c *EmailConfig) GetMaxRetries() int

GetMaxRetries 获取邮件发送最大重试次数

func (*EmailConfig) GetPassword

func (c *EmailConfig) GetPassword() string

GetPassword 获取邮箱账号密码

func (*EmailConfig) GetRetryInterval

func (c *EmailConfig) GetRetryInterval() time.Duration

GetRetryInterval 获取邮件发送重试间隔

func (*EmailConfig) GetSMTPHost

func (c *EmailConfig) GetSMTPHost() string

GetSMTPHost 获取SMTP服务器地址

func (*EmailConfig) GetSMTPPort

func (c *EmailConfig) GetSMTPPort() int

GetSMTPPort 获取SMTP服务器端口

func (*EmailConfig) GetTimeout

func (c *EmailConfig) GetTimeout() time.Duration

GetTimeout 获取邮件发送超时时间

func (*EmailConfig) GetUseTLS

func (c *EmailConfig) GetUseTLS() bool

GetUseTLS 检查是否使用TLS加密连接

func (*EmailConfig) GetUsername

func (c *EmailConfig) GetUsername() string

GetUsername 获取邮箱账号用户名

func (*EmailConfig) IsEnabled

func (c *EmailConfig) IsEnabled() bool

IsEnabled 检查邮件通知是否启用

func (*EmailConfig) Validate

func (c *EmailConfig) Validate() error

Validate 验证邮件配置有效性

type ExternalConfig

type ExternalConfig struct {
	LLM    LLMConfig    `mapstructure:"llm"`
	Aliyun AliyunConfig `mapstructure:"aliyun"`
	Tavily TavilyConfig `mapstructure:"tavily"`
}

ExternalConfig 外部服务配置(仅来自环境变量)

type FeishuConfig

type FeishuConfig struct {
	Enabled              bool   `mapstructure:"enabled" env:"NOTIFICATION_FEISHU_ENABLED" default:"false"`
	AppID                string `mapstructure:"app_id" env:"NOTIFICATION_FEISHU_APP_ID" default:""`
	AppSecret            string `mapstructure:"app_secret" env:"NOTIFICATION_FEISHU_APP_SECRET" default:""`
	WebhookURL           string `mapstructure:"webhook_url" env:"NOTIFICATION_FEISHU_WEBHOOK_URL" default:"https://open.feishu.cn/open-apis/bot/v2/hook/"`
	PrivateMessageAPI    string `` /* 138-byte string literal not displayed */
	TenantAccessTokenAPI string `` /* 168-byte string literal not displayed */
	MaxRetries           int    `mapstructure:"max_retries" env:"NOTIFICATION_FEISHU_MAX_RETRIES" default:"3"`
	RetryInterval        string `mapstructure:"retry_interval" env:"NOTIFICATION_FEISHU_RETRY_INTERVAL" default:"5m"`
	Timeout              string `mapstructure:"timeout" env:"NOTIFICATION_FEISHU_TIMEOUT" default:"10s"`
}

FeishuConfig 飞书配置

func (*FeishuConfig) GetAppID

func (c *FeishuConfig) GetAppID() string

GetAppID 获取飞书应用ID

func (*FeishuConfig) GetAppSecret

func (c *FeishuConfig) GetAppSecret() string

GetAppSecret 获取飞书应用密钥

func (*FeishuConfig) GetChannelName

func (c *FeishuConfig) GetChannelName() string

GetChannelName 获取飞书渠道名称

func (*FeishuConfig) GetMaxRetries

func (c *FeishuConfig) GetMaxRetries() int

GetMaxRetries 获取飞书发送最大重试次数

func (*FeishuConfig) GetPrivateMessageAPI

func (c *FeishuConfig) GetPrivateMessageAPI() string

GetPrivateMessageAPI 获取飞书私聊消息 API 地址

func (*FeishuConfig) GetRetryInterval

func (c *FeishuConfig) GetRetryInterval() time.Duration

GetRetryInterval 获取飞书发送重试间隔

func (*FeishuConfig) GetTenantAccessTokenAPI

func (c *FeishuConfig) GetTenantAccessTokenAPI() string

GetTenantAccessTokenAPI 获取飞书租户访问令牌 API 地址

func (*FeishuConfig) GetTimeout

func (c *FeishuConfig) GetTimeout() time.Duration

GetTimeout 获取飞书请求超时时间

func (*FeishuConfig) GetWebhookURL

func (c *FeishuConfig) GetWebhookURL() string

GetWebhookURL 获取飞书群机器人 Webhook URL

func (*FeishuConfig) IsEnabled

func (c *FeishuConfig) IsEnabled() bool

IsEnabled 检查飞书通知是否启用

func (*FeishuConfig) Validate

func (c *FeishuConfig) Validate() error

Validate 验证飞书配置有效性

type ImFeishuConfig

type ImFeishuConfig struct {
	GroupMessageAPI       string `` /* 132-byte string literal not displayed */
	RequestTimeoutSeconds int    `mapstructure:"request_timeout_seconds" env:"WEBHOOK_IM_FEISHU_REQUEST_TIMEOUT_SECONDS" default:"10"`
	PrivateRobotAppID     string `mapstructure:"private_robot_app_id" env:"WEBHOOK_IM_FEISHU_PRIVATE_ROBOT_APP_ID" default:""`
	PrivateRobotAppSecret string `mapstructure:"private_robot_app_secret" env:"WEBHOOK_IM_FEISHU_PRIVATE_ROBOT_APP_SECRET" default:""`
	TenantAccessTokenAPI  string `` /* 166-byte string literal not displayed */
}

ImFeishuConfig 飞书即时消息配置

type JWTConfig

type JWTConfig struct {
	Key1       string `mapstructure:"key1" env:"JWT_KEY1" default:"ebe3vxIP7sblVvUHXb7ZaiMPuz4oXo0l"`
	Key2       string `mapstructure:"key2" env:"JWT_KEY2" default:"ebe3vxIP7sblVvUHXb7ZaiMPuz4oXo0z"`
	Issuer     string `mapstructure:"issuer" env:"JWT_ISSUER" default:"K5mBPBYNQeNWEBvCTE5msog3KSGTdhmx"`
	Expiration int64  `mapstructure:"expiration" env:"JWT_EXPIRATION" default:"3600"`
}

JWTConfig JWT配置

type K8sConfig

type K8sConfig struct {
	RefreshCron string `mapstructure:"refresh_cron" env:"K8S_REFRESH_CRON" default:"@every 300s"`
}

K8sConfig Kubernetes配置

type LLMConfig

type LLMConfig struct {
	APIKey  string `env:"LLM_API_KEY" default:""`
	BaseURL string `env:"LLM_BASE_URL" default:""`
}

LLMConfig LLM配置(来自环境变量)

type LogConfig

type LogConfig struct {
	Dir   string `mapstructure:"dir" env:"LOG_DIR" default:"./logs"`
	Level string `mapstructure:"level" env:"LOG_LEVEL" default:"debug"`
}

LogConfig 日志配置

type MockConfig

type MockConfig struct {
	Enabled bool `mapstructure:"enabled" env:"MOCK_ENABLED" default:"true"`
}

MockConfig Mock配置

type MySQLConfig

type MySQLConfig struct {
	Addr string `` /* 126-byte string literal not displayed */
}

MySQLConfig MySQL配置

type NotificationConfig

type NotificationConfig struct {
	Email  *EmailConfig  `mapstructure:"email"`
	Feishu *FeishuConfig `mapstructure:"feishu"`
}

NotificationConfig 通知配置

func (*NotificationConfig) GetEmail

func (c *NotificationConfig) GetEmail() *EmailConfig

GetEmail 获取邮件通知配置

func (*NotificationConfig) GetFeishu

func (c *NotificationConfig) GetFeishu() *FeishuConfig

GetFeishu 获取飞书通知配置

type NotificationConfigAdapter

type NotificationConfigAdapter struct {
	// contains filtered or unexported fields
}

NotificationConfigAdapter 通知配置适配器

func (*NotificationConfigAdapter) GetEmail

GetEmail 获取邮箱配置

func (*NotificationConfigAdapter) GetFeishu

GetFeishu 获取飞书配置

type PrometheusConfig

type PrometheusConfig struct {
	RefreshCron         string `mapstructure:"refresh_cron" env:"PROMETHEUS_REFRESH_CRON" default:"@every 15s"`
	EnableAlert         int    `mapstructure:"enable_alert" env:"PROMETHEUS_ENABLE_ALERT" default:"0"`
	EnableRecord        int    `mapstructure:"enable_record" env:"PROMETHEUS_ENABLE_RECORD" default:"0"`
	AlertWebhookAddr    string `mapstructure:"alert_webhook_addr" env:"PROMETHEUS_ALERT_WEBHOOK_ADDR" default:"http://localhost:8889/api/v1/alerts/receive"`
	AlertWebhookFileDir string `mapstructure:"alert_webhook_file_dir" env:"PROMETHEUS_ALERT_WEBHOOK_FILE_DIR" default:"/tmp/webhook_files"`
	HttpSdAPI           string `mapstructure:"httpSdAPI" env:"PROMETHEUS_HTTP_SD_API" default:"http://localhost:8888/api/not_auth/getTreeNodeBindIps"`
}

PrometheusConfig Prometheus配置

type RedisConfig

type RedisConfig struct {
	Addr     string `mapstructure:"addr" env:"REDIS_ADDR" default:"localhost:6379"`
	Password string `mapstructure:"password" env:"REDIS_PASSWORD" default:""`
}

RedisConfig Redis配置

type ServerConfig

type ServerConfig struct {
	Port string `mapstructure:"port" env:"SERVER_PORT" default:"8889"`
}

ServerConfig 服务器配置

type TavilyConfig

type TavilyConfig struct {
	APIKey string `env:"TAVILY_API_KEY" default:""`
}

TavilyConfig Tavily配置(来自环境变量)

type TreeConfig

type TreeConfig struct {
	CheckStatusCron       string `mapstructure:"check_status_cron" env:"TREE_CHECK_STATUS_CRON" default:"@every 300s"`
	PasswordEncryptionKey string `mapstructure:"password_encryption_key" env:"TREE_PASSWORD_ENCRYPTION_KEY" default:"ebe3vxIP7sblVvUHXb7ZaiMPuz4oXo0l"`
}

TreeConfig 树形结构配置

type WebhookConfig

type WebhookConfig struct {
	Port                          string         `mapstructure:"port" env:"WEBHOOK_PORT" default:"8888"`
	FixedWorkers                  int            `mapstructure:"fixed_workers" env:"WEBHOOK_FIXED_WORKERS" default:"10"`
	FrontDomain                   string         `mapstructure:"front_domain" env:"WEBHOOK_FRONT_DOMAIN" default:"http://localhost:3000"`
	BackendDomain                 string         `mapstructure:"backend_domain" env:"WEBHOOK_BACKEND_DOMAIN" default:"http://localhost:8889"`
	DefaultUpgradeMinutes         int            `mapstructure:"default_upgrade_minutes" env:"WEBHOOK_DEFAULT_UPGRADE_MINUTES" default:"60"`
	AlertManagerAPI               string         `mapstructure:"alert_manager_api" env:"WEBHOOK_ALERT_MANAGER_API" default:"http://localhost:9093"`
	CommonMapRenewIntervalSeconds int            `mapstructure:"common_map_renew_interval_seconds" env:"WEBHOOK_COMMON_MAP_RENEW_INTERVAL_SECONDS" default:"300"`
	ImFeishu                      ImFeishuConfig `mapstructure:"im_feishu"`
}

WebhookConfig Webhook配置(用于webhook子系统)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL