1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-24 08:22:21 +02:00

improve code quality (#1792)

* Merge variable declaration with assignment
* Fix unnecessary typecasting on `bytes.Buffer`
* Remove unnecessary wrapping of function call
This commit is contained in:
Shubhendra Singh Chauhan 2021-02-26 15:34:34 +05:30 committed by GitHub
parent b0f56eaf96
commit 6a666acd5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 23 deletions

View File

@ -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 {
@ -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)

View File

@ -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"))
}
@ -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())
@ -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())
@ -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())

View File

@ -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"]))

View File

@ -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

View File

@ -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": {