From ad32f9de237c9258f67eb2c43ccc3424a7a86aa4 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Fri, 26 Feb 2021 16:27:04 +0800 Subject: [PATCH] fix golint issues in core/threading (#524) --- core/threading/routinegroup.go | 2 ++ core/threading/taskrunner.go | 3 +++ core/threading/workergroup.go | 3 +++ rest/httpx/util.go | 4 ++-- rest/httpx/util_test.go | 2 +- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core/threading/routinegroup.go b/core/threading/routinegroup.go index b71aebf9..00a17638 100644 --- a/core/threading/routinegroup.go +++ b/core/threading/routinegroup.go @@ -2,10 +2,12 @@ package threading import "sync" +// A RoutineGroup is used to group goroutines together and all wait all goroutines to be done. type RoutineGroup struct { waitGroup sync.WaitGroup } +// NewRoutineGroup returns a RoutineGroup. func NewRoutineGroup() *RoutineGroup { return new(RoutineGroup) } diff --git a/core/threading/taskrunner.go b/core/threading/taskrunner.go index ba0c7b34..6441b386 100644 --- a/core/threading/taskrunner.go +++ b/core/threading/taskrunner.go @@ -5,16 +5,19 @@ import ( "github.com/tal-tech/go-zero/core/rescue" ) +// A TaskRunner is used to control the concurrency of goroutines. type TaskRunner struct { limitChan chan lang.PlaceholderType } +// NewTaskRunner returns a TaskRunner. func NewTaskRunner(concurrency int) *TaskRunner { return &TaskRunner{ limitChan: make(chan lang.PlaceholderType, concurrency), } } +// Schedule schedules a task to run under concurrency control. func (rp *TaskRunner) Schedule(task func()) { rp.limitChan <- lang.Placeholder diff --git a/core/threading/workergroup.go b/core/threading/workergroup.go index a5100820..ccec6d9d 100644 --- a/core/threading/workergroup.go +++ b/core/threading/workergroup.go @@ -1,10 +1,12 @@ package threading +// A WorkerGroup is used to run given number of workers to process jobs. type WorkerGroup struct { job func() workers int } +// NewWorkerGroup returns a WorkerGroup with given job and workers. func NewWorkerGroup(job func(), workers int) WorkerGroup { return WorkerGroup{ job: job, @@ -12,6 +14,7 @@ func NewWorkerGroup(job func(), workers int) WorkerGroup { } } +// Start starts a WorkerGroup. func (wg WorkerGroup) Start() { group := NewRoutineGroup() for i := 0; i < wg.workers; i++ { diff --git a/rest/httpx/util.go b/rest/httpx/util.go index f83bce68..2f7c9755 100644 --- a/rest/httpx/util.go +++ b/rest/httpx/util.go @@ -2,11 +2,11 @@ package httpx import "net/http" -const xForwardFor = "X-Forwarded-For" +const xForwardedFor = "X-Forwarded-For" // GetRemoteAddr returns the peer address, supports X-Forward-For. func GetRemoteAddr(r *http.Request) string { - v := r.Header.Get(xForwardFor) + v := r.Header.Get(xForwardedFor) if len(v) > 0 { return v } diff --git a/rest/httpx/util_test.go b/rest/httpx/util_test.go index bcd9c416..ccef347c 100644 --- a/rest/httpx/util_test.go +++ b/rest/httpx/util_test.go @@ -13,6 +13,6 @@ func TestGetRemoteAddr(t *testing.T) { r, err := http.NewRequest(http.MethodGet, "/", strings.NewReader("")) assert.Nil(t, err) - r.Header.Set(xForwardFor, host) + r.Header.Set(xForwardedFor, host) assert.Equal(t, host, GetRemoteAddr(r)) }