diff --git a/adapter/context/param/conv_test.go b/adapter/context/param/conv_test.go index c27d385a..cd797250 100644 --- a/adapter/context/param/conv_test.go +++ b/adapter/context/param/conv_test.go @@ -23,7 +23,7 @@ import ( "github.com/beego/beego/v2/adapter/context" ) -func Demo(i int) { +func Demo(i int) { } @@ -37,4 +37,3 @@ func TestConvertParams(t *testing.T) { }, reflect.TypeOf(Demo), ctx) assert.Equal(t, int64(11), res[0].Int()) } - diff --git a/adapter/orm/models_boot_test.go b/adapter/orm/models_boot_test.go index 37dbfabd..5471885b 100644 --- a/adapter/orm/models_boot_test.go +++ b/adapter/orm/models_boot_test.go @@ -25,6 +25,7 @@ type User struct { type Seller struct { Id int } + func TestRegisterModelWithPrefix(t *testing.T) { RegisterModelWithPrefix("test", &User{}, &Seller{}) } diff --git a/client/cache/calc_utils.go b/client/cache/calc_utils.go index 91d0974b..733e2fc2 100644 --- a/client/cache/calc_utils.go +++ b/client/cache/calc_utils.go @@ -80,4 +80,4 @@ func decr(originVal interface{}) (interface{}, error) { default: return nil, fmt.Errorf("item val is not (u)int (u)int32 (u)int64") } -} \ No newline at end of file +} diff --git a/client/cache/calc_utils_test.go b/client/cache/calc_utils_test.go index b98e71de..e81c463b 100644 --- a/client/cache/calc_utils_test.go +++ b/client/cache/calc_utils_test.go @@ -19,7 +19,7 @@ func TestIncr(t *testing.T) { t.Errorf("incr failed, expect %v, but %v actually", updateVal, val) return } - _, err = incr(int(1 << (strconv.IntSize - 1) - 1)) + _, err = incr(int(1<<(strconv.IntSize-1) - 1)) if err == nil { t.Error("incr failed") return @@ -73,7 +73,7 @@ func TestIncr(t *testing.T) { t.Errorf("incr failed, expect %v, but %v actually", updateVal, val) return } - _, err = incr(uint(1 << (strconv.IntSize) - 1)) + _, err = incr(uint(1<<(strconv.IntSize) - 1)) if err == nil { t.Error("incr failed") return @@ -238,4 +238,4 @@ func TestDecr(t *testing.T) { t.Error("decr failed") return } -} \ No newline at end of file +} diff --git a/client/httplib/error_code.go b/client/httplib/error_code.go index 961e7e34..bd349a34 100644 --- a/client/httplib/error_code.go +++ b/client/httplib/error_code.go @@ -51,7 +51,6 @@ Sometimes you got JSON document and you want to make it as request body. So you If you do this, you got this code. Instead, you should call Header to set Content-type and call Body to set body data. `) - // start with 5 -------------------------------------------------------------------------- var CreateFormFileFailed = berror.DefineCode(5001001, moduleName, "CreateFormFileFailed", ` @@ -125,7 +124,3 @@ Make sure that: 1. You pass valid structure pointer to the function; 2. The body is valid YAML document `) - - - - diff --git a/client/httplib/http_response_test.go b/client/httplib/http_response_test.go index 90db3fca..a62dd42c 100644 --- a/client/httplib/http_response_test.go +++ b/client/httplib/http_response_test.go @@ -20,7 +20,6 @@ import ( "github.com/stretchr/testify/assert" ) - func TestNewHttpResponseWithJsonBody(t *testing.T) { // string resp := NewHttpResponseWithJsonBody("{}") diff --git a/client/httplib/httplib_test.go b/client/httplib/httplib_test.go index 36948de7..1fde708a 100644 --- a/client/httplib/httplib_test.go +++ b/client/httplib/httplib_test.go @@ -309,7 +309,6 @@ func TestFilterChainOrder(t *testing.T) { } }) - req.AddFilters(func(next Filter) Filter { return func(ctx context.Context, req *BeegoHTTPRequest) (*http.Response, error) { return NewHttpResponseWithJsonBody("second"), nil @@ -396,7 +395,7 @@ func TestBeegoHTTPRequest_Param(t *testing.T) { req.Param(key, value) assert.Equal(t, value, req.params[key][0]) - value1 := "test-param-value-1" + value1 := "test-param-value-1" req.Param(key, value1) assert.Equal(t, value1, req.params[key][1]) } @@ -419,10 +418,10 @@ func TestBeegoHTTPRequest_Body(t *testing.T) { req.Body(13) } - type user struct { Name string `xml:"name"` } + func TestBeegoHTTPRequest_XMLBody(t *testing.T) { req := Post("http://beego.me") body := &user{ @@ -432,4 +431,4 @@ func TestBeegoHTTPRequest_XMLBody(t *testing.T) { assert.True(t, req.req.ContentLength > 0) assert.Nil(t, err) assert.NotNil(t, req.req.GetBody) -} \ No newline at end of file +} diff --git a/client/httplib/mock/mock.go b/client/httplib/mock/mock.go index 7640e454..421a7a45 100644 --- a/client/httplib/mock/mock.go +++ b/client/httplib/mock/mock.go @@ -44,7 +44,7 @@ func StartMock() Stub { return mockFilter } -func CtxWithMock(ctx context.Context, mock... *Mock) context.Context { +func CtxWithMock(ctx context.Context, mock ...*Mock) context.Context { return context.WithValue(ctx, mockCtxKey, mock) } @@ -73,8 +73,6 @@ func NewMock(con RequestCondition, resp *http.Response, err error) *Mock { return &Mock{ cond: con, resp: resp, - err: err, + err: err, } } - - diff --git a/client/httplib/mock/mock_condition.go b/client/httplib/mock/mock_condition.go index 639b45a3..53d3d703 100644 --- a/client/httplib/mock/mock_condition.go +++ b/client/httplib/mock/mock_condition.go @@ -120,7 +120,6 @@ func (sc *SimpleCondition) matchBodyFields(ctx context.Context, req *httplib.Bee return false } - m := make(map[string]interface{}) err = json.Unmarshal(bytes, &m) diff --git a/client/httplib/mock/mock_test.go b/client/httplib/mock/mock_test.go index e73e8a6a..2972cf8f 100644 --- a/client/httplib/mock/mock_test.go +++ b/client/httplib/mock/mock_test.go @@ -72,6 +72,6 @@ func OriginnalCodeUsingHttplibPassCtx(ctx context.Context) (*http.Response, erro return httplib.Get("http://localhost:7777/abc").DoRequestWithCtx(ctx) } -func OriginalCodeUsingHttplib() (*http.Response, error){ +func OriginalCodeUsingHttplib() (*http.Response, error) { return httplib.Get("http://localhost:7777/abc").DoRequest() } diff --git a/client/httplib/setting.go b/client/httplib/setting.go index c8d049e0..d25fc4a9 100644 --- a/client/httplib/setting.go +++ b/client/httplib/setting.go @@ -78,4 +78,4 @@ func AddDefaultFilter(fc FilterChain) { defaultSetting.FilterChains = make([]FilterChain, 0, 4) } defaultSetting.FilterChains = append(defaultSetting.FilterChains, fc) -} \ No newline at end of file +} diff --git a/client/orm/clauses/const.go b/client/orm/clauses/const.go index 747d3fd7..38a6d556 100644 --- a/client/orm/clauses/const.go +++ b/client/orm/clauses/const.go @@ -1,6 +1,6 @@ package clauses const ( - ExprSep = "__" - ExprDot = "." + ExprSep = "__" + ExprDot = "." ) diff --git a/client/orm/clauses/order_clause/order.go b/client/orm/clauses/order_clause/order.go index e45c2f85..bdb2d1ca 100644 --- a/client/orm/clauses/order_clause/order.go +++ b/client/orm/clauses/order_clause/order.go @@ -1,8 +1,9 @@ package order_clause import ( - "github.com/beego/beego/v2/client/orm/clauses" "strings" + + "github.com/beego/beego/v2/client/orm/clauses" ) type Sort int8 diff --git a/client/orm/db_tables.go b/client/orm/db_tables.go index d62d8106..f81651ff 100644 --- a/client/orm/db_tables.go +++ b/client/orm/db_tables.go @@ -16,10 +16,11 @@ package orm import ( "fmt" - "github.com/beego/beego/v2/client/orm/clauses" - "github.com/beego/beego/v2/client/orm/clauses/order_clause" "strings" "time" + + "github.com/beego/beego/v2/client/orm/clauses" + "github.com/beego/beego/v2/client/orm/clauses/order_clause" ) // table info struct. diff --git a/client/orm/mock/condition.go b/client/orm/mock/condition.go index 486849d4..eda88824 100644 --- a/client/orm/mock/condition.go +++ b/client/orm/mock/condition.go @@ -23,14 +23,14 @@ import ( type Mock struct { cond Condition resp []interface{} - cb func(inv *orm.Invocation) + cb func(inv *orm.Invocation) } func NewMock(cond Condition, resp []interface{}, cb func(inv *orm.Invocation)) *Mock { return &Mock{ cond: cond, resp: resp, - cb: cb, + cb: cb, } } diff --git a/client/orm/mock/mock_orm_test.go b/client/orm/mock/mock_orm_test.go index d65855cb..1b321f01 100644 --- a/client/orm/mock/mock_orm_test.go +++ b/client/orm/mock/mock_orm_test.go @@ -24,7 +24,9 @@ import ( "github.com/beego/beego/v2/client/orm" ) + const mockErrorMsg = "mock error" + func init() { orm.RegisterModel(&User{}) } @@ -239,7 +241,7 @@ func TestTransactionRollback(t *testing.T) { assert.Equal(t, mock, err) } -func TestTransactionCommit(t *testing.T) { +func TestTransactionCommit(t *testing.T) { s := StartMock() defer s.Clear() mock := errors.New(mockErrorMsg) diff --git a/client/orm/mock/mock_queryM2Mer.go b/client/orm/mock/mock_queryM2Mer.go index 16648fee..a58f10ae 100644 --- a/client/orm/mock/mock_queryM2Mer.go +++ b/client/orm/mock/mock_queryM2Mer.go @@ -23,7 +23,6 @@ import ( // DoNothingQueryM2Mer do nothing // use it to build mock orm.QueryM2Mer type DoNothingQueryM2Mer struct { - } func (d *DoNothingQueryM2Mer) AddWithCtx(ctx context.Context, i ...interface{}) (int64, error) { @@ -68,13 +67,13 @@ func (d *DoNothingQueryM2Mer) Count() (int64, error) { type QueryM2MerCondition struct { tableName string - name string + name string } func NewQueryM2MerCondition(tableName string, name string) *QueryM2MerCondition { return &QueryM2MerCondition{ tableName: tableName, - name: name, + name: name, } } @@ -88,5 +87,3 @@ func (q *QueryM2MerCondition) Match(ctx context.Context, inv *orm.Invocation) bo } return res } - - diff --git a/client/orm/mock/mock_queryM2Mer_test.go b/client/orm/mock/mock_queryM2Mer_test.go index 82776e76..ef754092 100644 --- a/client/orm/mock/mock_queryM2Mer_test.go +++ b/client/orm/mock/mock_queryM2Mer_test.go @@ -60,4 +60,4 @@ func TestNewQueryM2MerCondition(t *testing.T) { assert.True(t, cond.Match(context.Background(), &orm.Invocation{ Args: []interface{}{0, "A"}, })) -} \ No newline at end of file +} diff --git a/client/orm/mock/mock_rawSetter.go b/client/orm/mock/mock_rawSetter.go index 016fde47..00311e80 100644 --- a/client/orm/mock/mock_rawSetter.go +++ b/client/orm/mock/mock_rawSetter.go @@ -61,4 +61,4 @@ func (d *DoNothingRawSetter) RowsToStruct(ptrStruct interface{}, keyCol, valueCo func (d *DoNothingRawSetter) Prepare() (orm.RawPreparer, error) { return nil, nil -} \ No newline at end of file +} diff --git a/client/orm/models.go b/client/orm/models.go index 0f07e24d..31cdc4a1 100644 --- a/client/orm/models.go +++ b/client/orm/models.go @@ -369,7 +369,7 @@ func (mc *_modelCache) register(prefixOrSuffixStr string, prefixOrSuffix bool, m } if _, ok := mc.get(table); ok { - return nil + return nil } mi := newModelInfo(val) diff --git a/client/orm/orm.go b/client/orm/orm.go index 660f2939..3f342868 100644 --- a/client/orm/orm.go +++ b/client/orm/orm.go @@ -58,11 +58,12 @@ import ( "database/sql" "errors" "fmt" - "github.com/beego/beego/v2/client/orm/clauses/order_clause" "os" "reflect" "time" + "github.com/beego/beego/v2/client/orm/clauses/order_clause" + "github.com/beego/beego/v2/client/orm/hints" "github.com/beego/beego/v2/core/utils" diff --git a/client/orm/orm_conds.go b/client/orm/orm_conds.go index 0080d53c..eeb5538a 100644 --- a/client/orm/orm_conds.go +++ b/client/orm/orm_conds.go @@ -16,8 +16,9 @@ package orm import ( "fmt" - "github.com/beego/beego/v2/client/orm/clauses" "strings" + + "github.com/beego/beego/v2/client/orm/clauses" ) // ExprSep define the expression separation diff --git a/client/orm/orm_test.go b/client/orm/orm_test.go index e2e25ac4..c9920f48 100644 --- a/client/orm/orm_test.go +++ b/client/orm/orm_test.go @@ -21,7 +21,6 @@ import ( "context" "database/sql" "fmt" - "github.com/beego/beego/v2/client/orm/clauses/order_clause" "io/ioutil" "math" "os" @@ -32,6 +31,8 @@ import ( "testing" "time" + "github.com/beego/beego/v2/client/orm/clauses/order_clause" + "github.com/beego/beego/v2/client/orm/hints" "github.com/stretchr/testify/assert" diff --git a/core/berror/codes.go b/core/berror/codes.go index e3a616e8..b6712a84 100644 --- a/core/berror/codes.go +++ b/core/berror/codes.go @@ -19,8 +19,6 @@ import ( "sync" ) - - // A Code is an unsigned 32-bit error code as defined in the beego spec. type Code interface { Code() uint32 @@ -38,9 +36,9 @@ var defaultCodeRegistry = &codeRegistry{ // desc could be markdown doc func DefineCode(code uint32, module string, name string, desc string) Code { res := &codeDefinition{ - code: code, + code: code, module: module, - desc: desc, + desc: desc, } defaultCodeRegistry.lock.Lock() defer defaultCodeRegistry.lock.Unlock() @@ -53,11 +51,10 @@ func DefineCode(code uint32, module string, name string, desc string) Code { } type codeRegistry struct { - lock sync.RWMutex + lock sync.RWMutex codes map[uint32]*codeDefinition } - func (cr *codeRegistry) Get(code uint32) (Code, bool) { cr.lock.RLock() defer cr.lock.RUnlock() @@ -66,13 +63,12 @@ func (cr *codeRegistry) Get(code uint32) (Code, bool) { } type codeDefinition struct { - code uint32 + code uint32 module string - desc string - name string + desc string + name string } - func (c *codeDefinition) Name() string { return c.name } @@ -88,4 +84,3 @@ func (c *codeDefinition) Module() string { func (c *codeDefinition) Desc() string { return c.desc } - diff --git a/core/berror/pre_define_code.go b/core/berror/pre_define_code.go index 01992957..275f86c1 100644 --- a/core/berror/pre_define_code.go +++ b/core/berror/pre_define_code.go @@ -21,7 +21,7 @@ import ( // pre define code // Unknown indicates got some error which is not defined -var Unknown = DefineCode(5000001, "error", "Unknown",fmt.Sprintf(` +var Unknown = DefineCode(5000001, "error", "Unknown", fmt.Sprintf(` Unknown error code. Usually you will see this code in three cases: 1. You forget to define Code or function DefineCode not being executed; 2. This is not Beego's error but you call FromError(); @@ -49,4 +49,3 @@ func goCodeBlock(code string) string { func codeBlock(lan string, code string) string { return fmt.Sprintf("```%s\n%s\n```", lan, code) } - diff --git a/server/web/context/context_test.go b/server/web/context/context_test.go index 977c3cbf..3915a853 100644 --- a/server/web/context/context_test.go +++ b/server/web/context/context_test.go @@ -15,10 +15,11 @@ package context import ( - "github.com/beego/beego/v2/server/web/session" "net/http" "net/http/httptest" "testing" + + "github.com/beego/beego/v2/server/web/session" ) func TestXsrfReset_01(t *testing.T) { @@ -68,4 +69,4 @@ func TestContext_Session2(t *testing.T) { if store, err := c.Session(); store == nil || err != nil { t.FailNow() } -} \ No newline at end of file +} diff --git a/server/web/filter/prometheus/filter_test.go b/server/web/filter/prometheus/filter_test.go index 7d88d843..618ce5af 100644 --- a/server/web/filter/prometheus/filter_test.go +++ b/server/web/filter/prometheus/filter_test.go @@ -53,4 +53,4 @@ func TestFilterChainBuilder_report(t *testing.T) { ctx.Input.SetData("RouterPattern", "my-route") report(time.Second, ctx, fb.buildVec()) -} \ No newline at end of file +} diff --git a/server/web/filter/session/filter.go b/server/web/filter/session/filter.go index bcf9edf4..b26e4d53 100644 --- a/server/web/filter/session/filter.go +++ b/server/web/filter/session/filter.go @@ -2,6 +2,7 @@ package session import ( "context" + "github.com/beego/beego/v2/core/logs" "github.com/beego/beego/v2/server/web" webContext "github.com/beego/beego/v2/server/web/context" @@ -32,4 +33,4 @@ func Session(providerType session.ProviderType, options ...session.ManagerConfig next(ctx) } } -} \ No newline at end of file +} diff --git a/server/web/filter/session/filter_test.go b/server/web/filter/session/filter_test.go index 687789a5..43046bf3 100644 --- a/server/web/filter/session/filter_test.go +++ b/server/web/filter/session/filter_test.go @@ -1,13 +1,14 @@ package session import ( + "net/http" + "net/http/httptest" + "testing" + "github.com/beego/beego/v2/server/web" webContext "github.com/beego/beego/v2/server/web/context" "github.com/beego/beego/v2/server/web/session" "github.com/google/uuid" - "net/http" - "net/http/httptest" - "testing" ) func testRequest(t *testing.T, handler *web.ControllerRegister, path string, method string, code int) { diff --git a/server/web/filter_chain_test.go b/server/web/filter_chain_test.go index 5dd38fc5..d76d8cbf 100644 --- a/server/web/filter_chain_test.go +++ b/server/web/filter_chain_test.go @@ -60,7 +60,6 @@ func TestControllerRegister_InsertFilterChain_Order(t *testing.T) { } }) - InsertFilterChain("/abc", func(next FilterFunc) FilterFunc { return func(ctx *context.Context) { ctx.Output.Header("second", fmt.Sprintf("%d", time.Now().UnixNano())) diff --git a/server/web/parser.go b/server/web/parser.go index 6d87207c..b3a8b42b 100644 --- a/server/web/parser.go +++ b/server/web/parser.go @@ -70,7 +70,7 @@ var ( } ) -const commentFilename = "commentsRouter.go" +const commentFilename = "commentsRouter.go" func init() { pkgLastupdate = make(map[string]int64) diff --git a/server/web/parser_test.go b/server/web/parser_test.go index 1f34d8d8..1dead882 100644 --- a/server/web/parser_test.go +++ b/server/web/parser_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" ) -func Test_getRouterDir(t *testing.T) { +func Test_getRouterDir(t *testing.T) { pkg := filepath.Dir(os.TempDir()) res := getRouterDir(pkg) diff --git a/server/web/session/session_config_test.go b/server/web/session/session_config_test.go index a596c5c6..0ea7d22b 100644 --- a/server/web/session/session_config_test.go +++ b/server/web/session/session_config_test.go @@ -219,4 +219,4 @@ func TestManagerConfig_Opts(t *testing.T) { if c.EnableSetCookie != true { t.Error() } -} \ No newline at end of file +} diff --git a/server/web/tree.go b/server/web/tree.go index 863d23ed..79f3da7a 100644 --- a/server/web/tree.go +++ b/server/web/tree.go @@ -342,7 +342,7 @@ func (t *Tree) match(treePattern string, pattern string, wildcardValues []string if runObject == nil && len(t.fixrouters) > 0 { // Filter the .json .xml .html extension for _, str := range allowSuffixExt { - if strings.HasSuffix(seg, str) && strings.HasSuffix(treePattern, seg){ + if strings.HasSuffix(seg, str) && strings.HasSuffix(treePattern, seg) { for _, subTree := range t.fixrouters { // strings.HasSuffix(treePattern, seg) avoid cases: /aaa.html/bbb could access /aaa/bbb if subTree.prefix == seg[:len(seg)-len(str)] {