Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add golangci lint to github action workflow #1068

Merged
merged 15 commits into from
Aug 31, 2023
Prev Previous commit
Next Next commit
update based on githubci lint
  • Loading branch information
suchen-sci committed Aug 29, 2023
commit be7ec3c4be304310052ec6d921021163a8656193
4 changes: 2 additions & 2 deletions pkg/filters/proxies/loadbalance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ func TestWeightedRandomLoadBalancePolicy(t *testing.T) {
lb := NewGeneralLoadBalancer(&LoadBalanceSpec{Policy: LoadBalancePolicyWeightedRandom}, servers)
lb.Init(nil, nil, nil)

for i := 0; i < 1000; i++ {
for i := 0; i < 50000; i++ {
svr := lb.ChooseServer(nil)
counter[svr.Weight-1]++
}

v := 0
for i := 0; i < 10; i++ {
if v >= counter[i] {
t.Error("possibility is not weighted even")
t.Errorf("possibility is not weighted even %v", counter)
}
v = counter[i]
}
Expand Down
25 changes: 11 additions & 14 deletions pkg/protocols/httpprot/httpheader/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,20 @@ func NewValidator(spec *ValidatorSpec) *Validator {
func (v Validator) Validate(h *HTTPHeader) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on doc.

if one of the header values of any header of the request is found in the array, the request is considered to pass the validation of current rule.
if one of the header values of any header of the request matches this regular expression, the request is considered to pass the validation of current rule

for key, vv := range *v.spec {
values := h.GetAll(key)
if len(values) == 0 {
return fmt.Errorf("header %s not found", key)
}
// check all Values in validator are in header
for _, v := range vv.Values {
if !stringtool.StrInSlice(v, values) {
return fmt.Errorf("header %s not contain value %s", key, v)
valid := false
for _, value := range values {
if stringtool.StrInSlice(value, vv.Values) {
valid = true
break
}
}
// check all values in header match regexp
if vv.re != nil {
for _, value := range values {
if !vv.re.MatchString(value) {
return fmt.Errorf("header %s:%s is invalid", key, value)
}
if vv.re != nil && vv.re.MatchString(value) {
valid = true
break
}
}
if !valid {
return fmt.Errorf("header %s is invalid", key)
}
}
return nil
}