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

improve code quality #1792

Merged
merged 3 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ type ValueBinder struct {
// QueryParamsBinder creates query parameter value binder
func QueryParamsBinder(c Context) *ValueBinder {
return &ValueBinder{
failFast: true,
ValueFunc: func(sourceParam string) string {
return c.QueryParam(sourceParam)
},
failFast: true,
ValueFunc: c.QueryParam,
ValuesFunc: func(sourceParam string) []string {
values, ok := c.QueryParams()[sourceParam]
if !ok {
Expand All @@ -119,10 +117,8 @@ func QueryParamsBinder(c Context) *ValueBinder {
// PathParamsBinder creates path parameter value binder
func PathParamsBinder(c Context) *ValueBinder {
return &ValueBinder{
failFast: true,
ValueFunc: func(sourceParam string) string {
return c.Param(sourceParam)
},
failFast: true,
ValueFunc: c.Param,
ValuesFunc: func(sourceParam string) []string {
// path parameter should not have multiple values so getting values does not make sense but lets not error out here
value := c.Param(sourceParam)
Expand Down
12 changes: 4 additions & 8 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,7 @@ func TestContextRedirect(t *testing.T) {
}

func TestContextStore(t *testing.T) {
var c Context
c = new(context)
var c Context = new(context)
c.Set("name", "Jon Snow")
testify.Equal(t, "Jon Snow", c.Get("name"))
}
Expand Down Expand Up @@ -687,8 +686,7 @@ func TestContextHandler(t *testing.T) {
}

func TestContext_SetHandler(t *testing.T) {
var c Context
c = new(context)
var c Context = new(context)

testify.Nil(t, c.Handler())

Expand All @@ -701,8 +699,7 @@ func TestContext_SetHandler(t *testing.T) {
func TestContext_Path(t *testing.T) {
path := "/pa/th"

var c Context
c = new(context)
var c Context = new(context)

c.SetPath(path)
testify.Equal(t, path, c.Path())
Expand Down Expand Up @@ -736,8 +733,7 @@ func TestContext_QueryString(t *testing.T) {
}

func TestContext_Request(t *testing.T) {
var c Context
c = new(context)
var c Context = new(context)

testify.Nil(t, c.Request())

Expand Down
2 changes: 1 addition & 1 deletion middleware/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestLoggerCustomTimestamp(t *testing.T) {
e.ServeHTTP(rec, req)

var objs map[string]*json.RawMessage
if err := json.Unmarshal([]byte(buf.String()), &objs); err != nil {
if err := json.Unmarshal(buf.Bytes(), &objs); err != nil {
panic(err)
}
loggedTime := *(*string)(unsafe.Pointer(objs["time"]))
Expand Down
4 changes: 1 addition & 3 deletions middleware/rate_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,4 @@ func (store *RateLimiterMemoryStore) cleanupStaleVisitors() {
/*
actual time method which is mocked in test file
*/
var now = func() time.Time {
return time.Now()
}
var now = time.Now
4 changes: 1 addition & 3 deletions middleware/rate_limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,7 @@ func TestRateLimiterMemoryStore_Allow(t *testing.T) {

func TestRateLimiterMemoryStore_cleanupStaleVisitors(t *testing.T) {
var inMemoryStore = NewRateLimiterMemoryStoreWithConfig(RateLimiterMemoryStoreConfig{Rate: 1, Burst: 3})
now = func() time.Time {
return time.Now()
}
now = time.Now
fmt.Println(now())
inMemoryStore.visitors = map[string]*Visitor{
"A": {
Expand Down