Skip to content

Commit

Permalink
fix golint issues in core/threading (zeromicro#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan authored Feb 26, 2021
1 parent f309e9f commit ad32f9d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions core/threading/routinegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions core/threading/taskrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions core/threading/workergroup.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
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,
workers: workers,
}
}

// Start starts a WorkerGroup.
func (wg WorkerGroup) Start() {
group := NewRoutineGroup()
for i := 0; i < wg.workers; i++ {
Expand Down
4 changes: 2 additions & 2 deletions rest/httpx/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion rest/httpx/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit ad32f9d

Please sign in to comment.