浏览代码

convert ifelseif to switch (#2529)

Laurence Jones 1 年之前
父节点
当前提交
0dd22e8b93
共有 1 个文件被更改,包括 4 次插入3 次删除
  1. 4 3
      pkg/exprhelpers/crowdsec_cti.go

+ 4 - 3
pkg/exprhelpers/crowdsec_cti.go

@@ -112,15 +112,16 @@ func CrowdsecCTI(params ...any) (any, error) {
 	ctiResp, err := ctiClient.GetIPInfo(ip)
 	ctiClient.Logger.Debugf("request for %s took %v", ip, time.Since(before))
 	if err != nil {
-		if err == cticlient.ErrUnauthorized {
+		switch err {
+		case cticlient.ErrUnauthorized:
 			CTIApiEnabled = false
 			ctiClient.Logger.Errorf("Invalid API key provided, disabling CTI API")
 			return &cticlient.SmokeItem{}, cticlient.ErrUnauthorized
-		} else if err == cticlient.ErrLimit {
+		case cticlient.ErrLimit:
 			CTIBackOffUntil = time.Now().Add(CTIBackOffDuration)
 			ctiClient.Logger.Errorf("CTI API is throttled, will try again in %s", CTIBackOffDuration)
 			return &cticlient.SmokeItem{}, cticlient.ErrLimit
-		} else {
+		default:
 			ctiClient.Logger.Warnf("CTI API error : %s", err)
 			return &cticlient.SmokeItem{}, fmt.Errorf("unexpected error : %v", err)
 		}