fix golint issues in core/load (#495)
This commit is contained in:
@@ -6,11 +6,13 @@ import (
|
|||||||
"github.com/tal-tech/go-zero/core/syncx"
|
"github.com/tal-tech/go-zero/core/syncx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// A ShedderGroup is a manager to manage key based shedders.
|
||||||
type ShedderGroup struct {
|
type ShedderGroup struct {
|
||||||
options []ShedderOption
|
options []ShedderOption
|
||||||
manager *syncx.ResourceManager
|
manager *syncx.ResourceManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewShedderGroup returns a ShedderGroup.
|
||||||
func NewShedderGroup(opts ...ShedderOption) *ShedderGroup {
|
func NewShedderGroup(opts ...ShedderOption) *ShedderGroup {
|
||||||
return &ShedderGroup{
|
return &ShedderGroup{
|
||||||
options: opts,
|
options: opts,
|
||||||
@@ -18,6 +20,7 @@ func NewShedderGroup(opts ...ShedderOption) *ShedderGroup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetShedder gets the Shedder for the given key.
|
||||||
func (g *ShedderGroup) GetShedder(key string) Shedder {
|
func (g *ShedderGroup) GetShedder(key string) Shedder {
|
||||||
shedder, _ := g.manager.GetResource(key, func() (closer io.Closer, e error) {
|
shedder, _ := g.manager.GetResource(key, func() (closer io.Closer, e error) {
|
||||||
return nopCloser{
|
return nopCloser{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// A SheddingStat is used to store the statistics for load shedding.
|
||||||
SheddingStat struct {
|
SheddingStat struct {
|
||||||
name string
|
name string
|
||||||
total int64
|
total int64
|
||||||
@@ -23,6 +24,7 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewSheddingStat returns a SheddingStat.
|
||||||
func NewSheddingStat(name string) *SheddingStat {
|
func NewSheddingStat(name string) *SheddingStat {
|
||||||
st := &SheddingStat{
|
st := &SheddingStat{
|
||||||
name: name,
|
name: name,
|
||||||
@@ -31,14 +33,17 @@ func NewSheddingStat(name string) *SheddingStat {
|
|||||||
return st
|
return st
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IncrementTotal increments the total requests.
|
||||||
func (s *SheddingStat) IncrementTotal() {
|
func (s *SheddingStat) IncrementTotal() {
|
||||||
atomic.AddInt64(&s.total, 1)
|
atomic.AddInt64(&s.total, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IncrementPass increments the passed requests.
|
||||||
func (s *SheddingStat) IncrementPass() {
|
func (s *SheddingStat) IncrementPass() {
|
||||||
atomic.AddInt64(&s.pass, 1)
|
atomic.AddInt64(&s.pass, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IncrementDrop increments the dropped requests.
|
||||||
func (s *SheddingStat) IncrementDrop() {
|
func (s *SheddingStat) IncrementDrop() {
|
||||||
atomic.AddInt64(&s.drop, 1)
|
atomic.AddInt64(&s.drop, 1)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user