优化结构

This commit is contained in:
Yvan
2026-08-30 01:08:10 +08:00
parent 509df03d61
commit e0c35e4e9b
23 changed files with 1513 additions and 38 deletions
+71 -4
View File
@@ -79,6 +79,25 @@ type IntegrationConnectionTester interface {
TestIntegration(context.Context, *IntegrationConfig) error
}
type ConnectionTestError struct {
Provider string
Err error
}
func (e *ConnectionTestError) Error() string {
if e == nil || strings.TrimSpace(e.Provider) == "" {
return "连接测试失败"
}
return strings.TrimSpace(e.Provider) + " 连接测试失败"
}
func (e *ConnectionTestError) Unwrap() error {
if e == nil {
return nil
}
return e.Err
}
type IntegrationConfigUsecase struct {
repo IntegrationConfigRepo
tester IntegrationConnectionTester
@@ -165,7 +184,14 @@ func (uc *IntegrationConfigUsecase) Test(ctx context.Context, config *Integratio
if uc.tester == nil {
return errors.New("集成连接测试器未初始化")
}
return uc.tester.TestIntegration(ctx, config)
if err := uc.tester.TestIntegration(ctx, config); err != nil {
provider := config.Provider
if definition, ok := IntegrationDefinition(config.Kind, config.Provider); ok && strings.TrimSpace(definition.Name) != "" {
provider = definition.Name
}
return &ConnectionTestError{Provider: provider, Err: err}
}
return nil
}
func (uc *IntegrationConfigUsecase) Delete(ctx context.Context, kind, provider string) error {
@@ -481,11 +507,52 @@ func IsIntegrationSecretKey(key string) bool {
}
func integrationInt64(values map[string]any, key string, fallback int64) int64 {
value := integrationText(values, key)
if value == "" {
value, exists := values[key]
if !exists || value == nil {
return fallback
}
parsed, err := strconv.ParseInt(value, 10, 64)
switch typed := value.(type) {
case int:
return int64(typed)
case int8:
return int64(typed)
case int16:
return int64(typed)
case int32:
return int64(typed)
case int64:
return typed
case uint:
return parseIntegrationInt64(strconv.FormatUint(uint64(typed), 10), fallback)
case uint8:
return int64(typed)
case uint16:
return int64(typed)
case uint32:
return int64(typed)
case uint64:
return parseIntegrationInt64(strconv.FormatUint(typed, 10), fallback)
case float32:
return parseIntegrationInt64(strconv.FormatFloat(float64(typed), 'f', -1, 32), fallback)
case float64:
return parseIntegrationInt64(strconv.FormatFloat(typed, 'f', -1, 64), fallback)
case json.Number:
if parsed, err := typed.Int64(); err == nil {
return parsed
}
if parsed, err := typed.Float64(); err == nil {
return parseIntegrationInt64(strconv.FormatFloat(parsed, 'f', -1, 64), fallback)
}
return fallback
case string:
return parseIntegrationInt64(typed, fallback)
default:
return parseIntegrationInt64(fmt.Sprint(typed), fallback)
}
}
func parseIntegrationInt64(value string, fallback int64) int64 {
parsed, err := strconv.ParseInt(strings.TrimSpace(value), 10, 64)
if err != nil {
return fallback
}