@@ -136,17 +136,15 @@ func ValidateTrafficIntercept(URL string, method string) (result *ValidateResult
136
136
if indexes == nil {
137
137
indexes = defaultTrafficInterceptStore .normalIndexes [indexForRest (URL , "*" )]
138
138
}
139
- if indexes != nil {
140
- for key := range indexes {
141
- trafficInterceptRule := defaultTrafficInterceptStore .rules [key ]
142
- if trafficInterceptRule != nil {
143
- if appsv1alpha1 .InterceptTypeWhite == trafficInterceptRule .InterceptType {
144
- result = & ValidateResult {Allowed : true , Reason : "white" , Message : fmt .Sprintf ("Traffic is allow by white rule, name: %s" , trafficInterceptRule .Name )}
145
- return result
146
- } else if appsv1alpha1 .InterceptTypeBlack == trafficInterceptRule .InterceptType {
147
- result = & ValidateResult {Allowed : false , Reason : "black" , Message : fmt .Sprintf ("Traffic is intercept by black rule, name: %s" , trafficInterceptRule .Name )}
148
- return result
149
- }
139
+ for key := range indexes {
140
+ trafficInterceptRule := defaultTrafficInterceptStore .rules [key ]
141
+ if trafficInterceptRule != nil {
142
+ if appsv1alpha1 .InterceptTypeWhite == trafficInterceptRule .InterceptType {
143
+ result = & ValidateResult {Allowed : true , Reason : "white" , Message : fmt .Sprintf ("Traffic is allow by white rule, name: %s" , trafficInterceptRule .Name )}
144
+ return result
145
+ } else if appsv1alpha1 .InterceptTypeBlack == trafficInterceptRule .InterceptType {
146
+ result = & ValidateResult {Allowed : false , Reason : "black" , Message : fmt .Sprintf ("Traffic is intercept by black rule, name: %s" , trafficInterceptRule .Name )}
147
+ return result
150
148
}
151
149
}
152
150
}
@@ -182,7 +180,7 @@ func ValidateTrafficIntercept(URL string, method string) (result *ValidateResult
182
180
func ValidateRest (URL string , method string ) (result ValidateResult ) {
183
181
now := time .Now ()
184
182
defer func () {
185
- logger .Info ("validate rest" , "URL" , URL , "method" , method , "result" , result , "cost time" , time .Now (). Sub (now ).String ())
183
+ logger .Info ("validate rest" , "URL" , URL , "method" , method , "result" , result , "cost time" , time .Since (now ).String ())
186
184
}()
187
185
188
186
if ! EnableCircuitBreaker {
@@ -206,7 +204,7 @@ func ValidateRest(URL string, method string) (result ValidateResult) {
206
204
func ValidateRestWithOption (URL string , method string , isPre bool ) (result ValidateResult ) {
207
205
now := time .Now ()
208
206
defer func () {
209
- logger .Info ("validate rest" , "URL" , URL , "method" , method , "result" , result , "cost time" , time .Now (). Sub (now ).String ())
207
+ logger .Info ("validate rest" , "URL" , URL , "method" , method , "result" , result , "cost time" , time .Since (now ).String ())
210
208
}()
211
209
212
210
if ! EnableCircuitBreaker {
@@ -232,7 +230,7 @@ func ValidateRestWithOption(URL string, method string, isPre bool) (result Valid
232
230
func ValidateResource (namespace , apiGroup , resource , verb string ) (result ValidateResult ) {
233
231
now := time .Now ()
234
232
defer func () {
235
- logger .Info ("validate resource" , "namespace" , namespace , "apiGroup" , apiGroup , "resource" , resource , "verb" , verb , "result" , result , "cost time" , time .Now (). Sub (now ).String ())
233
+ logger .Info ("validate resource" , "namespace" , namespace , "apiGroup" , apiGroup , "resource" , resource , "verb" , verb , "result" , result , "cost time" , time .Since (now ).String ())
236
234
}()
237
235
238
236
if ! EnableCircuitBreaker {
@@ -256,7 +254,7 @@ func ValidateResource(namespace, apiGroup, resource, verb string) (result Valida
256
254
func ValidateResourceWithOption (namespace , apiGroup , resource , verb string , isPre bool ) (result ValidateResult ) {
257
255
now := time .Now ()
258
256
defer func () {
259
- logger .Info ("validate resource" , "namespace" , namespace , "apiGroup" , apiGroup , "resource" , resource , "verb" , verb , "result" , result , "cost time" , time .Now (). Sub (now ).String ())
257
+ logger .Info ("validate resource" , "namespace" , namespace , "apiGroup" , apiGroup , "resource" , resource , "verb" , verb , "result" , result , "cost time" , time .Since (now ).String ())
260
258
}()
261
259
262
260
if ! EnableCircuitBreaker {
@@ -280,9 +278,7 @@ func ValidateResourceWithOption(namespace, apiGroup, resource, verb string, isPr
280
278
func generateWildcardUrls (URL string , method string ) []string {
281
279
var result []string
282
280
result = append (result , indexForRest (URL , method ))
283
- if strings .HasSuffix (URL , "/" ) {
284
- URL = strings .TrimSuffix (URL , "/" )
285
- }
281
+ URL = strings .TrimSuffix (URL , "/" )
286
282
u , err := url .Parse (URL )
287
283
if err != nil {
288
284
logger .Error (err , "failed to url" , "URL" , URL , "method" , method )
@@ -312,8 +308,7 @@ func generateWildcardSeeds(namespace, apiGroup, resource, verb string) []string
312
308
2、if wildcard number equal, the priority order is verb > resource > apiGroup > namespace.
313
309
eg. verb exist first match verb, then match resource, after match apiGroup, last match namespace
314
310
*/
315
- var result []string
316
- result = []string {
311
+ result := []string {
317
312
// zero wildcard
318
313
indexForResource (namespace , apiGroup , resource , verb ),
319
314
// one wildcard
0 commit comments