fadd
This commit is contained in:
50
internal/infrastructure/external/rongxing/rongxing_factory.go
vendored
Normal file
50
internal/infrastructure/external/rongxing/rongxing_factory.go
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
package rongxing
|
||||
|
||||
import (
|
||||
"hyapi-server/internal/config"
|
||||
"hyapi-server/internal/shared/external_logger"
|
||||
)
|
||||
|
||||
// NewRongxingServiceWithConfig 使用配置创建戎行服务
|
||||
func NewRongxingServiceWithConfig(cfg *config.Config) (*RongxingService, error) {
|
||||
loggingConfig := external_logger.ExternalServiceLoggingConfig{
|
||||
Enabled: cfg.Rongxing.Logging.Enabled,
|
||||
LogDir: cfg.Rongxing.Logging.LogDir,
|
||||
ServiceName: "rongxing",
|
||||
UseDaily: cfg.Rongxing.Logging.UseDaily,
|
||||
EnableLevelSeparation: cfg.Rongxing.Logging.EnableLevelSeparation,
|
||||
LevelConfigs: make(map[string]external_logger.ExternalServiceLevelFileConfig),
|
||||
}
|
||||
|
||||
if cfg.Rongxing.Logging.ServiceName != "" {
|
||||
loggingConfig.ServiceName = cfg.Rongxing.Logging.ServiceName
|
||||
}
|
||||
|
||||
for key, value := range cfg.Rongxing.Logging.LevelConfigs {
|
||||
loggingConfig.LevelConfigs[key] = external_logger.ExternalServiceLevelFileConfig{
|
||||
MaxSize: value.MaxSize,
|
||||
MaxBackups: value.MaxBackups,
|
||||
MaxAge: value.MaxAge,
|
||||
Compress: value.Compress,
|
||||
}
|
||||
}
|
||||
|
||||
logger, err := external_logger.NewExternalServiceLogger(loggingConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
timeout := cfg.Rongxing.Timeout
|
||||
if timeout <= 0 {
|
||||
timeout = defaultRequestTimeout
|
||||
}
|
||||
|
||||
return NewRongxingService(serviceConfig{
|
||||
BaseURL: cfg.Rongxing.URL,
|
||||
Account: cfg.Rongxing.Account,
|
||||
Password: cfg.Rongxing.Password,
|
||||
AppID: cfg.Rongxing.AppID,
|
||||
PrivateKey: cfg.Rongxing.PrivateKey,
|
||||
Timeout: timeout,
|
||||
}, logger), nil
|
||||
}
|
||||
Reference in New Issue
Block a user