fadd
This commit is contained in:
@@ -91,7 +91,25 @@ func (s *NuoerService) logError(transactionID, apiKey, seqNo string, err error,
|
||||
s.logger.LogError(seqNo, transactionID, apiKey, err, payload)
|
||||
}
|
||||
|
||||
func (s *NuoerService) CallAPI(ctx context.Context, apiKey, apiPath string, body map[string]string) (*nuoerResponse, error) {
|
||||
// CallAPIOption 诺尔智汇 CallAPI 可选参数
|
||||
type CallAPIOption func(*callAPIConfig)
|
||||
|
||||
type callAPIConfig struct {
|
||||
encryptionType int
|
||||
}
|
||||
|
||||
// WithEncryptionType 指定入参加密类型(如 MD5 入参为 2)
|
||||
func WithEncryptionType(encryptionType int) CallAPIOption {
|
||||
return func(c *callAPIConfig) {
|
||||
c.encryptionType = encryptionType
|
||||
}
|
||||
}
|
||||
|
||||
func (s *NuoerService) CallAPI(ctx context.Context, apiKey, apiPath string, body map[string]string, opts ...CallAPIOption) (*nuoerResponse, error) {
|
||||
cfg := callAPIConfig{}
|
||||
for _, opt := range opts {
|
||||
opt(&cfg)
|
||||
}
|
||||
requestURL := strings.TrimSuffix(s.config.URL, "/")
|
||||
if apiPath != "" {
|
||||
if !strings.HasPrefix(apiPath, "/") {
|
||||
@@ -116,6 +134,9 @@ func (s *NuoerService) CallAPI(ctx context.Context, apiKey, apiPath string, body
|
||||
"apiKey": apiKey,
|
||||
"body": body,
|
||||
}
|
||||
if cfg.encryptionType != 0 {
|
||||
requestPayload["encryptionType"] = cfg.encryptionType
|
||||
}
|
||||
|
||||
if s.logger != nil {
|
||||
s.logger.LogRequest("", transactionID, apiKey, requestURL)
|
||||
|
||||
Reference in New Issue
Block a user