NewBaseAsyncPlugin 创建基础异步插件
(name string, priority int)
| 415 | |
| 416 | // NewBaseAsyncPlugin 创建基础异步插件 |
| 417 | func NewBaseAsyncPlugin(name string, priority int) *BaseAsyncPlugin { |
| 418 | // 确保异步插件已初始化 |
| 419 | if !initialized { |
| 420 | initAsyncPlugin() |
| 421 | } |
| 422 | |
| 423 | // 确定超时和缓存时间 |
| 424 | responseTimeout := defaultAsyncResponseTimeout |
| 425 | processingTimeout := defaultPluginTimeout |
| 426 | cacheTTL := defaultCacheTTL |
| 427 | |
| 428 | // 如果配置已初始化,则使用配置中的值 |
| 429 | if config.AppConfig != nil { |
| 430 | responseTimeout = config.AppConfig.AsyncResponseTimeoutDur |
| 431 | processingTimeout = config.AppConfig.PluginTimeout |
| 432 | cacheTTL = time.Duration(config.AppConfig.AsyncCacheTTLHours) * time.Hour |
| 433 | } |
| 434 | |
| 435 | return &BaseAsyncPlugin{ |
| 436 | name: name, |
| 437 | priority: priority, |
| 438 | client: &http.Client{ |
| 439 | Timeout: responseTimeout, |
| 440 | }, |
| 441 | backgroundClient: &http.Client{ |
| 442 | Timeout: processingTimeout, |
| 443 | }, |
| 444 | cacheTTL: cacheTTL, |
| 445 | finalUpdateTracker: make(map[string]bool), // 初始化缓存更新追踪器 |
| 446 | skipServiceFilter: false, // 默认不跳过Service层过滤 |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | // NewBaseAsyncPluginWithFilter 创建基础异步插件(支持设置Service层过滤参数) |
| 451 | func NewBaseAsyncPluginWithFilter(name string, priority int, skipServiceFilter bool) *BaseAsyncPlugin { |
no test coverage detected