Skip to content

Commit

Permalink
Merge pull request #6 from housemecn/main
Browse files Browse the repository at this point in the history
 improve code,upgrade redis version
  • Loading branch information
houseme authored Mar 25, 2022
2 parents a2ae3e6 + 938648c commit bf93e75
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 149 deletions.
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/heiyeluren/koala

go 1.16

require (
github.com/gomodule/redigo v1.8.5
gopkg.in/yaml.v2 v2.3.0 // indirect
)
require github.com/gomodule/redigo v1.8.9-0.20220324232115-5b789c6cfe82
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gomodule/redigo v1.8.5 h1:nRAxCa+SVsyjSBrtZmG/cqb6VbTmuRzpg/PoTFlpumc=
github.com/gomodule/redigo v1.8.5/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
github.com/gomodule/redigo v1.8.9-0.20220324232115-5b789c6cfe82 h1:T13vzKSTMI3OQeCNkyR/x7GB1ugE40FLQKUAGRsvWLM=
github.com/gomodule/redigo v1.8.9-0.20220324232115-5b789c6cfe82/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion koala/KoalaKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (k *RangeKey) build(sp, ki, v string) error {
* matches
*/
func (k *RangeKey) matches(s string) bool {
// + 号,任意值逻辑,直接matche
// + 号,任意值逻辑,直接matches
for _, sco := range k.scopes {
if sco.op == "+" {
return true
Expand Down
1 change: 1 addition & 0 deletions koala/koala.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"runtime"

"github.com/gomodule/redigo/redis"

"github.com/heiyeluren/koala/utility"
)

Expand Down
10 changes: 5 additions & 5 deletions koala/koalaRule.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (

// Rule rule类型
type Rule struct {
method string //只能为如下四个字符串 count base direct leak
method string // 只能为如下四个字符串 count base direct leak
keys map[string]KoalaKey
base int32
time int32
Expand Down Expand Up @@ -255,7 +255,7 @@ func (k *Rule) getCacheValue(cacheKey string) (int, error) {
if err != nil {
return 0, err
}
//println(cacheKey, " --> value:", cacheValue)
// println(cacheKey, " --> value:", cacheValue)
return cacheValue, nil
}

Expand All @@ -276,7 +276,7 @@ func (k *Rule) countBrowse(cacheKey string) (bool, error) {
if err != nil {
return false, err
}
//println(cacheKey, " --> value:", cacheValue)
// println(cacheKey, " --> value:", cacheValue)
if k.count == 0 || k.count > int32(cacheValue) {
return false, nil
}
Expand Down Expand Up @@ -340,7 +340,7 @@ func (k *Rule) baseBrowse(cacheKey string) (bool, error) {
if err != nil {
return false, err
}
//println(cacheKey, " --> value:", cacheValue)
// println(cacheKey, " --> value:", cacheValue)
if k.base == 0 || k.base > int32(cacheValue) {
return false, nil
}
Expand All @@ -355,7 +355,7 @@ func (k *Rule) baseBrowse(cacheKey string) (bool, error) {
return false, err
}

//println(cacheKey_time, " --> value:", cacheValue)
// println(cacheKey_time, " --> value:", cacheValue)
if k.count == 0 || k.count > int32(cacheValue) {
return false, nil
}
Expand Down
4 changes: 2 additions & 2 deletions koala/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func PolicyInterpreter(extStream string) error {
if err = rulesBuilder(line); err != nil {
return errors.New(err.Error() + " ;AT-LINE-" + strconv.Itoa(index) + "; " + line)
}
//println(line)
// println(line)
}

// 解析返回结果配置
Expand Down Expand Up @@ -213,7 +213,7 @@ func resultsBuilder(result string) error {
if err = json.Unmarshal([]byte(inString), &ret); err != nil {
return err
}
//fmt.Printf("%+v \n", ret)
// fmt.Printf("%+v \n", ret)
TempPolicy.retValueTable[retType] = ret
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion koala/policyLoader.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func PolicyLoader() {
if err != nil {
logHandle.Warning("[errmsg=" + err.Error() + " md5=" + PolicyMd5 + "]")
}
//println(Policy_md5)
// println(Policy_md5)

if m != PolicyMd5 {
DynamicUpdateFiles = []string{}
Expand Down
4 changes: 2 additions & 2 deletions koala/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *FrontServer) DoRuleBrowse(request *utility.HttpRequest, response *utili
// 对命中的key,查缓存值,与阀值比较,判断是否超出限制
var isOut bool
ruleCacheKey := singleRule.getCacheKey(request.Gets())
//println(ruleCacheKey)
// println(ruleCacheKey)
switch singleRule.method {
case "direct":
isOut = true
Expand Down Expand Up @@ -364,7 +364,7 @@ func (s *FrontServer) DoMultiBrowse(request *utility.HttpRequest, response *util
logMsg += " intf=" + request.PathInfo()

var buffers []JobBuffer
//var job Job
// var job Job
for _, job := range jobs {
var buf JobBuffer
buf.ID = job.ID
Expand Down
1 change: 1 addition & 0 deletions utility/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ func (r *HttpResponse) Stream() []byte {
return b.Bytes()
}

// String . return string
func (r *HttpResponse) String() string {
return string(r.Stream())
}
Expand Down
Loading

0 comments on commit bf93e75

Please sign in to comment.