diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ee7e0b5a..5035ae94 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,6 +23,26 @@ cp ./githook/pre-commit ./.git/hooks/pre-commit ``` This will add git hooks into .git/hooks. Or you can add it manually. +## Prepare middleware + +Beego uses many middlewares, including MySQL, Redis, SSDB and so on. + +We provide docker compose file to start all middlewares. + +You can run: +```shell script +docker-compose -f scripts/test_docker_compose.yml up -d +``` +Unit tests read addressed from environment, here is an example: +```shell script +export ORM_DRIVER=mysql +export ORM_SOURCE="beego:test@tcp(192.168.0.105:13306)/orm_test?charset=utf8" +export MEMCACHE_ADDR="192.168.0.105:11211" +export REDIS_ADDR="192.168.0.105:6379" +export SSDB_ADDR="192.168.0.105:8888" +``` + + ## Contribution guidelines ### Pull requests diff --git a/pkg/web/doc.go b/pkg/adapter/doc.go similarity index 87% rename from pkg/web/doc.go rename to pkg/adapter/doc.go index 1425a729..c8f2174c 100644 --- a/pkg/web/doc.go +++ b/pkg/adapter/doc.go @@ -1,4 +1,4 @@ -// Copyright 2020 beego +// Copyright 2020 // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,5 +12,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -// we will move all web related codes here -package web +// used to keep compatible with v1.x +package adapter diff --git a/pkg/cache/README.md b/pkg/client/cache/README.md similarity index 100% rename from pkg/cache/README.md rename to pkg/client/cache/README.md diff --git a/pkg/cache/cache.go b/pkg/client/cache/cache.go similarity index 100% rename from pkg/cache/cache.go rename to pkg/client/cache/cache.go diff --git a/pkg/cache/cache_test.go b/pkg/client/cache/cache_test.go similarity index 100% rename from pkg/cache/cache_test.go rename to pkg/client/cache/cache_test.go diff --git a/pkg/cache/conv.go b/pkg/client/cache/conv.go similarity index 100% rename from pkg/cache/conv.go rename to pkg/client/cache/conv.go diff --git a/pkg/cache/conv_test.go b/pkg/client/cache/conv_test.go similarity index 100% rename from pkg/cache/conv_test.go rename to pkg/client/cache/conv_test.go diff --git a/pkg/cache/file.go b/pkg/client/cache/file.go similarity index 100% rename from pkg/cache/file.go rename to pkg/client/cache/file.go diff --git a/pkg/cache/memcache/memcache.go b/pkg/client/cache/memcache/memcache.go similarity index 98% rename from pkg/cache/memcache/memcache.go rename to pkg/client/cache/memcache/memcache.go index 94fc61dc..60712c2f 100644 --- a/pkg/cache/memcache/memcache.go +++ b/pkg/client/cache/memcache/memcache.go @@ -37,7 +37,7 @@ import ( "github.com/bradfitz/gomemcache/memcache" - "github.com/astaxie/beego/pkg/cache" + "github.com/astaxie/beego/pkg/client/cache" ) // Cache Memcache adapter. diff --git a/pkg/cache/memcache/memcache_test.go b/pkg/client/cache/memcache/memcache_test.go similarity index 92% rename from pkg/cache/memcache/memcache_test.go rename to pkg/client/cache/memcache/memcache_test.go index b7dad8fc..df2ba37f 100644 --- a/pkg/cache/memcache/memcache_test.go +++ b/pkg/client/cache/memcache/memcache_test.go @@ -15,17 +15,26 @@ package memcache import ( + "fmt" + "os" + _ "github.com/bradfitz/gomemcache/memcache" "strconv" "testing" "time" - "github.com/astaxie/beego/pkg/cache" + "github.com/astaxie/beego/pkg/client/cache" ) func TestMemcacheCache(t *testing.T) { - bm, err := cache.NewCache("memcache", `{"conn": "127.0.0.1:11211"}`) + + addr := os.Getenv("MEMCACHE_ADDR") + if addr == "" { + addr = "127.0.0.1:11211" + } + + bm, err := cache.NewCache("memcache", fmt.Sprintf(`{"conn": "%s"}`, addr)) if err != nil { t.Error("init err") } diff --git a/pkg/cache/memory.go b/pkg/client/cache/memory.go similarity index 100% rename from pkg/cache/memory.go rename to pkg/client/cache/memory.go diff --git a/pkg/cache/redis/redis.go b/pkg/client/cache/redis/redis.go similarity index 99% rename from pkg/cache/redis/redis.go rename to pkg/client/cache/redis/redis.go index 68a934bf..2cd20503 100644 --- a/pkg/cache/redis/redis.go +++ b/pkg/client/cache/redis/redis.go @@ -39,7 +39,7 @@ import ( "github.com/gomodule/redigo/redis" - "github.com/astaxie/beego/pkg/cache" + "github.com/astaxie/beego/pkg/client/cache" ) var ( diff --git a/pkg/cache/redis/redis_test.go b/pkg/client/cache/redis/redis_test.go similarity index 88% rename from pkg/cache/redis/redis_test.go rename to pkg/client/cache/redis/redis_test.go index 8de331ab..00206157 100644 --- a/pkg/cache/redis/redis_test.go +++ b/pkg/client/cache/redis/redis_test.go @@ -16,17 +16,24 @@ package redis import ( "fmt" + "os" "testing" "time" "github.com/gomodule/redigo/redis" "github.com/stretchr/testify/assert" - "github.com/astaxie/beego/pkg/cache" + "github.com/astaxie/beego/pkg/client/cache" ) func TestRedisCache(t *testing.T) { - bm, err := cache.NewCache("redis", `{"conn": "127.0.0.1:6379"}`) + + redisAddr := os.Getenv("REDIS_ADDR") + if redisAddr == "" { + redisAddr = "127.0.0.1:6379" + } + + bm, err := cache.NewCache("redis", fmt.Sprintf(`{"conn": "%s"}`, redisAddr)) if err != nil { t.Error("init err") } @@ -110,8 +117,14 @@ func TestRedisCache(t *testing.T) { func TestCache_Scan(t *testing.T) { timeoutDuration := 10 * time.Second + + addr := os.Getenv("REDIS_ADDR") + if addr == "" { + addr = "127.0.0.1:6379" + } + // init - bm, err := cache.NewCache("redis", `{"conn": "127.0.0.1:6379"}`) + bm, err := cache.NewCache("redis", fmt.Sprintf(`{"conn": "%s"}`, addr)) if err != nil { t.Error("init err") } @@ -121,6 +134,7 @@ func TestCache_Scan(t *testing.T) { t.Error("set Error", err) } } + time.Sleep(time.Second) // scan all for the first time keys, err := bm.(*Cache).Scan(DefaultKey + ":*") if err != nil { diff --git a/pkg/cache/ssdb/ssdb.go b/pkg/client/cache/ssdb/ssdb.go similarity index 99% rename from pkg/cache/ssdb/ssdb.go rename to pkg/client/cache/ssdb/ssdb.go index 038b2ebe..10ff72b0 100644 --- a/pkg/cache/ssdb/ssdb.go +++ b/pkg/client/cache/ssdb/ssdb.go @@ -9,7 +9,7 @@ import ( "github.com/ssdb/gossdb/ssdb" - "github.com/astaxie/beego/pkg/cache" + "github.com/astaxie/beego/pkg/client/cache" ) // Cache SSDB adapter diff --git a/pkg/cache/ssdb/ssdb_test.go b/pkg/client/cache/ssdb/ssdb_test.go similarity index 90% rename from pkg/cache/ssdb/ssdb_test.go rename to pkg/client/cache/ssdb/ssdb_test.go index 7390ea94..bd6ede4e 100644 --- a/pkg/cache/ssdb/ssdb_test.go +++ b/pkg/client/cache/ssdb/ssdb_test.go @@ -1,15 +1,23 @@ package ssdb import ( + "fmt" + "os" "strconv" "testing" "time" - "github.com/astaxie/beego/pkg/cache" + "github.com/astaxie/beego/pkg/client/cache" ) func TestSsdbcacheCache(t *testing.T) { - ssdb, err := cache.NewCache("ssdb", `{"conn": "127.0.0.1:8888"}`) + + ssdbAddr := os.Getenv("SSDB_ADDR") + if ssdbAddr == "" { + ssdbAddr = "127.0.0.1:8888" + } + + ssdb, err := cache.NewCache("ssdb", fmt.Sprintf(`{"conn": "%s"}`, ssdbAddr)) if err != nil { t.Error("init err") } diff --git a/pkg/httplib/README.md b/pkg/client/httplib/README.md similarity index 100% rename from pkg/httplib/README.md rename to pkg/client/httplib/README.md diff --git a/pkg/httplib/filter.go b/pkg/client/httplib/filter.go similarity index 100% rename from pkg/httplib/filter.go rename to pkg/client/httplib/filter.go diff --git a/pkg/httplib/filter/opentracing/filter.go b/pkg/client/httplib/filter/opentracing/filter.go similarity index 98% rename from pkg/httplib/filter/opentracing/filter.go rename to pkg/client/httplib/filter/opentracing/filter.go index 6cc4d6b0..93376843 100644 --- a/pkg/httplib/filter/opentracing/filter.go +++ b/pkg/client/httplib/filter/opentracing/filter.go @@ -18,7 +18,7 @@ import ( "context" "net/http" - "github.com/astaxie/beego/pkg/httplib" + "github.com/astaxie/beego/pkg/client/httplib" logKit "github.com/go-kit/kit/log" opentracingKit "github.com/go-kit/kit/tracing/opentracing" "github.com/opentracing/opentracing-go" diff --git a/pkg/httplib/filter/opentracing/filter_test.go b/pkg/client/httplib/filter/opentracing/filter_test.go similarity index 96% rename from pkg/httplib/filter/opentracing/filter_test.go rename to pkg/client/httplib/filter/opentracing/filter_test.go index 8849a9ad..46937803 100644 --- a/pkg/httplib/filter/opentracing/filter_test.go +++ b/pkg/client/httplib/filter/opentracing/filter_test.go @@ -23,7 +23,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/astaxie/beego/pkg/httplib" + "github.com/astaxie/beego/pkg/client/httplib" ) func TestFilterChainBuilder_FilterChain(t *testing.T) { diff --git a/pkg/httplib/filter/prometheus/filter.go b/pkg/client/httplib/filter/prometheus/filter.go similarity index 91% rename from pkg/httplib/filter/prometheus/filter.go rename to pkg/client/httplib/filter/prometheus/filter.go index e7f7316f..917d4720 100644 --- a/pkg/httplib/filter/prometheus/filter.go +++ b/pkg/client/httplib/filter/prometheus/filter.go @@ -22,8 +22,8 @@ import ( "github.com/prometheus/client_golang/prometheus" - beego "github.com/astaxie/beego/pkg" - "github.com/astaxie/beego/pkg/httplib" + "github.com/astaxie/beego/pkg/client/httplib" + "github.com/astaxie/beego/pkg/server/web" ) type FilterChainBuilder struct { @@ -36,9 +36,9 @@ func (builder *FilterChainBuilder) FilterChain(next httplib.Filter) httplib.Filt Name: "beego", Subsystem: "remote_http_request", ConstLabels: map[string]string{ - "server": beego.BConfig.ServerName, - "env": beego.BConfig.RunMode, - "appname": beego.BConfig.AppName, + "server": web.BConfig.ServerName, + "env": web.BConfig.RunMode, + "appname": web.BConfig.AppName, }, Help: "The statics info for remote http requests", }, []string{"proto", "scheme", "method", "host", "path", "status", "duration", "isError"}) diff --git a/pkg/httplib/filter/prometheus/filter_test.go b/pkg/client/httplib/filter/prometheus/filter_test.go similarity index 96% rename from pkg/httplib/filter/prometheus/filter_test.go rename to pkg/client/httplib/filter/prometheus/filter_test.go index 2964e6c5..2964a4a2 100644 --- a/pkg/httplib/filter/prometheus/filter_test.go +++ b/pkg/client/httplib/filter/prometheus/filter_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/astaxie/beego/pkg/httplib" + "github.com/astaxie/beego/pkg/client/httplib" ) func TestFilterChainBuilder_FilterChain(t *testing.T) { diff --git a/pkg/httplib/httplib.go b/pkg/client/httplib/httplib.go similarity index 100% rename from pkg/httplib/httplib.go rename to pkg/client/httplib/httplib.go diff --git a/pkg/httplib/httplib_test.go b/pkg/client/httplib/httplib_test.go similarity index 100% rename from pkg/httplib/httplib_test.go rename to pkg/client/httplib/httplib_test.go diff --git a/pkg/testing/client.go b/pkg/client/httplib/testing/client.go similarity index 94% rename from pkg/testing/client.go rename to pkg/client/httplib/testing/client.go index 0062b857..19e6cd23 100644 --- a/pkg/testing/client.go +++ b/pkg/client/httplib/testing/client.go @@ -15,8 +15,9 @@ package testing import ( - "github.com/astaxie/beego/pkg/config" - "github.com/astaxie/beego/pkg/httplib" + "github.com/astaxie/beego/pkg/client/httplib" + + "github.com/astaxie/beego/pkg/infrastructure/config" ) var port = "" diff --git a/pkg/orm/README.md b/pkg/client/orm/README.md similarity index 100% rename from pkg/orm/README.md rename to pkg/client/orm/README.md diff --git a/pkg/orm/cmd.go b/pkg/client/orm/cmd.go similarity index 100% rename from pkg/orm/cmd.go rename to pkg/client/orm/cmd.go diff --git a/pkg/orm/cmd_utils.go b/pkg/client/orm/cmd_utils.go similarity index 100% rename from pkg/orm/cmd_utils.go rename to pkg/client/orm/cmd_utils.go diff --git a/pkg/orm/db.go b/pkg/client/orm/db.go similarity index 99% rename from pkg/orm/db.go rename to pkg/client/orm/db.go index 905c8189..5905325d 100644 --- a/pkg/orm/db.go +++ b/pkg/client/orm/db.go @@ -22,7 +22,7 @@ import ( "strings" "time" - "github.com/astaxie/beego/pkg/orm/hints" + "github.com/astaxie/beego/pkg/client/orm/hints" ) const ( diff --git a/pkg/orm/db_alias.go b/pkg/client/orm/db_alias.go similarity index 98% rename from pkg/orm/db_alias.go rename to pkg/client/orm/db_alias.go index 0a53ad31..8a5cfb10 100644 --- a/pkg/orm/db_alias.go +++ b/pkg/client/orm/db_alias.go @@ -21,11 +21,10 @@ import ( "sync" "time" - "github.com/astaxie/beego/pkg/orm/hints" + "github.com/astaxie/beego/pkg/client/orm/hints" + "github.com/astaxie/beego/pkg/infrastructure/utils" lru "github.com/hashicorp/golang-lru" - - "github.com/astaxie/beego/pkg/common" ) // DriverType database driver constant int. @@ -341,7 +340,7 @@ func detectTZ(al *alias) { } } -func addAliasWthDB(aliasName, driverName string, db *sql.DB, params ...common.KV) (*alias, error) { +func addAliasWthDB(aliasName, driverName string, db *sql.DB, params ...utils.KV) (*alias, error) { existErr := fmt.Errorf("DataBase alias name `%s` already registered, cannot reuse", aliasName) if _, ok := dataBaseCache.get(aliasName); ok { return nil, existErr @@ -359,8 +358,8 @@ func addAliasWthDB(aliasName, driverName string, db *sql.DB, params ...common.KV return al, nil } -func newAliasWithDb(aliasName, driverName string, db *sql.DB, params ...common.KV) (*alias, error) { - kvs := common.NewKVs(params...) +func newAliasWithDb(aliasName, driverName string, db *sql.DB, params ...utils.KV) (*alias, error) { + kvs := utils.NewKVs(params...) var stmtCache *lru.Cache var stmtCacheSize int @@ -418,13 +417,13 @@ func newAliasWithDb(aliasName, driverName string, db *sql.DB, params ...common.K } // AddAliasWthDB add a aliasName for the drivename -func AddAliasWthDB(aliasName, driverName string, db *sql.DB, params ...common.KV) error { +func AddAliasWthDB(aliasName, driverName string, db *sql.DB, params ...utils.KV) error { _, err := addAliasWthDB(aliasName, driverName, db, params...) return err } // RegisterDataBase Setting the database connect params. Use the database driver self dataSource args. -func RegisterDataBase(aliasName, driverName, dataSource string, params ...common.KV) error { +func RegisterDataBase(aliasName, driverName, dataSource string, params ...utils.KV) error { var ( err error db *sql.DB diff --git a/pkg/orm/db_alias_test.go b/pkg/client/orm/db_alias_test.go similarity index 98% rename from pkg/orm/db_alias_test.go rename to pkg/client/orm/db_alias_test.go index 4a561a27..0043ba76 100644 --- a/pkg/orm/db_alias_test.go +++ b/pkg/client/orm/db_alias_test.go @@ -18,7 +18,7 @@ import ( "testing" "time" - "github.com/astaxie/beego/pkg/orm/hints" + "github.com/astaxie/beego/pkg/client/orm/hints" "github.com/stretchr/testify/assert" ) diff --git a/pkg/orm/db_mysql.go b/pkg/client/orm/db_mysql.go similarity index 100% rename from pkg/orm/db_mysql.go rename to pkg/client/orm/db_mysql.go diff --git a/pkg/orm/db_oracle.go b/pkg/client/orm/db_oracle.go similarity index 98% rename from pkg/orm/db_oracle.go rename to pkg/client/orm/db_oracle.go index 66246ec4..d8d8c6c1 100644 --- a/pkg/orm/db_oracle.go +++ b/pkg/client/orm/db_oracle.go @@ -18,7 +18,7 @@ import ( "fmt" "strings" - "github.com/astaxie/beego/pkg/orm/hints" + "github.com/astaxie/beego/pkg/client/orm/hints" ) // oracle operators. diff --git a/pkg/orm/db_postgres.go b/pkg/client/orm/db_postgres.go similarity index 100% rename from pkg/orm/db_postgres.go rename to pkg/client/orm/db_postgres.go diff --git a/pkg/orm/db_sqlite.go b/pkg/client/orm/db_sqlite.go similarity index 99% rename from pkg/orm/db_sqlite.go rename to pkg/client/orm/db_sqlite.go index f9d379ce..8cb936be 100644 --- a/pkg/orm/db_sqlite.go +++ b/pkg/client/orm/db_sqlite.go @@ -21,7 +21,7 @@ import ( "strings" "time" - "github.com/astaxie/beego/pkg/orm/hints" + "github.com/astaxie/beego/pkg/client/orm/hints" ) // sqlite operators. diff --git a/pkg/orm/db_tables.go b/pkg/client/orm/db_tables.go similarity index 100% rename from pkg/orm/db_tables.go rename to pkg/client/orm/db_tables.go diff --git a/pkg/orm/db_tidb.go b/pkg/client/orm/db_tidb.go similarity index 100% rename from pkg/orm/db_tidb.go rename to pkg/client/orm/db_tidb.go diff --git a/pkg/orm/db_utils.go b/pkg/client/orm/db_utils.go similarity index 100% rename from pkg/orm/db_utils.go rename to pkg/client/orm/db_utils.go diff --git a/pkg/orm/do_nothing_orm.go b/pkg/client/orm/do_nothing_orm.go similarity index 96% rename from pkg/orm/do_nothing_orm.go rename to pkg/client/orm/do_nothing_orm.go index afc428f2..e27e7f3a 100644 --- a/pkg/orm/do_nothing_orm.go +++ b/pkg/client/orm/do_nothing_orm.go @@ -18,7 +18,7 @@ import ( "context" "database/sql" - "github.com/astaxie/beego/pkg/common" + "github.com/astaxie/beego/pkg/infrastructure/utils" ) // DoNothingOrm won't do anything, usually you use this to custom your mock Ormer implementation @@ -54,11 +54,11 @@ func (d *DoNothingOrm) ReadOrCreateWithCtx(ctx context.Context, md interface{}, return false, 0, nil } -func (d *DoNothingOrm) LoadRelated(md interface{}, name string, args ...common.KV) (int64, error) { +func (d *DoNothingOrm) LoadRelated(md interface{}, name string, args ...utils.KV) (int64, error) { return 0, nil } -func (d *DoNothingOrm) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...common.KV) (int64, error) { +func (d *DoNothingOrm) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...utils.KV) (int64, error) { return 0, nil } diff --git a/pkg/orm/do_nothing_orm_test.go b/pkg/client/orm/do_nothing_orm_test.go similarity index 100% rename from pkg/orm/do_nothing_orm_test.go rename to pkg/client/orm/do_nothing_orm_test.go diff --git a/pkg/orm/filter.go b/pkg/client/orm/filter.go similarity index 100% rename from pkg/orm/filter.go rename to pkg/client/orm/filter.go diff --git a/pkg/orm/filter/bean/default_value_filter.go b/pkg/client/orm/filter/bean/default_value_filter.go similarity index 96% rename from pkg/orm/filter/bean/default_value_filter.go rename to pkg/client/orm/filter/bean/default_value_filter.go index b3ef7415..a367a6e2 100644 --- a/pkg/orm/filter/bean/default_value_filter.go +++ b/pkg/client/orm/filter/bean/default_value_filter.go @@ -19,9 +19,10 @@ import ( "reflect" "strings" - "github.com/astaxie/beego/pkg/bean" - "github.com/astaxie/beego/pkg/logs" - "github.com/astaxie/beego/pkg/orm" + "github.com/astaxie/beego/pkg/infrastructure/logs" + + "github.com/astaxie/beego/pkg/client/orm" + "github.com/astaxie/beego/pkg/infrastructure/bean" ) // DefaultValueFilterChainBuilder only works for InsertXXX method, diff --git a/pkg/orm/filter/bean/default_value_filter_test.go b/pkg/client/orm/filter/bean/default_value_filter_test.go similarity index 97% rename from pkg/orm/filter/bean/default_value_filter_test.go rename to pkg/client/orm/filter/bean/default_value_filter_test.go index 2c754a3e..fde7abf8 100644 --- a/pkg/orm/filter/bean/default_value_filter_test.go +++ b/pkg/client/orm/filter/bean/default_value_filter_test.go @@ -19,7 +19,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/astaxie/beego/pkg/orm" + "github.com/astaxie/beego/pkg/client/orm" ) func TestDefaultValueFilterChainBuilder_FilterChain(t *testing.T) { diff --git a/pkg/orm/filter/opentracing/filter.go b/pkg/client/orm/filter/opentracing/filter.go similarity index 98% rename from pkg/orm/filter/opentracing/filter.go rename to pkg/client/orm/filter/opentracing/filter.go index 0b6968b7..1a2ee541 100644 --- a/pkg/orm/filter/opentracing/filter.go +++ b/pkg/client/orm/filter/opentracing/filter.go @@ -20,7 +20,7 @@ import ( "github.com/opentracing/opentracing-go" - "github.com/astaxie/beego/pkg/orm" + "github.com/astaxie/beego/pkg/client/orm" ) // FilterChainBuilder provides an extension point diff --git a/pkg/orm/filter/opentracing/filter_test.go b/pkg/client/orm/filter/opentracing/filter_test.go similarity index 96% rename from pkg/orm/filter/opentracing/filter_test.go rename to pkg/client/orm/filter/opentracing/filter_test.go index 8f6d4807..9e89e5da 100644 --- a/pkg/orm/filter/opentracing/filter_test.go +++ b/pkg/client/orm/filter/opentracing/filter_test.go @@ -21,7 +21,7 @@ import ( "github.com/opentracing/opentracing-go" - "github.com/astaxie/beego/pkg/orm" + "github.com/astaxie/beego/pkg/client/orm" ) func TestFilterChainBuilder_FilterChain(t *testing.T) { diff --git a/pkg/orm/filter/prometheus/filter.go b/pkg/client/orm/filter/prometheus/filter.go similarity index 93% rename from pkg/orm/filter/prometheus/filter.go rename to pkg/client/orm/filter/prometheus/filter.go index fb2b473d..175b26be 100644 --- a/pkg/orm/filter/prometheus/filter.go +++ b/pkg/client/orm/filter/prometheus/filter.go @@ -22,8 +22,8 @@ import ( "github.com/prometheus/client_golang/prometheus" - beego "github.com/astaxie/beego/pkg" - "github.com/astaxie/beego/pkg/orm" + "github.com/astaxie/beego/pkg/client/orm" + "github.com/astaxie/beego/pkg/server/web" ) // FilterChainBuilder is an extension point, @@ -42,9 +42,9 @@ func NewFilterChainBuilder() *FilterChainBuilder { Name: "beego", Subsystem: "orm_operation", ConstLabels: map[string]string{ - "server": beego.BConfig.ServerName, - "env": beego.BConfig.RunMode, - "appname": beego.BConfig.AppName, + "server": web.BConfig.ServerName, + "env": web.BConfig.RunMode, + "appname": web.BConfig.AppName, }, Help: "The statics info for orm operation", }, []string{"method", "name", "duration", "insideTx", "txName"}) diff --git a/pkg/orm/filter/prometheus/filter_test.go b/pkg/client/orm/filter/prometheus/filter_test.go similarity index 97% rename from pkg/orm/filter/prometheus/filter_test.go rename to pkg/client/orm/filter/prometheus/filter_test.go index aad62c18..1b55b989 100644 --- a/pkg/orm/filter/prometheus/filter_test.go +++ b/pkg/client/orm/filter/prometheus/filter_test.go @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/astaxie/beego/pkg/orm" + "github.com/astaxie/beego/pkg/client/orm" ) func TestFilterChainBuilder_FilterChain(t *testing.T) { diff --git a/pkg/orm/filter_orm_decorator.go b/pkg/client/orm/filter_orm_decorator.go similarity index 98% rename from pkg/orm/filter_orm_decorator.go rename to pkg/client/orm/filter_orm_decorator.go index 97221a07..d0c5c537 100644 --- a/pkg/orm/filter_orm_decorator.go +++ b/pkg/client/orm/filter_orm_decorator.go @@ -20,7 +20,7 @@ import ( "reflect" "time" - "github.com/astaxie/beego/pkg/common" + "github.com/astaxie/beego/pkg/infrastructure/utils" ) const ( @@ -137,11 +137,11 @@ func (f *filterOrmDecorator) ReadOrCreateWithCtx(ctx context.Context, md interfa return res[0].(bool), res[1].(int64), f.convertError(res[2]) } -func (f *filterOrmDecorator) LoadRelated(md interface{}, name string, args ...common.KV) (int64, error) { +func (f *filterOrmDecorator) LoadRelated(md interface{}, name string, args ...utils.KV) (int64, error) { return f.LoadRelatedWithCtx(context.Background(), md, name, args...) } -func (f *filterOrmDecorator) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...common.KV) (int64, error) { +func (f *filterOrmDecorator) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...utils.KV) (int64, error) { mi, _ := modelCache.getByMd(md) inv := &Invocation{ diff --git a/pkg/orm/filter_orm_decorator_test.go b/pkg/client/orm/filter_orm_decorator_test.go similarity index 99% rename from pkg/orm/filter_orm_decorator_test.go rename to pkg/client/orm/filter_orm_decorator_test.go index 47f20854..7acb7d46 100644 --- a/pkg/orm/filter_orm_decorator_test.go +++ b/pkg/client/orm/filter_orm_decorator_test.go @@ -21,7 +21,7 @@ import ( "sync" "testing" - "github.com/astaxie/beego/pkg/common" + "github.com/astaxie/beego/pkg/infrastructure/utils" "github.com/stretchr/testify/assert" ) @@ -362,7 +362,7 @@ func (f *filterMockOrm) ReadForUpdateWithCtx(ctx context.Context, md interface{} return errors.New("read for update error") } -func (f *filterMockOrm) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...common.KV) (int64, error) { +func (f *filterMockOrm) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...utils.KV) (int64, error) { return 99, errors.New("load related error") } diff --git a/pkg/orm/filter_test.go b/pkg/client/orm/filter_test.go similarity index 100% rename from pkg/orm/filter_test.go rename to pkg/client/orm/filter_test.go diff --git a/pkg/orm/hints/db_hints.go b/pkg/client/orm/hints/db_hints.go similarity index 96% rename from pkg/orm/hints/db_hints.go rename to pkg/client/orm/hints/db_hints.go index 0649ab9f..4d199312 100644 --- a/pkg/orm/hints/db_hints.go +++ b/pkg/client/orm/hints/db_hints.go @@ -17,7 +17,7 @@ package hints import ( "time" - "github.com/astaxie/beego/pkg/common" + "github.com/astaxie/beego/pkg/infrastructure/utils" ) const ( @@ -43,7 +43,7 @@ type Hint struct { value interface{} } -var _ common.KV = new(Hint) +var _ utils.KV = new(Hint) // GetKey return key func (s *Hint) GetKey() interface{} { @@ -55,7 +55,7 @@ func (s *Hint) GetValue() interface{} { return s.value } -var _ common.KV = new(Hint) +var _ utils.KV = new(Hint) // MaxIdleConnections return a hint about MaxIdleConnections func MaxIdleConnections(v int) *Hint { diff --git a/pkg/orm/hints/db_hints_test.go b/pkg/client/orm/hints/db_hints_test.go similarity index 100% rename from pkg/orm/hints/db_hints_test.go rename to pkg/client/orm/hints/db_hints_test.go diff --git a/pkg/orm/invocation.go b/pkg/client/orm/invocation.go similarity index 100% rename from pkg/orm/invocation.go rename to pkg/client/orm/invocation.go diff --git a/pkg/migration/ddl.go b/pkg/client/orm/migration/ddl.go similarity index 99% rename from pkg/migration/ddl.go rename to pkg/client/orm/migration/ddl.go index b6d3a2d9..c21352a8 100644 --- a/pkg/migration/ddl.go +++ b/pkg/client/orm/migration/ddl.go @@ -17,7 +17,7 @@ package migration import ( "fmt" - "github.com/astaxie/beego/pkg/logs" + "github.com/astaxie/beego/pkg/infrastructure/logs" ) // Index struct defines the structure of Index Columns diff --git a/pkg/migration/doc.go b/pkg/client/orm/migration/doc.go similarity index 100% rename from pkg/migration/doc.go rename to pkg/client/orm/migration/doc.go diff --git a/pkg/migration/migration.go b/pkg/client/orm/migration/migration.go similarity index 98% rename from pkg/migration/migration.go rename to pkg/client/orm/migration/migration.go index c62fd901..3f740594 100644 --- a/pkg/migration/migration.go +++ b/pkg/client/orm/migration/migration.go @@ -33,8 +33,8 @@ import ( "strings" "time" - "github.com/astaxie/beego/pkg/logs" - "github.com/astaxie/beego/pkg/orm" + "github.com/astaxie/beego/pkg/client/orm" + "github.com/astaxie/beego/pkg/infrastructure/logs" ) // const the data format for the bee generate migration datatype diff --git a/pkg/orm/model_utils_test.go b/pkg/client/orm/model_utils_test.go similarity index 100% rename from pkg/orm/model_utils_test.go rename to pkg/client/orm/model_utils_test.go diff --git a/pkg/orm/models.go b/pkg/client/orm/models.go similarity index 100% rename from pkg/orm/models.go rename to pkg/client/orm/models.go diff --git a/pkg/orm/models_boot.go b/pkg/client/orm/models_boot.go similarity index 100% rename from pkg/orm/models_boot.go rename to pkg/client/orm/models_boot.go diff --git a/pkg/orm/models_fields.go b/pkg/client/orm/models_fields.go similarity index 100% rename from pkg/orm/models_fields.go rename to pkg/client/orm/models_fields.go diff --git a/pkg/orm/models_info_f.go b/pkg/client/orm/models_info_f.go similarity index 100% rename from pkg/orm/models_info_f.go rename to pkg/client/orm/models_info_f.go diff --git a/pkg/orm/models_info_m.go b/pkg/client/orm/models_info_m.go similarity index 100% rename from pkg/orm/models_info_m.go rename to pkg/client/orm/models_info_m.go diff --git a/pkg/orm/models_test.go b/pkg/client/orm/models_test.go similarity index 97% rename from pkg/orm/models_test.go rename to pkg/client/orm/models_test.go index 8fcd2e06..8a60c36b 100644 --- a/pkg/orm/models_test.go +++ b/pkg/client/orm/models_test.go @@ -22,7 +22,7 @@ import ( "strings" "time" - "github.com/astaxie/beego/pkg/orm/hints" + "github.com/astaxie/beego/pkg/client/orm/hints" _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" @@ -303,7 +303,7 @@ type Post struct { Content string `orm:"type(text)"` Created time.Time `orm:"auto_now_add"` Updated time.Time `orm:"auto_now"` - Tags []*Tag `orm:"rel(m2m);rel_through(github.com/astaxie/beego/pkg/orm.PostTags)"` + Tags []*Tag `orm:"rel(m2m);rel_through(github.com/astaxie/beego/pkg/client/orm.PostTags)"` } func (u *Post) TableIndex() [][]string { @@ -361,7 +361,7 @@ type Group struct { type Permission struct { ID int `orm:"column(id)"` Name string - Groups []*Group `orm:"rel(m2m);rel_through(github.com/astaxie/beego/pkg/orm.GroupPermissions)"` + Groups []*Group `orm:"rel(m2m);rel_through(github.com/astaxie/beego/pkg/client/orm.GroupPermissions)"` } type GroupPermissions struct { @@ -470,7 +470,7 @@ var ( usage: - go get -u github.com/astaxie/beego/pkg/orm + go get -u github.com/astaxie/beego/pkg/client/orm go get -u github.com/go-sql-driver/mysql go get -u github.com/mattn/go-sqlite3 go get -u github.com/lib/pq @@ -480,20 +480,20 @@ var ( mysql -u root -e 'create database orm_test;' export ORM_DRIVER=mysql export ORM_SOURCE="root:@/orm_test?charset=utf8" - go test -v github.com/astaxie/beego/pkg/orm + go test -v github.com/astaxie/beego/pkg/client/orm #### Sqlite3 export ORM_DRIVER=sqlite3 export ORM_SOURCE='file:memory_test?mode=memory' - go test -v github.com/astaxie/beego/pkg/orm + go test -v github.com/astaxie/beego/pkg/client/orm #### PostgreSQL psql -c 'create database orm_test;' -U postgres export ORM_DRIVER=postgres export ORM_SOURCE="user=postgres dbname=orm_test sslmode=disable" - go test -v github.com/astaxie/beego/pkg/orm + go test -v github.com/astaxie/beego/pkg/client/orm #### TiDB export ORM_DRIVER=tidb diff --git a/pkg/orm/models_utils.go b/pkg/client/orm/models_utils.go similarity index 100% rename from pkg/orm/models_utils.go rename to pkg/client/orm/models_utils.go diff --git a/pkg/orm/orm.go b/pkg/client/orm/orm.go similarity index 97% rename from pkg/orm/orm.go rename to pkg/client/orm/orm.go index d7dc3915..634b1892 100644 --- a/pkg/orm/orm.go +++ b/pkg/client/orm/orm.go @@ -21,7 +21,7 @@ // // import ( // "fmt" -// "github.com/astaxie/beego/pkg/orm" +// "github.com/astaxie/beego/pkg/client/orm" // _ "github.com/go-sql-driver/mysql" // import your used driver // ) // @@ -62,10 +62,10 @@ import ( "reflect" "time" - "github.com/astaxie/beego/pkg/common" - "github.com/astaxie/beego/pkg/orm/hints" + "github.com/astaxie/beego/pkg/client/orm/hints" + "github.com/astaxie/beego/pkg/infrastructure/utils" - "github.com/astaxie/beego/pkg/logs" + "github.com/astaxie/beego/pkg/infrastructure/logs" ) // DebugQueries define the debug @@ -307,10 +307,10 @@ func (o *ormBase) QueryM2MWithCtx(ctx context.Context, md interface{}, name stri // for _,tag := range post.Tags{...} // // make sure the relation is defined in model struct tags. -func (o *ormBase) LoadRelated(md interface{}, name string, args ...common.KV) (int64, error) { +func (o *ormBase) LoadRelated(md interface{}, name string, args ...utils.KV) (int64, error) { return o.LoadRelatedWithCtx(context.Background(), md, name, args...) } -func (o *ormBase) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...common.KV) (int64, error) { +func (o *ormBase) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...utils.KV) (int64, error) { _, fi, ind, qseter := o.queryRelated(md, name) qs := qseter.(*querySet) @@ -319,7 +319,7 @@ func (o *ormBase) LoadRelatedWithCtx(ctx context.Context, md interface{}, name s var limit, offset int64 var order string - kvs := common.NewKVs(args...) + kvs := utils.NewKVs(args...) kvs.IfContains(hints.KeyRelDepth, func(value interface{}) { if v, ok := value.(bool); ok { if v { @@ -603,7 +603,7 @@ func NewOrmUsingDB(aliasName string) Ormer { } // NewOrmWithDB create a new ormer object with specify *sql.DB for query -func NewOrmWithDB(driverName, aliasName string, db *sql.DB, params ...common.KV) (Ormer, error) { +func NewOrmWithDB(driverName, aliasName string, db *sql.DB, params ...utils.KV) (Ormer, error) { al, err := newAliasWithDb(aliasName, driverName, db, params...) if err != nil { return nil, err diff --git a/pkg/orm/orm_conds.go b/pkg/client/orm/orm_conds.go similarity index 100% rename from pkg/orm/orm_conds.go rename to pkg/client/orm/orm_conds.go diff --git a/pkg/orm/orm_log.go b/pkg/client/orm/orm_log.go similarity index 100% rename from pkg/orm/orm_log.go rename to pkg/client/orm/orm_log.go diff --git a/pkg/orm/orm_object.go b/pkg/client/orm/orm_object.go similarity index 100% rename from pkg/orm/orm_object.go rename to pkg/client/orm/orm_object.go diff --git a/pkg/orm/orm_querym2m.go b/pkg/client/orm/orm_querym2m.go similarity index 100% rename from pkg/orm/orm_querym2m.go rename to pkg/client/orm/orm_querym2m.go diff --git a/pkg/orm/orm_queryset.go b/pkg/client/orm/orm_queryset.go similarity index 99% rename from pkg/orm/orm_queryset.go rename to pkg/client/orm/orm_queryset.go index 3a50fcae..906505de 100644 --- a/pkg/orm/orm_queryset.go +++ b/pkg/client/orm/orm_queryset.go @@ -18,7 +18,7 @@ import ( "context" "fmt" - "github.com/astaxie/beego/pkg/orm/hints" + "github.com/astaxie/beego/pkg/client/orm/hints" ) type colValue struct { diff --git a/pkg/orm/orm_raw.go b/pkg/client/orm/orm_raw.go similarity index 96% rename from pkg/orm/orm_raw.go rename to pkg/client/orm/orm_raw.go index 92410eb2..c2539147 100644 --- a/pkg/orm/orm_raw.go +++ b/pkg/client/orm/orm_raw.go @@ -383,19 +383,33 @@ func (o *rawSet) QueryRow(containers ...interface{}) error { } } } else { - for i := 0; i < ind.NumField(); i++ { - f := ind.Field(i) - fe := ind.Type().Field(i) - _, tags := parseStructTag(fe.Tag.Get(defaultStructTagName)) - var col string - if col = tags["column"]; col == "" { - col = nameStrategyMap[nameStrategy](fe.Name) - } - if v, ok := columnsMp[col]; ok { - value := reflect.ValueOf(v).Elem().Interface() - o.setFieldValue(f, value) + // define recursive function + var recursiveSetField func(rv reflect.Value) + recursiveSetField = func(rv reflect.Value) { + for i := 0; i < rv.NumField(); i++ { + f := rv.Field(i) + fe := rv.Type().Field(i) + + // check if the field is a Struct + // recursive the Struct type + if fe.Type.Kind() == reflect.Struct { + recursiveSetField(f) + } + + _, tags := parseStructTag(fe.Tag.Get(defaultStructTagName)) + var col string + if col = tags["column"]; col == "" { + col = nameStrategyMap[nameStrategy](fe.Name) + } + if v, ok := columnsMp[col]; ok { + value := reflect.ValueOf(v).Elem().Interface() + o.setFieldValue(f, value) + } } } + + // init call the recursive function + recursiveSetField(ind) } } else { diff --git a/pkg/orm/orm_test.go b/pkg/client/orm/orm_test.go similarity index 99% rename from pkg/orm/orm_test.go rename to pkg/client/orm/orm_test.go index cbe5c9a1..92374e02 100644 --- a/pkg/orm/orm_test.go +++ b/pkg/client/orm/orm_test.go @@ -31,7 +31,7 @@ import ( "testing" "time" - "github.com/astaxie/beego/pkg/orm/hints" + "github.com/astaxie/beego/pkg/client/orm/hints" "github.com/stretchr/testify/assert" ) @@ -1742,6 +1742,24 @@ func TestRawQueryRow(t *testing.T) { throwFail(t, AssertIs(*status, 3)) throwFail(t, AssertIs(pid, nil)) + type Embeded struct { + Email string + } + type queryRowNoModelTest struct { + Id int + EmbedField Embeded + } + + cols = []string{ + "id", "email", + } + var row queryRowNoModelTest + query = fmt.Sprintf("SELECT %s%s%s FROM %suser%s WHERE id = ?", Q, strings.Join(cols, sep), Q, Q, Q) + err = dORM.Raw(query, 4).QueryRow(&row) + throwFail(t, err) + throwFail(t, AssertIs(row.Id, 4)) + throwFail(t, AssertIs(row.EmbedField.Email, "nobody@gmail.com")) + // test for sql.Null* fields nData := &DataNull{ NullString: sql.NullString{String: "test sql.null", Valid: true}, diff --git a/pkg/orm/qb.go b/pkg/client/orm/qb.go similarity index 100% rename from pkg/orm/qb.go rename to pkg/client/orm/qb.go diff --git a/pkg/orm/qb_mysql.go b/pkg/client/orm/qb_mysql.go similarity index 100% rename from pkg/orm/qb_mysql.go rename to pkg/client/orm/qb_mysql.go diff --git a/pkg/orm/qb_tidb.go b/pkg/client/orm/qb_tidb.go similarity index 100% rename from pkg/orm/qb_tidb.go rename to pkg/client/orm/qb_tidb.go diff --git a/pkg/orm/types.go b/pkg/client/orm/types.go similarity index 99% rename from pkg/orm/types.go rename to pkg/client/orm/types.go index 06ba12f2..eb34e759 100644 --- a/pkg/orm/types.go +++ b/pkg/client/orm/types.go @@ -20,7 +20,7 @@ import ( "reflect" "time" - "github.com/astaxie/beego/pkg/common" + "github.com/astaxie/beego/pkg/infrastructure/utils" ) // TableNaming is usually used by model @@ -183,8 +183,8 @@ type DQL interface { // hints.Offset int offset default offset 0 // hints.OrderBy string order for example : "-Id" // make sure the relation is defined in model struct tags. - LoadRelated(md interface{}, name string, args ...common.KV) (int64, error) - LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...common.KV) (int64, error) + LoadRelated(md interface{}, name string, args ...utils.KV) (int64, error) + LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...utils.KV) (int64, error) // create a models to models queryer // for example: diff --git a/pkg/orm/utils.go b/pkg/client/orm/utils.go similarity index 100% rename from pkg/orm/utils.go rename to pkg/client/orm/utils.go diff --git a/pkg/orm/utils_test.go b/pkg/client/orm/utils_test.go similarity index 100% rename from pkg/orm/utils_test.go rename to pkg/client/orm/utils_test.go diff --git a/pkg/doc.go b/pkg/doc.go index a1cdbbb0..2e4378c8 100644 --- a/pkg/doc.go +++ b/pkg/doc.go @@ -1,17 +1,15 @@ -/* -Package beego provide a MVC framework -beego: an open-source, high-performance, modular, full-stack web framework +// Copyright 2020 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. -It is used for rapid development of RESTful APIs, web apps and backend services in Go. -beego is inspired by Tornado, Sinatra and Flask with the added benefit of some Go-specific features such as interfaces and struct embedding. - - package main - import "github.com/astaxie/beego/pkg" - - func main() { - beego.Run() - } - -more information: http://beego.me -*/ -package beego +package pkg diff --git a/pkg/bean/context.go b/pkg/infrastructure/bean/context.go similarity index 100% rename from pkg/bean/context.go rename to pkg/infrastructure/bean/context.go diff --git a/pkg/bean/doc.go b/pkg/infrastructure/bean/doc.go similarity index 100% rename from pkg/bean/doc.go rename to pkg/infrastructure/bean/doc.go diff --git a/pkg/bean/factory.go b/pkg/infrastructure/bean/factory.go similarity index 100% rename from pkg/bean/factory.go rename to pkg/infrastructure/bean/factory.go diff --git a/pkg/bean/metadata.go b/pkg/infrastructure/bean/metadata.go similarity index 100% rename from pkg/bean/metadata.go rename to pkg/infrastructure/bean/metadata.go diff --git a/pkg/bean/tag_auto_wire_bean_factory.go b/pkg/infrastructure/bean/tag_auto_wire_bean_factory.go similarity index 99% rename from pkg/bean/tag_auto_wire_bean_factory.go rename to pkg/infrastructure/bean/tag_auto_wire_bean_factory.go index 569ffb0d..f80388f9 100644 --- a/pkg/bean/tag_auto_wire_bean_factory.go +++ b/pkg/infrastructure/bean/tag_auto_wire_bean_factory.go @@ -22,7 +22,7 @@ import ( "github.com/pkg/errors" - "github.com/astaxie/beego/pkg/logs" + "github.com/astaxie/beego/pkg/infrastructure/logs" ) const DefaultValueTagKey = "default" diff --git a/pkg/bean/tag_auto_wire_bean_factory_test.go b/pkg/infrastructure/bean/tag_auto_wire_bean_factory_test.go similarity index 100% rename from pkg/bean/tag_auto_wire_bean_factory_test.go rename to pkg/infrastructure/bean/tag_auto_wire_bean_factory_test.go diff --git a/pkg/bean/time_type_adapter.go b/pkg/infrastructure/bean/time_type_adapter.go similarity index 100% rename from pkg/bean/time_type_adapter.go rename to pkg/infrastructure/bean/time_type_adapter.go diff --git a/pkg/bean/time_type_adapter_test.go b/pkg/infrastructure/bean/time_type_adapter_test.go similarity index 100% rename from pkg/bean/time_type_adapter_test.go rename to pkg/infrastructure/bean/time_type_adapter_test.go diff --git a/pkg/bean/type_adapter.go b/pkg/infrastructure/bean/type_adapter.go similarity index 100% rename from pkg/bean/type_adapter.go rename to pkg/infrastructure/bean/type_adapter.go diff --git a/pkg/config/base_config_test.go b/pkg/infrastructure/config/base_config_test.go similarity index 100% rename from pkg/config/base_config_test.go rename to pkg/infrastructure/config/base_config_test.go diff --git a/pkg/config/config.go b/pkg/infrastructure/config/config.go similarity index 100% rename from pkg/config/config.go rename to pkg/infrastructure/config/config.go diff --git a/pkg/config/config_test.go b/pkg/infrastructure/config/config_test.go similarity index 100% rename from pkg/config/config_test.go rename to pkg/infrastructure/config/config_test.go diff --git a/pkg/config/env/env.go b/pkg/infrastructure/config/env/env.go similarity index 97% rename from pkg/config/env/env.go rename to pkg/infrastructure/config/env/env.go index 5d8e47de..83155b34 100644 --- a/pkg/config/env/env.go +++ b/pkg/infrastructure/config/env/env.go @@ -21,7 +21,7 @@ import ( "os" "strings" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/utils" ) var env *utils.BeeMap diff --git a/pkg/config/env/env_test.go b/pkg/infrastructure/config/env/env_test.go similarity index 100% rename from pkg/config/env/env_test.go rename to pkg/infrastructure/config/env/env_test.go diff --git a/pkg/config/fake.go b/pkg/infrastructure/config/fake.go similarity index 100% rename from pkg/config/fake.go rename to pkg/infrastructure/config/fake.go diff --git a/pkg/config/ini.go b/pkg/infrastructure/config/ini.go similarity index 100% rename from pkg/config/ini.go rename to pkg/infrastructure/config/ini.go diff --git a/pkg/config/ini_test.go b/pkg/infrastructure/config/ini_test.go similarity index 100% rename from pkg/config/ini_test.go rename to pkg/infrastructure/config/ini_test.go diff --git a/pkg/config/json/json.go b/pkg/infrastructure/config/json/json.go similarity index 99% rename from pkg/config/json/json.go rename to pkg/infrastructure/config/json/json.go index 876077e1..bd28411f 100644 --- a/pkg/config/json/json.go +++ b/pkg/infrastructure/config/json/json.go @@ -24,7 +24,7 @@ import ( "strings" "sync" - "github.com/astaxie/beego/pkg/config" + "github.com/astaxie/beego/pkg/infrastructure/config" ) // JSONConfig is a json config parser and implements Config interface. diff --git a/pkg/config/json/json_test.go b/pkg/infrastructure/config/json/json_test.go similarity index 99% rename from pkg/config/json/json_test.go rename to pkg/infrastructure/config/json/json_test.go index da87986f..75a42145 100644 --- a/pkg/config/json/json_test.go +++ b/pkg/infrastructure/config/json/json_test.go @@ -19,7 +19,7 @@ import ( "os" "testing" - "github.com/astaxie/beego/pkg/config" + "github.com/astaxie/beego/pkg/infrastructure/config" ) func TestJsonStartsWithArray(t *testing.T) { diff --git a/pkg/config/xml/xml.go b/pkg/infrastructure/config/xml/xml.go similarity index 99% rename from pkg/config/xml/xml.go rename to pkg/infrastructure/config/xml/xml.go index 9b5ec791..3413e0a5 100644 --- a/pkg/config/xml/xml.go +++ b/pkg/infrastructure/config/xml/xml.go @@ -39,7 +39,7 @@ import ( "strings" "sync" - "github.com/astaxie/beego/pkg/config" + "github.com/astaxie/beego/pkg/infrastructure/config" "github.com/beego/x2j" ) diff --git a/pkg/config/xml/xml_test.go b/pkg/infrastructure/config/xml/xml_test.go similarity index 98% rename from pkg/config/xml/xml_test.go rename to pkg/infrastructure/config/xml/xml_test.go index b7828933..4cd0df1f 100644 --- a/pkg/config/xml/xml_test.go +++ b/pkg/infrastructure/config/xml/xml_test.go @@ -19,7 +19,7 @@ import ( "os" "testing" - "github.com/astaxie/beego/pkg/config" + "github.com/astaxie/beego/pkg/infrastructure/config" ) func TestXML(t *testing.T) { diff --git a/pkg/config/yaml/yaml.go b/pkg/infrastructure/config/yaml/yaml.go similarity index 99% rename from pkg/config/yaml/yaml.go rename to pkg/infrastructure/config/yaml/yaml.go index 5c77e88f..9a3b698a 100644 --- a/pkg/config/yaml/yaml.go +++ b/pkg/infrastructure/config/yaml/yaml.go @@ -40,7 +40,7 @@ import ( "strings" "sync" - "github.com/astaxie/beego/pkg/config" + "github.com/astaxie/beego/pkg/infrastructure/config" "github.com/beego/goyaml2" ) diff --git a/pkg/config/yaml/yaml_test.go b/pkg/infrastructure/config/yaml/yaml_test.go similarity index 97% rename from pkg/config/yaml/yaml_test.go rename to pkg/infrastructure/config/yaml/yaml_test.go index 0e76457f..2437d6c7 100644 --- a/pkg/config/yaml/yaml_test.go +++ b/pkg/infrastructure/config/yaml/yaml_test.go @@ -19,7 +19,7 @@ import ( "os" "testing" - "github.com/astaxie/beego/pkg/config" + "github.com/astaxie/beego/pkg/infrastructure/config" ) func TestYaml(t *testing.T) { diff --git a/pkg/toolbox/healthcheck.go b/pkg/infrastructure/governor/healthcheck.go similarity index 96% rename from pkg/toolbox/healthcheck.go rename to pkg/infrastructure/governor/healthcheck.go index e3544b3a..a91f09fa 100644 --- a/pkg/toolbox/healthcheck.go +++ b/pkg/infrastructure/governor/healthcheck.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package toolbox healthcheck +// Package governor healthcheck // // type DatabaseCheck struct { // } @@ -28,7 +28,7 @@ // AddHealthCheck("database",&DatabaseCheck{}) // // more docs: http://beego.me/docs/module/toolbox.md -package toolbox +package governor // AdminCheckList holds health checker map var AdminCheckList map[string]HealthChecker diff --git a/pkg/toolbox/profile.go b/pkg/infrastructure/governor/profile.go similarity index 82% rename from pkg/toolbox/profile.go rename to pkg/infrastructure/governor/profile.go index 06e40ede..c40cf6ba 100644 --- a/pkg/toolbox/profile.go +++ b/pkg/infrastructure/governor/profile.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package toolbox +package governor import ( "fmt" @@ -25,6 +25,8 @@ import ( "runtime/pprof" "strconv" "time" + + "github.com/astaxie/beego/pkg/infrastructure/utils" ) var startTime = time.Now() @@ -112,15 +114,15 @@ func printGC(memStats *runtime.MemStats, gcstats *debug.GCStats, w io.Writer) { fmt.Fprintf(w, "NumGC:%d Pause:%s Pause(Avg):%s Overhead:%3.2f%% Alloc:%s Sys:%s Alloc(Rate):%s/s Histogram:%s %s %s \n", gcstats.NumGC, - toS(lastPause), - toS(avg(gcstats.Pause)), + utils.ToShortTimeFormat(lastPause), + utils.ToShortTimeFormat(avg(gcstats.Pause)), overhead, toH(memStats.Alloc), toH(memStats.Sys), toH(uint64(allocatedRate)), - toS(gcstats.PauseQuantiles[94]), - toS(gcstats.PauseQuantiles[98]), - toS(gcstats.PauseQuantiles[99])) + utils.ToShortTimeFormat(gcstats.PauseQuantiles[94]), + utils.ToShortTimeFormat(gcstats.PauseQuantiles[98]), + utils.ToShortTimeFormat(gcstats.PauseQuantiles[99])) } else { // while GC has disabled elapsed := time.Now().Sub(startTime) @@ -154,31 +156,3 @@ func toH(bytes uint64) string { return fmt.Sprintf("%.2fG", float64(bytes)/1024/1024/1024) } } - -// short string format -func toS(d time.Duration) string { - - u := uint64(d) - if u < uint64(time.Second) { - switch { - case u == 0: - return "0" - case u < uint64(time.Microsecond): - return fmt.Sprintf("%.2fns", float64(u)) - case u < uint64(time.Millisecond): - return fmt.Sprintf("%.2fus", float64(u)/1000) - default: - return fmt.Sprintf("%.2fms", float64(u)/1000/1000) - } - } else { - switch { - case u < uint64(time.Minute): - return fmt.Sprintf("%.2fs", float64(u)/1000/1000/1000) - case u < uint64(time.Hour): - return fmt.Sprintf("%.2fm", float64(u)/1000/1000/1000/60) - default: - return fmt.Sprintf("%.2fh", float64(u)/1000/1000/1000/60/60) - } - } - -} diff --git a/pkg/toolbox/profile_test.go b/pkg/infrastructure/governor/profile_test.go similarity index 98% rename from pkg/toolbox/profile_test.go rename to pkg/infrastructure/governor/profile_test.go index 07a20c4e..530b0637 100644 --- a/pkg/toolbox/profile_test.go +++ b/pkg/infrastructure/governor/profile_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package toolbox +package governor import ( "os" diff --git a/pkg/logs/README.md b/pkg/infrastructure/logs/README.md similarity index 100% rename from pkg/logs/README.md rename to pkg/infrastructure/logs/README.md diff --git a/pkg/logs/accesslog.go b/pkg/infrastructure/logs/accesslog.go similarity index 100% rename from pkg/logs/accesslog.go rename to pkg/infrastructure/logs/accesslog.go diff --git a/pkg/logs/alils/alils.go b/pkg/infrastructure/logs/alils/alils.go similarity index 98% rename from pkg/logs/alils/alils.go rename to pkg/infrastructure/logs/alils/alils.go index 6c1464f2..02e6f995 100644 --- a/pkg/logs/alils/alils.go +++ b/pkg/infrastructure/logs/alils/alils.go @@ -5,7 +5,7 @@ import ( "strings" "sync" - "github.com/astaxie/beego/pkg/logs" + "github.com/astaxie/beego/pkg/infrastructure/logs" "github.com/gogo/protobuf/proto" ) diff --git a/pkg/logs/alils/config.go b/pkg/infrastructure/logs/alils/config.go similarity index 100% rename from pkg/logs/alils/config.go rename to pkg/infrastructure/logs/alils/config.go diff --git a/pkg/logs/alils/log.pb.go b/pkg/infrastructure/logs/alils/log.pb.go similarity index 100% rename from pkg/logs/alils/log.pb.go rename to pkg/infrastructure/logs/alils/log.pb.go diff --git a/pkg/logs/alils/log_config.go b/pkg/infrastructure/logs/alils/log_config.go similarity index 100% rename from pkg/logs/alils/log_config.go rename to pkg/infrastructure/logs/alils/log_config.go diff --git a/pkg/logs/alils/log_project.go b/pkg/infrastructure/logs/alils/log_project.go similarity index 100% rename from pkg/logs/alils/log_project.go rename to pkg/infrastructure/logs/alils/log_project.go diff --git a/pkg/logs/alils/log_store.go b/pkg/infrastructure/logs/alils/log_store.go similarity index 100% rename from pkg/logs/alils/log_store.go rename to pkg/infrastructure/logs/alils/log_store.go diff --git a/pkg/logs/alils/machine_group.go b/pkg/infrastructure/logs/alils/machine_group.go similarity index 100% rename from pkg/logs/alils/machine_group.go rename to pkg/infrastructure/logs/alils/machine_group.go diff --git a/pkg/logs/alils/request.go b/pkg/infrastructure/logs/alils/request.go similarity index 100% rename from pkg/logs/alils/request.go rename to pkg/infrastructure/logs/alils/request.go diff --git a/pkg/logs/alils/signature.go b/pkg/infrastructure/logs/alils/signature.go similarity index 100% rename from pkg/logs/alils/signature.go rename to pkg/infrastructure/logs/alils/signature.go diff --git a/pkg/logs/conn.go b/pkg/infrastructure/logs/conn.go similarity index 100% rename from pkg/logs/conn.go rename to pkg/infrastructure/logs/conn.go diff --git a/pkg/logs/conn_test.go b/pkg/infrastructure/logs/conn_test.go similarity index 100% rename from pkg/logs/conn_test.go rename to pkg/infrastructure/logs/conn_test.go diff --git a/pkg/logs/console.go b/pkg/infrastructure/logs/console.go similarity index 100% rename from pkg/logs/console.go rename to pkg/infrastructure/logs/console.go diff --git a/pkg/logs/console_test.go b/pkg/infrastructure/logs/console_test.go similarity index 100% rename from pkg/logs/console_test.go rename to pkg/infrastructure/logs/console_test.go diff --git a/pkg/logs/es/es.go b/pkg/infrastructure/logs/es/es.go similarity index 97% rename from pkg/logs/es/es.go rename to pkg/infrastructure/logs/es/es.go index 5c91b2ed..c2631584 100644 --- a/pkg/logs/es/es.go +++ b/pkg/infrastructure/logs/es/es.go @@ -12,7 +12,7 @@ import ( "github.com/elastic/go-elasticsearch/v6" "github.com/elastic/go-elasticsearch/v6/esapi" - "github.com/astaxie/beego/pkg/logs" + "github.com/astaxie/beego/pkg/infrastructure/logs" ) // NewES returns a LoggerInterface diff --git a/pkg/logs/file.go b/pkg/infrastructure/logs/file.go similarity index 100% rename from pkg/logs/file.go rename to pkg/infrastructure/logs/file.go diff --git a/pkg/logs/file_test.go b/pkg/infrastructure/logs/file_test.go similarity index 100% rename from pkg/logs/file_test.go rename to pkg/infrastructure/logs/file_test.go diff --git a/pkg/logs/jianliao.go b/pkg/infrastructure/logs/jianliao.go similarity index 100% rename from pkg/logs/jianliao.go rename to pkg/infrastructure/logs/jianliao.go diff --git a/pkg/logs/log.go b/pkg/infrastructure/logs/log.go similarity index 100% rename from pkg/logs/log.go rename to pkg/infrastructure/logs/log.go diff --git a/pkg/logs/logger.go b/pkg/infrastructure/logs/logger.go similarity index 100% rename from pkg/logs/logger.go rename to pkg/infrastructure/logs/logger.go diff --git a/pkg/logs/logger_test.go b/pkg/infrastructure/logs/logger_test.go similarity index 100% rename from pkg/logs/logger_test.go rename to pkg/infrastructure/logs/logger_test.go diff --git a/pkg/logs/multifile.go b/pkg/infrastructure/logs/multifile.go similarity index 100% rename from pkg/logs/multifile.go rename to pkg/infrastructure/logs/multifile.go diff --git a/pkg/logs/multifile_test.go b/pkg/infrastructure/logs/multifile_test.go similarity index 100% rename from pkg/logs/multifile_test.go rename to pkg/infrastructure/logs/multifile_test.go diff --git a/pkg/logs/slack.go b/pkg/infrastructure/logs/slack.go similarity index 100% rename from pkg/logs/slack.go rename to pkg/infrastructure/logs/slack.go diff --git a/pkg/logs/smtp.go b/pkg/infrastructure/logs/smtp.go similarity index 100% rename from pkg/logs/smtp.go rename to pkg/infrastructure/logs/smtp.go diff --git a/pkg/logs/smtp_test.go b/pkg/infrastructure/logs/smtp_test.go similarity index 100% rename from pkg/logs/smtp_test.go rename to pkg/infrastructure/logs/smtp_test.go diff --git a/pkg/session/README.md b/pkg/infrastructure/session/README.md similarity index 100% rename from pkg/session/README.md rename to pkg/infrastructure/session/README.md diff --git a/pkg/session/couchbase/sess_couchbase.go b/pkg/infrastructure/session/couchbase/sess_couchbase.go similarity index 99% rename from pkg/session/couchbase/sess_couchbase.go rename to pkg/infrastructure/session/couchbase/sess_couchbase.go index b824a938..378cfc9f 100644 --- a/pkg/session/couchbase/sess_couchbase.go +++ b/pkg/infrastructure/session/couchbase/sess_couchbase.go @@ -39,7 +39,7 @@ import ( couchbase "github.com/couchbase/go-couchbase" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" ) var couchbpder = &Provider{} diff --git a/pkg/session/ledis/ledis_session.go b/pkg/infrastructure/session/ledis/ledis_session.go similarity index 98% rename from pkg/session/ledis/ledis_session.go rename to pkg/infrastructure/session/ledis/ledis_session.go index e43d70a0..96e6efa3 100644 --- a/pkg/session/ledis/ledis_session.go +++ b/pkg/infrastructure/session/ledis/ledis_session.go @@ -10,7 +10,7 @@ import ( "github.com/ledisdb/ledisdb/config" "github.com/ledisdb/ledisdb/ledis" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" ) var ( diff --git a/pkg/session/memcache/sess_memcache.go b/pkg/infrastructure/session/memcache/sess_memcache.go similarity index 99% rename from pkg/session/memcache/sess_memcache.go rename to pkg/infrastructure/session/memcache/sess_memcache.go index 7fab842a..0758c43f 100644 --- a/pkg/session/memcache/sess_memcache.go +++ b/pkg/infrastructure/session/memcache/sess_memcache.go @@ -37,7 +37,7 @@ import ( "strings" "sync" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" "github.com/bradfitz/gomemcache/memcache" ) diff --git a/pkg/session/mysql/sess_mysql.go b/pkg/infrastructure/session/mysql/sess_mysql.go similarity index 99% rename from pkg/session/mysql/sess_mysql.go rename to pkg/infrastructure/session/mysql/sess_mysql.go index c641a4bf..2dadd317 100644 --- a/pkg/session/mysql/sess_mysql.go +++ b/pkg/infrastructure/session/mysql/sess_mysql.go @@ -46,7 +46,7 @@ import ( "sync" "time" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" // import mysql driver _ "github.com/go-sql-driver/mysql" ) diff --git a/pkg/session/postgres/sess_postgresql.go b/pkg/infrastructure/session/postgres/sess_postgresql.go similarity index 99% rename from pkg/session/postgres/sess_postgresql.go rename to pkg/infrastructure/session/postgres/sess_postgresql.go index 688c0e36..adcf647b 100644 --- a/pkg/session/postgres/sess_postgresql.go +++ b/pkg/infrastructure/session/postgres/sess_postgresql.go @@ -56,7 +56,7 @@ import ( "sync" "time" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" // import postgresql Driver _ "github.com/lib/pq" ) diff --git a/pkg/session/redis/sess_redis.go b/pkg/infrastructure/session/redis/sess_redis.go similarity index 99% rename from pkg/session/redis/sess_redis.go rename to pkg/infrastructure/session/redis/sess_redis.go index b68ee012..e775102c 100644 --- a/pkg/session/redis/sess_redis.go +++ b/pkg/infrastructure/session/redis/sess_redis.go @@ -39,7 +39,7 @@ import ( "sync" "time" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" "github.com/go-redis/redis/v7" ) diff --git a/pkg/session/redis/sess_redis_test.go b/pkg/infrastructure/session/redis/sess_redis_test.go similarity index 88% rename from pkg/session/redis/sess_redis_test.go rename to pkg/infrastructure/session/redis/sess_redis_test.go index db5bb2c7..ef466eab 100644 --- a/pkg/session/redis/sess_redis_test.go +++ b/pkg/infrastructure/session/redis/sess_redis_test.go @@ -1,11 +1,13 @@ package redis import ( + "fmt" "net/http" "net/http/httptest" + "os" "testing" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" ) func TestRedis(t *testing.T) { @@ -16,8 +18,14 @@ func TestRedis(t *testing.T) { Maxlifetime: 3600, Secure: false, CookieLifeTime: 3600, - ProviderConfig: "127.0.0.1:6379,100,,0,30", } + + redisAddr := os.Getenv("REDIS_ADDR") + if redisAddr == "" { + redisAddr = "127.0.0.1:6379" + } + + sessionConfig.ProviderConfig = fmt.Sprintf("%s,100,,0,30", redisAddr) globalSession, err := session.NewManager("redis", sessionConfig) if err != nil { t.Fatal("could not create manager:", err) diff --git a/pkg/session/redis_cluster/redis_cluster.go b/pkg/infrastructure/session/redis_cluster/redis_cluster.go similarity index 99% rename from pkg/session/redis_cluster/redis_cluster.go rename to pkg/infrastructure/session/redis_cluster/redis_cluster.go index dcdfae85..40487d76 100644 --- a/pkg/session/redis_cluster/redis_cluster.go +++ b/pkg/infrastructure/session/redis_cluster/redis_cluster.go @@ -39,7 +39,7 @@ import ( "sync" "time" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" rediss "github.com/go-redis/redis/v7" ) diff --git a/pkg/session/redis_sentinel/sess_redis_sentinel.go b/pkg/infrastructure/session/redis_sentinel/sess_redis_sentinel.go similarity index 99% rename from pkg/session/redis_sentinel/sess_redis_sentinel.go rename to pkg/infrastructure/session/redis_sentinel/sess_redis_sentinel.go index 6721539a..1f6ebaa7 100644 --- a/pkg/session/redis_sentinel/sess_redis_sentinel.go +++ b/pkg/infrastructure/session/redis_sentinel/sess_redis_sentinel.go @@ -39,7 +39,7 @@ import ( "sync" "time" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" "github.com/go-redis/redis/v7" ) diff --git a/pkg/session/redis_sentinel/sess_redis_sentinel_test.go b/pkg/infrastructure/session/redis_sentinel/sess_redis_sentinel_test.go similarity index 97% rename from pkg/session/redis_sentinel/sess_redis_sentinel_test.go rename to pkg/infrastructure/session/redis_sentinel/sess_redis_sentinel_test.go index bd31741f..0dc3520a 100644 --- a/pkg/session/redis_sentinel/sess_redis_sentinel_test.go +++ b/pkg/infrastructure/session/redis_sentinel/sess_redis_sentinel_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "testing" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" ) func TestRedisSentinel(t *testing.T) { diff --git a/pkg/session/sess_cookie.go b/pkg/infrastructure/session/sess_cookie.go similarity index 100% rename from pkg/session/sess_cookie.go rename to pkg/infrastructure/session/sess_cookie.go diff --git a/pkg/session/sess_cookie_test.go b/pkg/infrastructure/session/sess_cookie_test.go similarity index 100% rename from pkg/session/sess_cookie_test.go rename to pkg/infrastructure/session/sess_cookie_test.go diff --git a/pkg/session/sess_file.go b/pkg/infrastructure/session/sess_file.go similarity index 100% rename from pkg/session/sess_file.go rename to pkg/infrastructure/session/sess_file.go diff --git a/pkg/session/sess_file_test.go b/pkg/infrastructure/session/sess_file_test.go similarity index 100% rename from pkg/session/sess_file_test.go rename to pkg/infrastructure/session/sess_file_test.go diff --git a/pkg/session/sess_mem.go b/pkg/infrastructure/session/sess_mem.go similarity index 100% rename from pkg/session/sess_mem.go rename to pkg/infrastructure/session/sess_mem.go diff --git a/pkg/session/sess_mem_test.go b/pkg/infrastructure/session/sess_mem_test.go similarity index 100% rename from pkg/session/sess_mem_test.go rename to pkg/infrastructure/session/sess_mem_test.go diff --git a/pkg/session/sess_test.go b/pkg/infrastructure/session/sess_test.go similarity index 100% rename from pkg/session/sess_test.go rename to pkg/infrastructure/session/sess_test.go diff --git a/pkg/session/sess_utils.go b/pkg/infrastructure/session/sess_utils.go similarity index 99% rename from pkg/session/sess_utils.go rename to pkg/infrastructure/session/sess_utils.go index 5b70afa8..906e1c4b 100644 --- a/pkg/session/sess_utils.go +++ b/pkg/infrastructure/session/sess_utils.go @@ -29,7 +29,7 @@ import ( "strconv" "time" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/utils" ) func init() { diff --git a/pkg/session/session.go b/pkg/infrastructure/session/session.go similarity index 100% rename from pkg/session/session.go rename to pkg/infrastructure/session/session.go diff --git a/pkg/session/ssdb/sess_ssdb.go b/pkg/infrastructure/session/ssdb/sess_ssdb.go similarity index 98% rename from pkg/session/ssdb/sess_ssdb.go rename to pkg/infrastructure/session/ssdb/sess_ssdb.go index f950b835..77d0c5c2 100644 --- a/pkg/session/ssdb/sess_ssdb.go +++ b/pkg/infrastructure/session/ssdb/sess_ssdb.go @@ -7,7 +7,7 @@ import ( "strings" "sync" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" "github.com/ssdb/gossdb/ssdb" ) diff --git a/pkg/utils/caller.go b/pkg/infrastructure/utils/caller.go similarity index 100% rename from pkg/utils/caller.go rename to pkg/infrastructure/utils/caller.go diff --git a/pkg/utils/caller_test.go b/pkg/infrastructure/utils/caller_test.go similarity index 100% rename from pkg/utils/caller_test.go rename to pkg/infrastructure/utils/caller_test.go diff --git a/pkg/utils/debug.go b/pkg/infrastructure/utils/debug.go similarity index 100% rename from pkg/utils/debug.go rename to pkg/infrastructure/utils/debug.go diff --git a/pkg/utils/debug_test.go b/pkg/infrastructure/utils/debug_test.go similarity index 100% rename from pkg/utils/debug_test.go rename to pkg/infrastructure/utils/debug_test.go diff --git a/pkg/utils/file.go b/pkg/infrastructure/utils/file.go similarity index 100% rename from pkg/utils/file.go rename to pkg/infrastructure/utils/file.go diff --git a/pkg/utils/file_test.go b/pkg/infrastructure/utils/file_test.go similarity index 100% rename from pkg/utils/file_test.go rename to pkg/infrastructure/utils/file_test.go diff --git a/pkg/common/kv.go b/pkg/infrastructure/utils/kv.go similarity index 99% rename from pkg/common/kv.go rename to pkg/infrastructure/utils/kv.go index 80797aa9..f4e6c4d4 100644 --- a/pkg/common/kv.go +++ b/pkg/infrastructure/utils/kv.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package common +package utils type KV interface { GetKey() interface{} diff --git a/pkg/common/kv_test.go b/pkg/infrastructure/utils/kv_test.go similarity index 98% rename from pkg/common/kv_test.go rename to pkg/infrastructure/utils/kv_test.go index 7b52a300..4c9643dc 100644 --- a/pkg/common/kv_test.go +++ b/pkg/infrastructure/utils/kv_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package common +package utils import ( "testing" diff --git a/pkg/utils/mail.go b/pkg/infrastructure/utils/mail.go similarity index 100% rename from pkg/utils/mail.go rename to pkg/infrastructure/utils/mail.go diff --git a/pkg/utils/mail_test.go b/pkg/infrastructure/utils/mail_test.go similarity index 100% rename from pkg/utils/mail_test.go rename to pkg/infrastructure/utils/mail_test.go diff --git a/pkg/utils/pagination/doc.go b/pkg/infrastructure/utils/pagination/doc.go similarity index 95% rename from pkg/utils/pagination/doc.go rename to pkg/infrastructure/utils/pagination/doc.go index 718f5e7a..86a2ba5d 100644 --- a/pkg/utils/pagination/doc.go +++ b/pkg/infrastructure/utils/pagination/doc.go @@ -8,7 +8,7 @@ In your beego.Controller: package controllers - import "github.com/astaxie/beego/pkg/utils/pagination" + import "github.com/astaxie/beego/pkg/infrastructure/utils/pagination" type PostsController struct { beego.Controller diff --git a/pkg/utils/pagination/paginator.go b/pkg/infrastructure/utils/pagination/paginator.go similarity index 100% rename from pkg/utils/pagination/paginator.go rename to pkg/infrastructure/utils/pagination/paginator.go diff --git a/pkg/utils/pagination/utils.go b/pkg/infrastructure/utils/pagination/utils.go similarity index 100% rename from pkg/utils/pagination/utils.go rename to pkg/infrastructure/utils/pagination/utils.go diff --git a/pkg/utils/rand.go b/pkg/infrastructure/utils/rand.go similarity index 100% rename from pkg/utils/rand.go rename to pkg/infrastructure/utils/rand.go diff --git a/pkg/utils/rand_test.go b/pkg/infrastructure/utils/rand_test.go similarity index 100% rename from pkg/utils/rand_test.go rename to pkg/infrastructure/utils/rand_test.go diff --git a/pkg/utils/safemap.go b/pkg/infrastructure/utils/safemap.go similarity index 100% rename from pkg/utils/safemap.go rename to pkg/infrastructure/utils/safemap.go diff --git a/pkg/utils/safemap_test.go b/pkg/infrastructure/utils/safemap_test.go similarity index 100% rename from pkg/utils/safemap_test.go rename to pkg/infrastructure/utils/safemap_test.go diff --git a/pkg/utils/slice.go b/pkg/infrastructure/utils/slice.go similarity index 100% rename from pkg/utils/slice.go rename to pkg/infrastructure/utils/slice.go diff --git a/pkg/utils/slice_test.go b/pkg/infrastructure/utils/slice_test.go similarity index 100% rename from pkg/utils/slice_test.go rename to pkg/infrastructure/utils/slice_test.go diff --git a/pkg/utils/testdata/grepe.test b/pkg/infrastructure/utils/testdata/grepe.test similarity index 100% rename from pkg/utils/testdata/grepe.test rename to pkg/infrastructure/utils/testdata/grepe.test diff --git a/pkg/infrastructure/utils/time.go b/pkg/infrastructure/utils/time.go new file mode 100644 index 00000000..579b292a --- /dev/null +++ b/pkg/infrastructure/utils/time.go @@ -0,0 +1,48 @@ +// Copyright 2020 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package utils + +import ( + "fmt" + "time" +) + +// short string format +func ToShortTimeFormat(d time.Duration) string { + + u := uint64(d) + if u < uint64(time.Second) { + switch { + case u == 0: + return "0" + case u < uint64(time.Microsecond): + return fmt.Sprintf("%.2fns", float64(u)) + case u < uint64(time.Millisecond): + return fmt.Sprintf("%.2fus", float64(u)/1000) + default: + return fmt.Sprintf("%.2fms", float64(u)/1000/1000) + } + } else { + switch { + case u < uint64(time.Minute): + return fmt.Sprintf("%.2fs", float64(u)/1000/1000/1000) + case u < uint64(time.Hour): + return fmt.Sprintf("%.2fm", float64(u)/1000/1000/1000/60) + default: + return fmt.Sprintf("%.2fh", float64(u)/1000/1000/1000/60/60) + } + } + +} diff --git a/pkg/utils/utils.go b/pkg/infrastructure/utils/utils.go similarity index 100% rename from pkg/utils/utils.go rename to pkg/infrastructure/utils/utils.go diff --git a/pkg/utils/utils_test.go b/pkg/infrastructure/utils/utils_test.go similarity index 100% rename from pkg/utils/utils_test.go rename to pkg/infrastructure/utils/utils_test.go diff --git a/pkg/validation/README.md b/pkg/infrastructure/validation/README.md similarity index 100% rename from pkg/validation/README.md rename to pkg/infrastructure/validation/README.md diff --git a/pkg/validation/util.go b/pkg/infrastructure/validation/util.go similarity index 100% rename from pkg/validation/util.go rename to pkg/infrastructure/validation/util.go diff --git a/pkg/validation/util_test.go b/pkg/infrastructure/validation/util_test.go similarity index 100% rename from pkg/validation/util_test.go rename to pkg/infrastructure/validation/util_test.go diff --git a/pkg/validation/validation.go b/pkg/infrastructure/validation/validation.go similarity index 100% rename from pkg/validation/validation.go rename to pkg/infrastructure/validation/validation.go diff --git a/pkg/validation/validation_test.go b/pkg/infrastructure/validation/validation_test.go similarity index 100% rename from pkg/validation/validation_test.go rename to pkg/infrastructure/validation/validation_test.go diff --git a/pkg/validation/validators.go b/pkg/infrastructure/validation/validators.go similarity index 99% rename from pkg/validation/validators.go rename to pkg/infrastructure/validation/validators.go index 534a371e..94152b89 100644 --- a/pkg/validation/validators.go +++ b/pkg/infrastructure/validation/validators.go @@ -23,7 +23,7 @@ import ( "time" "unicode/utf8" - "github.com/astaxie/beego/pkg/logs" + "github.com/astaxie/beego/pkg/infrastructure/logs" ) // CanSkipFuncs will skip valid if RequiredFirst is true and the struct field's value is empty diff --git a/pkg/LICENSE b/pkg/server/web/LICENSE similarity index 100% rename from pkg/LICENSE rename to pkg/server/web/LICENSE diff --git a/pkg/admin.go b/pkg/server/web/admin.go similarity index 95% rename from pkg/admin.go rename to pkg/server/web/admin.go index 4d8b256f..aace3d9e 100644 --- a/pkg/admin.go +++ b/pkg/server/web/admin.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "bytes" @@ -27,10 +27,12 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/astaxie/beego/pkg/grace" - "github.com/astaxie/beego/pkg/logs" - "github.com/astaxie/beego/pkg/toolbox" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/logs" + + "github.com/astaxie/beego/pkg/infrastructure/governor" + "github.com/astaxie/beego/pkg/infrastructure/utils" + "github.com/astaxie/beego/pkg/server/web/grace" + "github.com/astaxie/beego/pkg/task" ) // BeeAdminApp is the default adminApp used by admin module. @@ -79,7 +81,7 @@ func adminIndex(rw http.ResponseWriter, _ *http.Request) { // it's registered with url pattern "/qps" in admin module. func qpsIndex(rw http.ResponseWriter, _ *http.Request) { data := make(map[interface{}]interface{}) - data["Content"] = toolbox.StatisticsMap.GetMap() + data["Content"] = StatisticsMap.GetMap() // do html escape before display path, avoid xss if content, ok := (data["Content"]).(M); ok { @@ -271,7 +273,7 @@ func profIndex(rw http.ResponseWriter, r *http.Request) { data = make(map[interface{}]interface{}) result bytes.Buffer ) - toolbox.ProcessInput(command, &result) + governor.ProcessInput(command, &result) data["Content"] = template.HTMLEscapeString(result.String()) if format == "json" && command == "gc summary" { @@ -304,7 +306,7 @@ func healthcheck(rw http.ResponseWriter, r *http.Request) { } ) - for name, h := range toolbox.AdminCheckList { + for name, h := range governor.AdminCheckList { if err := h.Check(); err != nil { result = []string{ "error", @@ -375,7 +377,7 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) { req.ParseForm() taskname := req.Form.Get("taskname") if taskname != "" { - if t, ok := toolbox.AdminTaskList[taskname]; ok { + if t, ok := task.AdminTaskList[taskname]; ok { if err := t.Run(); err != nil { data["Message"] = []string{"error", template.HTMLEscapeString(fmt.Sprintf("%s", err))} } @@ -395,7 +397,7 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) { "Last Time", "", } - for tname, tk := range toolbox.AdminTaskList { + for tname, tk := range task.AdminTaskList { result := []string{ template.HTMLEscapeString(tname), template.HTMLEscapeString(tk.GetSpec()), @@ -433,8 +435,8 @@ func (admin *adminApp) Route(pattern string, f http.HandlerFunc) { // Run adminApp http server. // Its addr is defined in configuration file as adminhttpaddr and adminhttpport. func (admin *adminApp) Run() { - if len(toolbox.AdminTaskList) > 0 { - toolbox.StartTask() + if len(task.AdminTaskList) > 0 { + task.StartTask() } addr := BConfig.Listen.AdminAddr diff --git a/pkg/admin_test.go b/pkg/server/web/admin_test.go similarity index 96% rename from pkg/admin_test.go rename to pkg/server/web/admin_test.go index 5094aeed..acc67aeb 100644 --- a/pkg/admin_test.go +++ b/pkg/server/web/admin_test.go @@ -1,4 +1,4 @@ -package beego +package web import ( "encoding/json" @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/astaxie/beego/pkg/toolbox" + "github.com/astaxie/beego/pkg/infrastructure/governor" ) type SampleDatabaseCheck struct { @@ -126,8 +126,8 @@ func TestWriteJSON(t *testing.T) { func TestHealthCheckHandlerDefault(t *testing.T) { endpointPath := "/healthcheck" - toolbox.AddHealthCheck("database", &SampleDatabaseCheck{}) - toolbox.AddHealthCheck("cache", &SampleCacheCheck{}) + governor.AddHealthCheck("database", &SampleDatabaseCheck{}) + governor.AddHealthCheck("cache", &SampleCacheCheck{}) req, err := http.NewRequest("GET", endpointPath, nil) if err != nil { @@ -187,8 +187,8 @@ func TestBuildHealthCheckResponseList(t *testing.T) { func TestHealthCheckHandlerReturnsJSON(t *testing.T) { - toolbox.AddHealthCheck("database", &SampleDatabaseCheck{}) - toolbox.AddHealthCheck("cache", &SampleCacheCheck{}) + governor.AddHealthCheck("database", &SampleDatabaseCheck{}) + governor.AddHealthCheck("cache", &SampleCacheCheck{}) req, err := http.NewRequest("GET", "/healthcheck?json=true", nil) if err != nil { diff --git a/pkg/adminui.go b/pkg/server/web/adminui.go similarity index 99% rename from pkg/adminui.go rename to pkg/server/web/adminui.go index cdcdef33..de8c9455 100644 --- a/pkg/adminui.go +++ b/pkg/server/web/adminui.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web var indexTpl = ` {{define "content"}} @@ -21,7 +21,7 @@ var indexTpl = ` For detail usage please check our document:

-Toolbox +Toolbox

Live Monitor diff --git a/pkg/app.go b/pkg/server/web/app.go similarity index 98% rename from pkg/app.go rename to pkg/server/web/app.go index ea71ce4e..e61084a5 100644 --- a/pkg/app.go +++ b/pkg/server/web/app.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "crypto/tls" @@ -29,9 +29,10 @@ import ( "golang.org/x/crypto/acme/autocert" - "github.com/astaxie/beego/pkg/grace" - "github.com/astaxie/beego/pkg/logs" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/logs" + + "github.com/astaxie/beego/pkg/infrastructure/utils" + "github.com/astaxie/beego/pkg/server/web/grace" ) var ( diff --git a/pkg/beego.go b/pkg/server/web/beego.go similarity index 99% rename from pkg/beego.go rename to pkg/server/web/beego.go index c08ae528..76e7b85e 100644 --- a/pkg/beego.go +++ b/pkg/server/web/beego.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "os" diff --git a/pkg/build_info.go b/pkg/server/web/build_info.go similarity index 98% rename from pkg/build_info.go rename to pkg/server/web/build_info.go index c31152ea..53351c11 100644 --- a/pkg/build_info.go +++ b/pkg/server/web/build_info.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web var ( BuildVersion string diff --git a/pkg/utils/captcha/LICENSE b/pkg/server/web/captcha/LICENSE similarity index 100% rename from pkg/utils/captcha/LICENSE rename to pkg/server/web/captcha/LICENSE diff --git a/pkg/utils/captcha/README.md b/pkg/server/web/captcha/README.md similarity index 100% rename from pkg/utils/captcha/README.md rename to pkg/server/web/captcha/README.md diff --git a/pkg/utils/captcha/captcha.go b/pkg/server/web/captcha/captcha.go similarity index 94% rename from pkg/utils/captcha/captcha.go rename to pkg/server/web/captcha/captcha.go index 62fc26cf..2ae1fb8f 100644 --- a/pkg/utils/captcha/captcha.go +++ b/pkg/server/web/captcha/captcha.go @@ -66,11 +66,12 @@ import ( "strings" "time" - beego "github.com/astaxie/beego/pkg" - "github.com/astaxie/beego/pkg/cache" - "github.com/astaxie/beego/pkg/context" - "github.com/astaxie/beego/pkg/logs" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/logs" + + "github.com/astaxie/beego/pkg/client/cache" + "github.com/astaxie/beego/pkg/infrastructure/utils" + "github.com/astaxie/beego/pkg/server/web" + "github.com/astaxie/beego/pkg/server/web/context" ) var ( @@ -261,10 +262,10 @@ func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha { cpt := NewCaptcha(urlPrefix, store) // create filter for serve captcha image - beego.InsertFilter(cpt.URLPrefix+"*", beego.BeforeRouter, cpt.Handler) + web.InsertFilter(cpt.URLPrefix+"*", web.BeforeRouter, cpt.Handler) // add to template func map - beego.AddFuncMap("create_captcha", cpt.CreateCaptchaHTML) + web.AddFuncMap("create_captcha", cpt.CreateCaptchaHTML) return cpt } diff --git a/pkg/utils/captcha/image.go b/pkg/server/web/captcha/image.go similarity index 100% rename from pkg/utils/captcha/image.go rename to pkg/server/web/captcha/image.go diff --git a/pkg/utils/captcha/image_test.go b/pkg/server/web/captcha/image_test.go similarity index 96% rename from pkg/utils/captcha/image_test.go rename to pkg/server/web/captcha/image_test.go index 73d3361b..36cba386 100644 --- a/pkg/utils/captcha/image_test.go +++ b/pkg/server/web/captcha/image_test.go @@ -17,7 +17,7 @@ package captcha import ( "testing" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/utils" ) type byteCounter struct { diff --git a/pkg/utils/captcha/siprng.go b/pkg/server/web/captcha/siprng.go similarity index 100% rename from pkg/utils/captcha/siprng.go rename to pkg/server/web/captcha/siprng.go diff --git a/pkg/utils/captcha/siprng_test.go b/pkg/server/web/captcha/siprng_test.go similarity index 100% rename from pkg/utils/captcha/siprng_test.go rename to pkg/server/web/captcha/siprng_test.go diff --git a/pkg/config.go b/pkg/server/web/config.go similarity index 98% rename from pkg/config.go rename to pkg/server/web/config.go index e8bde705..3abe255e 100644 --- a/pkg/config.go +++ b/pkg/server/web/config.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "fmt" @@ -22,11 +22,12 @@ import ( "runtime" "strings" - "github.com/astaxie/beego/pkg/config" - "github.com/astaxie/beego/pkg/context" - "github.com/astaxie/beego/pkg/logs" - "github.com/astaxie/beego/pkg/session" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/config" + "github.com/astaxie/beego/pkg/infrastructure/logs" + "github.com/astaxie/beego/pkg/infrastructure/session" + + "github.com/astaxie/beego/pkg/infrastructure/utils" + "github.com/astaxie/beego/pkg/server/web/context" ) // Config is the main struct for BConfig diff --git a/pkg/config_test.go b/pkg/server/web/config_test.go similarity index 97% rename from pkg/config_test.go rename to pkg/server/web/config_test.go index c810a9e3..1d6de695 100644 --- a/pkg/config_test.go +++ b/pkg/server/web/config_test.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "encoding/json" "reflect" "testing" - beeJson "github.com/astaxie/beego/pkg/config/json" + beeJson "github.com/astaxie/beego/pkg/infrastructure/config/json" ) func TestDefaults(t *testing.T) { diff --git a/pkg/context/acceptencoder.go b/pkg/server/web/context/acceptencoder.go similarity index 100% rename from pkg/context/acceptencoder.go rename to pkg/server/web/context/acceptencoder.go diff --git a/pkg/context/acceptencoder_test.go b/pkg/server/web/context/acceptencoder_test.go similarity index 100% rename from pkg/context/acceptencoder_test.go rename to pkg/server/web/context/acceptencoder_test.go diff --git a/pkg/context/context.go b/pkg/server/web/context/context.go similarity index 99% rename from pkg/context/context.go rename to pkg/server/web/context/context.go index f7b325a9..78e0a6d6 100644 --- a/pkg/context/context.go +++ b/pkg/server/web/context/context.go @@ -35,7 +35,7 @@ import ( "strings" "time" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/utils" ) // Commonly used mime-types diff --git a/pkg/context/context_test.go b/pkg/server/web/context/context_test.go similarity index 100% rename from pkg/context/context_test.go rename to pkg/server/web/context/context_test.go diff --git a/pkg/context/input.go b/pkg/server/web/context/input.go similarity index 99% rename from pkg/context/input.go rename to pkg/server/web/context/input.go index 5ff85f43..b8272f64 100644 --- a/pkg/context/input.go +++ b/pkg/server/web/context/input.go @@ -29,7 +29,7 @@ import ( "strings" "sync" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" ) // Regexes for checking the accept headers diff --git a/pkg/context/input_test.go b/pkg/server/web/context/input_test.go similarity index 100% rename from pkg/context/input_test.go rename to pkg/server/web/context/input_test.go diff --git a/pkg/context/output.go b/pkg/server/web/context/output.go similarity index 100% rename from pkg/context/output.go rename to pkg/server/web/context/output.go diff --git a/pkg/context/param/conv.go b/pkg/server/web/context/param/conv.go similarity index 94% rename from pkg/context/param/conv.go rename to pkg/server/web/context/param/conv.go index d96f964c..a96dacdd 100644 --- a/pkg/context/param/conv.go +++ b/pkg/server/web/context/param/conv.go @@ -4,8 +4,8 @@ import ( "fmt" "reflect" - beecontext "github.com/astaxie/beego/pkg/context" - "github.com/astaxie/beego/pkg/logs" + "github.com/astaxie/beego/pkg/infrastructure/logs" + beecontext "github.com/astaxie/beego/pkg/server/web/context" ) // ConvertParams converts http method params to values that will be passed to the method controller as arguments diff --git a/pkg/context/param/methodparams.go b/pkg/server/web/context/param/methodparams.go similarity index 100% rename from pkg/context/param/methodparams.go rename to pkg/server/web/context/param/methodparams.go diff --git a/pkg/context/param/options.go b/pkg/server/web/context/param/options.go similarity index 100% rename from pkg/context/param/options.go rename to pkg/server/web/context/param/options.go diff --git a/pkg/context/param/parsers.go b/pkg/server/web/context/param/parsers.go similarity index 100% rename from pkg/context/param/parsers.go rename to pkg/server/web/context/param/parsers.go diff --git a/pkg/context/param/parsers_test.go b/pkg/server/web/context/param/parsers_test.go similarity index 100% rename from pkg/context/param/parsers_test.go rename to pkg/server/web/context/param/parsers_test.go diff --git a/pkg/context/renderer.go b/pkg/server/web/context/renderer.go similarity index 100% rename from pkg/context/renderer.go rename to pkg/server/web/context/renderer.go diff --git a/pkg/context/response.go b/pkg/server/web/context/response.go similarity index 100% rename from pkg/context/response.go rename to pkg/server/web/context/response.go diff --git a/pkg/controller.go b/pkg/server/web/controller.go similarity index 99% rename from pkg/controller.go rename to pkg/server/web/controller.go index f3989a76..6b71d617 100644 --- a/pkg/controller.go +++ b/pkg/server/web/controller.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "bytes" @@ -28,9 +28,10 @@ import ( "strconv" "strings" - "github.com/astaxie/beego/pkg/context" - "github.com/astaxie/beego/pkg/context/param" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/session" + + "github.com/astaxie/beego/pkg/server/web/context" + "github.com/astaxie/beego/pkg/server/web/context/param" ) var ( diff --git a/pkg/controller_test.go b/pkg/server/web/controller_test.go similarity index 98% rename from pkg/controller_test.go rename to pkg/server/web/controller_test.go index 97f1e964..46da3629 100644 --- a/pkg/controller_test.go +++ b/pkg/server/web/controller_test.go @@ -12,19 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "math" + "os" + "path/filepath" "strconv" "testing" "github.com/stretchr/testify/assert" - "os" - "path/filepath" - - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web/context" ) func TestGetInt(t *testing.T) { diff --git a/pkg/server/web/doc.go b/pkg/server/web/doc.go new file mode 100644 index 00000000..0ab10bfd --- /dev/null +++ b/pkg/server/web/doc.go @@ -0,0 +1,17 @@ +/* +Package beego provide a MVC framework +beego: an open-source, high-performance, modular, full-stack web framework + +It is used for rapid development of RESTful APIs, web apps and backend services in Go. +beego is inspired by Tornado, Sinatra and Flask with the added benefit of some Go-specific features such as interfaces and struct embedding. + + package main + import "github.com/astaxie/beego/pkg" + + func main() { + beego.Run() + } + +more information: http://beego.me +*/ +package web diff --git a/pkg/error.go b/pkg/server/web/error.go similarity index 99% rename from pkg/error.go rename to pkg/server/web/error.go index aff984c0..b62fb70d 100644 --- a/pkg/error.go +++ b/pkg/server/web/error.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "fmt" @@ -23,8 +23,9 @@ import ( "strconv" "strings" - "github.com/astaxie/beego/pkg/context" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/utils" + + "github.com/astaxie/beego/pkg/server/web/context" ) const ( diff --git a/pkg/error_test.go b/pkg/server/web/error_test.go similarity index 99% rename from pkg/error_test.go rename to pkg/server/web/error_test.go index 378aa953..2685a985 100644 --- a/pkg/error_test.go +++ b/pkg/server/web/error_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "net/http" diff --git a/pkg/filter.go b/pkg/server/web/filter.go similarity index 98% rename from pkg/filter.go rename to pkg/server/web/filter.go index 911cb848..8d3acb24 100644 --- a/pkg/filter.go +++ b/pkg/server/web/filter.go @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "strings" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web/context" ) // FilterChain is different from pure FilterFunc diff --git a/pkg/plugins/apiauth/apiauth.go b/pkg/server/web/filter/apiauth/apiauth.go similarity index 93% rename from pkg/plugins/apiauth/apiauth.go rename to pkg/server/web/filter/apiauth/apiauth.go index 7b1d4405..ba56030b 100644 --- a/pkg/plugins/apiauth/apiauth.go +++ b/pkg/server/web/filter/apiauth/apiauth.go @@ -65,15 +65,15 @@ import ( "sort" "time" - beego "github.com/astaxie/beego/pkg" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web" + "github.com/astaxie/beego/pkg/server/web/context" ) // AppIDToAppSecret gets appsecret through appid type AppIDToAppSecret func(string) string // APIBasicAuth uses the basic appid/appkey as the AppIdToAppSecret -func APIBasicAuth(appid, appkey string) beego.FilterFunc { +func APIBasicAuth(appid, appkey string) web.FilterFunc { ft := func(aid string) string { if aid == appid { return appkey @@ -84,12 +84,12 @@ func APIBasicAuth(appid, appkey string) beego.FilterFunc { } // APIBasicAuth calls APIBasicAuth for previous callers -func APIBaiscAuth(appid, appkey string) beego.FilterFunc { +func APIBaiscAuth(appid, appkey string) web.FilterFunc { return APIBasicAuth(appid, appkey) } // APISecretAuth uses AppIdToAppSecret verify and -func APISecretAuth(f AppIDToAppSecret, timeout int) beego.FilterFunc { +func APISecretAuth(f AppIDToAppSecret, timeout int) web.FilterFunc { return func(ctx *context.Context) { if ctx.Input.Query("appid") == "" { ctx.ResponseWriter.WriteHeader(403) diff --git a/pkg/plugins/apiauth/apiauth_test.go b/pkg/server/web/filter/apiauth/apiauth_test.go similarity index 100% rename from pkg/plugins/apiauth/apiauth_test.go rename to pkg/server/web/filter/apiauth/apiauth_test.go diff --git a/pkg/plugins/auth/basic.go b/pkg/server/web/filter/auth/basic.go similarity index 94% rename from pkg/plugins/auth/basic.go rename to pkg/server/web/filter/auth/basic.go index d84b8df2..209cd97d 100644 --- a/pkg/plugins/auth/basic.go +++ b/pkg/server/web/filter/auth/basic.go @@ -40,14 +40,14 @@ import ( "net/http" "strings" - beego "github.com/astaxie/beego/pkg" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web" + "github.com/astaxie/beego/pkg/server/web/context" ) var defaultRealm = "Authorization Required" // Basic is the http basic auth -func Basic(username string, password string) beego.FilterFunc { +func Basic(username string, password string) web.FilterFunc { secrets := func(user, pass string) bool { return user == username && pass == password } @@ -55,7 +55,7 @@ func Basic(username string, password string) beego.FilterFunc { } // NewBasicAuthenticator return the BasicAuth -func NewBasicAuthenticator(secrets SecretProvider, Realm string) beego.FilterFunc { +func NewBasicAuthenticator(secrets SecretProvider, Realm string) web.FilterFunc { return func(ctx *context.Context) { a := &BasicAuth{Secrets: secrets, Realm: Realm} if username := a.CheckAuth(ctx.Request); username == "" { diff --git a/pkg/plugins/authz/authz.go b/pkg/server/web/filter/authz/authz.go similarity index 94% rename from pkg/plugins/authz/authz.go rename to pkg/server/web/filter/authz/authz.go index 47a20c8a..a3a8dca6 100644 --- a/pkg/plugins/authz/authz.go +++ b/pkg/server/web/filter/authz/authz.go @@ -42,14 +42,15 @@ package authz import ( "net/http" - beego "github.com/astaxie/beego/pkg" - "github.com/astaxie/beego/pkg/context" "github.com/casbin/casbin" + + "github.com/astaxie/beego/pkg/server/web" + "github.com/astaxie/beego/pkg/server/web/context" ) // NewAuthorizer returns the authorizer. // Use a casbin enforcer as input -func NewAuthorizer(e *casbin.Enforcer) beego.FilterFunc { +func NewAuthorizer(e *casbin.Enforcer) web.FilterFunc { return func(ctx *context.Context) { a := &BasicAuthorizer{enforcer: e} diff --git a/pkg/plugins/authz/authz_model.conf b/pkg/server/web/filter/authz/authz_model.conf similarity index 100% rename from pkg/plugins/authz/authz_model.conf rename to pkg/server/web/filter/authz/authz_model.conf diff --git a/pkg/plugins/authz/authz_policy.csv b/pkg/server/web/filter/authz/authz_policy.csv similarity index 100% rename from pkg/plugins/authz/authz_policy.csv rename to pkg/server/web/filter/authz/authz_policy.csv diff --git a/pkg/plugins/authz/authz_test.go b/pkg/server/web/filter/authz/authz_test.go similarity index 79% rename from pkg/plugins/authz/authz_test.go rename to pkg/server/web/filter/authz/authz_test.go index 6cc081f3..e50596b4 100644 --- a/pkg/plugins/authz/authz_test.go +++ b/pkg/server/web/filter/authz/authz_test.go @@ -19,13 +19,14 @@ import ( "net/http/httptest" "testing" - beego "github.com/astaxie/beego/pkg" - "github.com/astaxie/beego/pkg/context" - "github.com/astaxie/beego/pkg/plugins/auth" "github.com/casbin/casbin" + + "github.com/astaxie/beego/pkg/server/web" + "github.com/astaxie/beego/pkg/server/web/context" + "github.com/astaxie/beego/pkg/server/web/filter/auth" ) -func testRequest(t *testing.T, handler *beego.ControllerRegister, user string, path string, method string, code int) { +func testRequest(t *testing.T, handler *web.ControllerRegister, user string, path string, method string, code int) { r, _ := http.NewRequest(method, path, nil) r.SetBasicAuth(user, "123") w := httptest.NewRecorder() @@ -37,10 +38,10 @@ func testRequest(t *testing.T, handler *beego.ControllerRegister, user string, p } func TestBasic(t *testing.T) { - handler := beego.NewControllerRegister() + handler := web.NewControllerRegister() - handler.InsertFilter("*", beego.BeforeRouter, auth.Basic("alice", "123")) - handler.InsertFilter("*", beego.BeforeRouter, NewAuthorizer(casbin.NewEnforcer("authz_model.conf", "authz_policy.csv"))) + handler.InsertFilter("*", web.BeforeRouter, auth.Basic("alice", "123")) + handler.InsertFilter("*", web.BeforeRouter, NewAuthorizer(casbin.NewEnforcer("authz_model.conf", "authz_policy.csv"))) handler.Any("*", func(ctx *context.Context) { ctx.Output.SetStatus(200) @@ -53,10 +54,10 @@ func TestBasic(t *testing.T) { } func TestPathWildcard(t *testing.T) { - handler := beego.NewControllerRegister() + handler := web.NewControllerRegister() - handler.InsertFilter("*", beego.BeforeRouter, auth.Basic("bob", "123")) - handler.InsertFilter("*", beego.BeforeRouter, NewAuthorizer(casbin.NewEnforcer("authz_model.conf", "authz_policy.csv"))) + handler.InsertFilter("*", web.BeforeRouter, auth.Basic("bob", "123")) + handler.InsertFilter("*", web.BeforeRouter, NewAuthorizer(casbin.NewEnforcer("authz_model.conf", "authz_policy.csv"))) handler.Any("*", func(ctx *context.Context) { ctx.Output.SetStatus(200) @@ -78,11 +79,11 @@ func TestPathWildcard(t *testing.T) { } func TestRBAC(t *testing.T) { - handler := beego.NewControllerRegister() + handler := web.NewControllerRegister() - handler.InsertFilter("*", beego.BeforeRouter, auth.Basic("cathy", "123")) + handler.InsertFilter("*", web.BeforeRouter, auth.Basic("cathy", "123")) e := casbin.NewEnforcer("authz_model.conf", "authz_policy.csv") - handler.InsertFilter("*", beego.BeforeRouter, NewAuthorizer(e)) + handler.InsertFilter("*", web.BeforeRouter, NewAuthorizer(e)) handler.Any("*", func(ctx *context.Context) { ctx.Output.SetStatus(200) diff --git a/pkg/plugins/cors/cors.go b/pkg/server/web/filter/cors/cors.go similarity index 97% rename from pkg/plugins/cors/cors.go rename to pkg/server/web/filter/cors/cors.go index 18bf2bec..800eeded 100644 --- a/pkg/plugins/cors/cors.go +++ b/pkg/server/web/filter/cors/cors.go @@ -42,8 +42,8 @@ import ( "strings" "time" - beego "github.com/astaxie/beego/pkg" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web" + "github.com/astaxie/beego/pkg/server/web/context" ) const ( @@ -187,7 +187,7 @@ func (o *Options) IsOriginAllowed(origin string) (allowed bool) { } // Allow enables CORS for requests those match the provided options. -func Allow(opts *Options) beego.FilterFunc { +func Allow(opts *Options) web.FilterFunc { // Allow default headers if nothing is specified. if len(opts.AllowHeaders) == 0 { opts.AllowHeaders = defaultAllowHeaders diff --git a/pkg/plugins/cors/cors_test.go b/pkg/server/web/filter/cors/cors_test.go similarity index 88% rename from pkg/plugins/cors/cors_test.go rename to pkg/server/web/filter/cors/cors_test.go index 664d35a7..60659fdd 100644 --- a/pkg/plugins/cors/cors_test.go +++ b/pkg/server/web/filter/cors/cors_test.go @@ -21,8 +21,8 @@ import ( "testing" "time" - beego "github.com/astaxie/beego/pkg" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web" + "github.com/astaxie/beego/pkg/server/web/context" ) // HTTPHeaderGuardRecorder is httptest.ResponseRecorder with own http.Header @@ -55,8 +55,8 @@ func (gr *HTTPHeaderGuardRecorder) Header() http.Header { func Test_AllowAll(t *testing.T) { recorder := httptest.NewRecorder() - handler := beego.NewControllerRegister() - handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + handler := web.NewControllerRegister() + handler.InsertFilter("*", web.BeforeRouter, Allow(&Options{ AllowAllOrigins: true, })) handler.Any("/foo", func(ctx *context.Context) { @@ -72,8 +72,8 @@ func Test_AllowAll(t *testing.T) { func Test_AllowRegexMatch(t *testing.T) { recorder := httptest.NewRecorder() - handler := beego.NewControllerRegister() - handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + handler := web.NewControllerRegister() + handler.InsertFilter("*", web.BeforeRouter, Allow(&Options{ AllowOrigins: []string{"https://aaa.com", "https://*.foo.com"}, })) handler.Any("/foo", func(ctx *context.Context) { @@ -92,8 +92,8 @@ func Test_AllowRegexMatch(t *testing.T) { func Test_AllowRegexNoMatch(t *testing.T) { recorder := httptest.NewRecorder() - handler := beego.NewControllerRegister() - handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + handler := web.NewControllerRegister() + handler.InsertFilter("*", web.BeforeRouter, Allow(&Options{ AllowOrigins: []string{"https://*.foo.com"}, })) handler.Any("/foo", func(ctx *context.Context) { @@ -112,8 +112,8 @@ func Test_AllowRegexNoMatch(t *testing.T) { func Test_OtherHeaders(t *testing.T) { recorder := httptest.NewRecorder() - handler := beego.NewControllerRegister() - handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + handler := web.NewControllerRegister() + handler.InsertFilter("*", web.BeforeRouter, Allow(&Options{ AllowAllOrigins: true, AllowCredentials: true, AllowMethods: []string{"PATCH", "GET"}, @@ -156,8 +156,8 @@ func Test_OtherHeaders(t *testing.T) { func Test_DefaultAllowHeaders(t *testing.T) { recorder := httptest.NewRecorder() - handler := beego.NewControllerRegister() - handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + handler := web.NewControllerRegister() + handler.InsertFilter("*", web.BeforeRouter, Allow(&Options{ AllowAllOrigins: true, })) handler.Any("/foo", func(ctx *context.Context) { @@ -175,8 +175,8 @@ func Test_DefaultAllowHeaders(t *testing.T) { func Test_Preflight(t *testing.T) { recorder := NewRecorder() - handler := beego.NewControllerRegister() - handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + handler := web.NewControllerRegister() + handler.InsertFilter("*", web.BeforeRouter, Allow(&Options{ AllowAllOrigins: true, AllowMethods: []string{"PUT", "PATCH"}, AllowHeaders: []string{"Origin", "X-whatever", "X-CaseSensitive"}, @@ -219,8 +219,8 @@ func Test_Preflight(t *testing.T) { func Benchmark_WithoutCORS(b *testing.B) { recorder := httptest.NewRecorder() - handler := beego.NewControllerRegister() - beego.BConfig.RunMode = beego.PROD + handler := web.NewControllerRegister() + web.BConfig.RunMode = web.PROD handler.Any("/foo", func(ctx *context.Context) { ctx.Output.SetStatus(500) }) @@ -233,9 +233,9 @@ func Benchmark_WithoutCORS(b *testing.B) { func Benchmark_WithCORS(b *testing.B) { recorder := httptest.NewRecorder() - handler := beego.NewControllerRegister() - beego.BConfig.RunMode = beego.PROD - handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + handler := web.NewControllerRegister() + web.BConfig.RunMode = web.PROD + handler.InsertFilter("*", web.BeforeRouter, Allow(&Options{ AllowAllOrigins: true, AllowCredentials: true, AllowMethods: []string{"PATCH", "GET"}, diff --git a/pkg/web/filter/opentracing/filter.go b/pkg/server/web/filter/opentracing/filter.go similarity index 92% rename from pkg/web/filter/opentracing/filter.go rename to pkg/server/web/filter/opentracing/filter.go index e6ee9150..dd5663f9 100644 --- a/pkg/web/filter/opentracing/filter.go +++ b/pkg/server/web/filter/opentracing/filter.go @@ -21,8 +21,8 @@ import ( opentracingKit "github.com/go-kit/kit/tracing/opentracing" "github.com/opentracing/opentracing-go" - beego "github.com/astaxie/beego/pkg" - beegoCtx "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web" + beegoCtx "github.com/astaxie/beego/pkg/server/web/context" ) // FilterChainBuilder provides an extension point that we can support more configurations if necessary @@ -31,7 +31,7 @@ type FilterChainBuilder struct { CustomSpanFunc func(span opentracing.Span, ctx *beegoCtx.Context) } -func (builder *FilterChainBuilder) FilterChain(next beego.FilterFunc) beego.FilterFunc { +func (builder *FilterChainBuilder) FilterChain(next web.FilterFunc) web.FilterFunc { return func(ctx *beegoCtx.Context) { var ( spanCtx context.Context @@ -79,7 +79,7 @@ func (builder *FilterChainBuilder) operationName(ctx *beegoCtx.Context) string { operationName := ctx.Input.URL() // it means that there is not any span, so we create a span as the root span. // TODO, if we support multiple servers, this need to be changed - route, found := beego.BeeApp.Handlers.FindRouter(ctx) + route, found := web.BeeApp.Handlers.FindRouter(ctx) if found { operationName = ctx.Input.Method() + "#" + route.GetPattern() } diff --git a/pkg/web/filter/opentracing/filter_test.go b/pkg/server/web/filter/opentracing/filter_test.go similarity index 96% rename from pkg/web/filter/opentracing/filter_test.go rename to pkg/server/web/filter/opentracing/filter_test.go index 750ea7a9..04f44324 100644 --- a/pkg/web/filter/opentracing/filter_test.go +++ b/pkg/server/web/filter/opentracing/filter_test.go @@ -22,7 +22,7 @@ import ( "github.com/opentracing/opentracing-go" "github.com/stretchr/testify/assert" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web/context" ) func TestFilterChainBuilder_FilterChain(t *testing.T) { diff --git a/pkg/web/filter/prometheus/filter.go b/pkg/server/web/filter/prometheus/filter.go similarity index 76% rename from pkg/web/filter/prometheus/filter.go rename to pkg/server/web/filter/prometheus/filter.go index 8f4b46e3..f4231c73 100644 --- a/pkg/web/filter/prometheus/filter.go +++ b/pkg/server/web/filter/prometheus/filter.go @@ -21,8 +21,8 @@ import ( "github.com/prometheus/client_golang/prometheus" - beego "github.com/astaxie/beego/pkg" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web" + "github.com/astaxie/beego/pkg/server/web/context" ) // FilterChainBuilder is an extension point, @@ -32,14 +32,14 @@ type FilterChainBuilder struct { } // FilterChain returns a FilterFunc. The filter will records some metrics -func (builder *FilterChainBuilder) FilterChain(next beego.FilterFunc) beego.FilterFunc { +func (builder *FilterChainBuilder) FilterChain(next web.FilterFunc) web.FilterFunc { summaryVec := prometheus.NewSummaryVec(prometheus.SummaryOpts{ Name: "beego", Subsystem: "http_request", ConstLabels: map[string]string{ - "server": beego.BConfig.ServerName, - "env": beego.BConfig.RunMode, - "appname": beego.BConfig.AppName, + "server": web.BConfig.ServerName, + "env": web.BConfig.RunMode, + "appname": web.BConfig.AppName, }, Help: "The statics info for http request", }, []string{"pattern", "method", "status", "duration"}) @@ -62,14 +62,14 @@ func registerBuildInfo() { Subsystem: "build_info", Help: "The building information", ConstLabels: map[string]string{ - "appname": beego.BConfig.AppName, - "build_version": beego.BuildVersion, - "build_revision": beego.BuildGitRevision, - "build_status": beego.BuildStatus, - "build_tag": beego.BuildTag, - "build_time": strings.Replace(beego.BuildTime, "--", " ", 1), - "go_version": beego.GoVersion, - "git_branch": beego.GitBranch, + "appname": web.BConfig.AppName, + "build_version": web.BuildVersion, + "build_revision": web.BuildGitRevision, + "build_status": web.BuildStatus, + "build_tag": web.BuildTag, + "build_time": strings.Replace(web.BuildTime, "--", " ", 1), + "go_version": web.GoVersion, + "git_branch": web.GitBranch, "start_time": time.Now().Format("2006-01-02 15:04:05"), }, }, []string{}) diff --git a/pkg/web/filter/prometheus/filter_test.go b/pkg/server/web/filter/prometheus/filter_test.go similarity index 95% rename from pkg/web/filter/prometheus/filter_test.go rename to pkg/server/web/filter/prometheus/filter_test.go index 822892bc..08887839 100644 --- a/pkg/web/filter/prometheus/filter_test.go +++ b/pkg/server/web/filter/prometheus/filter_test.go @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web/context" ) func TestFilterChain(t *testing.T) { diff --git a/pkg/filter_chain_test.go b/pkg/server/web/filter_chain_test.go similarity index 94% rename from pkg/filter_chain_test.go rename to pkg/server/web/filter_chain_test.go index f1f86088..44d5f71e 100644 --- a/pkg/filter_chain_test.go +++ b/pkg/server/web/filter_chain_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "net/http" @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web/context" ) func TestControllerRegister_InsertFilterChain(t *testing.T) { diff --git a/pkg/filter_test.go b/pkg/server/web/filter_test.go similarity index 97% rename from pkg/filter_test.go rename to pkg/server/web/filter_test.go index 3a1bcb07..eea50534 100644 --- a/pkg/filter_test.go +++ b/pkg/server/web/filter_test.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "net/http" "net/http/httptest" "testing" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web/context" ) var FilterUser = func(ctx *context.Context) { diff --git a/pkg/flash.go b/pkg/server/web/flash.go similarity index 99% rename from pkg/flash.go rename to pkg/server/web/flash.go index a6485a17..55f6435d 100644 --- a/pkg/flash.go +++ b/pkg/server/web/flash.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "fmt" diff --git a/pkg/flash_test.go b/pkg/server/web/flash_test.go similarity index 99% rename from pkg/flash_test.go rename to pkg/server/web/flash_test.go index d5e9608d..2deef54e 100644 --- a/pkg/flash_test.go +++ b/pkg/server/web/flash_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "net/http" diff --git a/pkg/fs.go b/pkg/server/web/fs.go similarity index 99% rename from pkg/fs.go rename to pkg/server/web/fs.go index 41cc6f6e..5457457a 100644 --- a/pkg/fs.go +++ b/pkg/server/web/fs.go @@ -1,4 +1,4 @@ -package beego +package web import ( "net/http" diff --git a/pkg/grace/grace.go b/pkg/server/web/grace/grace.go similarity index 100% rename from pkg/grace/grace.go rename to pkg/server/web/grace/grace.go diff --git a/pkg/grace/server.go b/pkg/server/web/grace/server.go similarity index 100% rename from pkg/grace/server.go rename to pkg/server/web/grace/server.go diff --git a/pkg/hooks.go b/pkg/server/web/hooks.go similarity index 94% rename from pkg/hooks.go rename to pkg/server/web/hooks.go index 3f778cdc..13194733 100644 --- a/pkg/hooks.go +++ b/pkg/server/web/hooks.go @@ -1,4 +1,4 @@ -package beego +package web import ( "encoding/json" @@ -6,9 +6,10 @@ import ( "net/http" "path/filepath" - "github.com/astaxie/beego/pkg/context" - "github.com/astaxie/beego/pkg/logs" - "github.com/astaxie/beego/pkg/session" + "github.com/astaxie/beego/pkg/infrastructure/logs" + "github.com/astaxie/beego/pkg/infrastructure/session" + + "github.com/astaxie/beego/pkg/server/web/context" ) // register MIME type with content type diff --git a/pkg/mime.go b/pkg/server/web/mime.go similarity index 99% rename from pkg/mime.go rename to pkg/server/web/mime.go index ca2878ab..9393e9c7 100644 --- a/pkg/mime.go +++ b/pkg/server/web/mime.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web var mimemaps = map[string]string{ ".3dm": "x-world/x-3dmf", diff --git a/pkg/namespace.go b/pkg/server/web/namespace.go similarity index 99% rename from pkg/namespace.go rename to pkg/server/web/namespace.go index bda18f4b..e59f38c5 100644 --- a/pkg/namespace.go +++ b/pkg/server/web/namespace.go @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "net/http" "strings" - beecontext "github.com/astaxie/beego/pkg/context" + beecontext "github.com/astaxie/beego/pkg/server/web/context" ) type namespaceCond func(*beecontext.Context) bool diff --git a/pkg/namespace_test.go b/pkg/server/web/namespace_test.go similarity index 98% rename from pkg/namespace_test.go rename to pkg/server/web/namespace_test.go index bdf33b4f..39d60041 100644 --- a/pkg/namespace_test.go +++ b/pkg/server/web/namespace_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "net/http" @@ -20,7 +20,7 @@ import ( "strconv" "testing" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web/context" ) func TestNamespaceGet(t *testing.T) { diff --git a/pkg/utils/pagination/controller.go b/pkg/server/web/pagination/controller.go similarity index 79% rename from pkg/utils/pagination/controller.go rename to pkg/server/web/pagination/controller.go index b5b09a2f..530a72ff 100644 --- a/pkg/utils/pagination/controller.go +++ b/pkg/server/web/pagination/controller.go @@ -15,12 +15,13 @@ package pagination import ( - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/infrastructure/utils/pagination" + "github.com/astaxie/beego/pkg/server/web/context" ) // SetPaginator Instantiates a Paginator and assigns it to context.Input.Data("paginator"). -func SetPaginator(context *context.Context, per int, nums int64) (paginator *Paginator) { - paginator = NewPaginator(context.Request, per, nums) +func SetPaginator(context *context.Context, per int, nums int64) (paginator *pagination.Paginator) { + paginator = pagination.NewPaginator(context.Request, per, nums) context.Input.SetData("paginator", &paginator) return } diff --git a/pkg/parser.go b/pkg/server/web/parser.go similarity index 98% rename from pkg/parser.go rename to pkg/server/web/parser.go index bee45d7b..ce63a0be 100644 --- a/pkg/parser.go +++ b/pkg/server/web/parser.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "encoding/json" @@ -30,16 +30,17 @@ import ( "golang.org/x/tools/go/packages" - "github.com/astaxie/beego/pkg/context/param" - "github.com/astaxie/beego/pkg/logs" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/logs" + + "github.com/astaxie/beego/pkg/infrastructure/utils" + "github.com/astaxie/beego/pkg/server/web/context/param" ) var globalRouterTemplate = `package {{.routersDir}} import ( "github.com/astaxie/beego/pkg" - "github.com/astaxie/beego/pkg/context/param"{{.globalimport}} + "github.com/astaxie/beego/pkg/server/web/context/param"{{.globalimport}} ) func init() { diff --git a/pkg/policy.go b/pkg/server/web/policy.go similarity index 97% rename from pkg/policy.go rename to pkg/server/web/policy.go index 4af240f1..2099f99d 100644 --- a/pkg/policy.go +++ b/pkg/server/web/policy.go @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "strings" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web/context" ) // PolicyFunc defines a policy function which is invoked before the controller handler is executed. diff --git a/pkg/router.go b/pkg/server/web/router.go similarity index 98% rename from pkg/router.go rename to pkg/server/web/router.go index 6b25d7e3..9b70753e 100644 --- a/pkg/router.go +++ b/pkg/server/web/router.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "errors" @@ -25,11 +25,11 @@ import ( "sync" "time" - beecontext "github.com/astaxie/beego/pkg/context" - "github.com/astaxie/beego/pkg/context/param" - "github.com/astaxie/beego/pkg/logs" - "github.com/astaxie/beego/pkg/toolbox" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/logs" + + "github.com/astaxie/beego/pkg/infrastructure/utils" + beecontext "github.com/astaxie/beego/pkg/server/web/context" + "github.com/astaxie/beego/pkg/server/web/context/param" ) // default filter execution points @@ -906,7 +906,7 @@ Admin: if runRouter != nil { routerName = runRouter.Name() } - go toolbox.StatisticsMap.AddStatistics(r.Method, r.URL.Path, routerName, timeDur) + go StatisticsMap.AddStatistics(r.Method, r.URL.Path, routerName, timeDur) } } diff --git a/pkg/router_test.go b/pkg/server/web/router_test.go similarity index 99% rename from pkg/router_test.go rename to pkg/server/web/router_test.go index 8a7862f6..14ad1484 100644 --- a/pkg/router_test.go +++ b/pkg/server/web/router_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "bytes" @@ -21,8 +21,9 @@ import ( "strings" "testing" - "github.com/astaxie/beego/pkg/context" - "github.com/astaxie/beego/pkg/logs" + "github.com/astaxie/beego/pkg/infrastructure/logs" + + "github.com/astaxie/beego/pkg/server/web/context" ) type TestController struct { diff --git a/pkg/staticfile.go b/pkg/server/web/staticfile.go similarity index 98% rename from pkg/staticfile.go rename to pkg/server/web/staticfile.go index f8b17fc5..7b9942f4 100644 --- a/pkg/staticfile.go +++ b/pkg/server/web/staticfile.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "bytes" @@ -26,9 +26,10 @@ import ( "sync" "time" - "github.com/astaxie/beego/pkg/context" - "github.com/astaxie/beego/pkg/logs" + "github.com/astaxie/beego/pkg/infrastructure/logs" lru "github.com/hashicorp/golang-lru" + + "github.com/astaxie/beego/pkg/server/web/context" ) var errNotStaticRequest = errors.New("request not a static file request") diff --git a/pkg/staticfile_test.go b/pkg/server/web/staticfile_test.go similarity index 99% rename from pkg/staticfile_test.go rename to pkg/server/web/staticfile_test.go index e46c13ec..0725a2f8 100644 --- a/pkg/staticfile_test.go +++ b/pkg/server/web/staticfile_test.go @@ -1,4 +1,4 @@ -package beego +package web import ( "bytes" diff --git a/pkg/toolbox/statistics.go b/pkg/server/web/statistics.go similarity index 85% rename from pkg/toolbox/statistics.go rename to pkg/server/web/statistics.go index fd73dfb3..ccc3a1fc 100644 --- a/pkg/toolbox/statistics.go +++ b/pkg/server/web/statistics.go @@ -12,12 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package toolbox +package web import ( "fmt" "sync" "time" + + "github.com/astaxie/beego/pkg/infrastructure/utils" ) // Statistics struct @@ -100,13 +102,13 @@ func (m *URLMap) GetMap() map[string]interface{} { fmt.Sprintf("% -10s", kk), fmt.Sprintf("% -16d", vv.RequestNum), fmt.Sprintf("%d", vv.TotalTime), - fmt.Sprintf("% -16s", toS(vv.TotalTime)), + fmt.Sprintf("% -16s", utils.ToShortTimeFormat(vv.TotalTime)), fmt.Sprintf("%d", vv.MaxTime), - fmt.Sprintf("% -16s", toS(vv.MaxTime)), + fmt.Sprintf("% -16s", utils.ToShortTimeFormat(vv.MaxTime)), fmt.Sprintf("%d", vv.MinTime), - fmt.Sprintf("% -16s", toS(vv.MinTime)), + fmt.Sprintf("% -16s", utils.ToShortTimeFormat(vv.MinTime)), fmt.Sprintf("%d", time.Duration(int64(vv.TotalTime)/vv.RequestNum)), - fmt.Sprintf("% -16s", toS(time.Duration(int64(vv.TotalTime)/vv.RequestNum))), + fmt.Sprintf("% -16s", utils.ToShortTimeFormat(time.Duration(int64(vv.TotalTime)/vv.RequestNum))), } resultLists = append(resultLists, result) } @@ -128,10 +130,10 @@ func (m *URLMap) GetMapData() []map[string]interface{} { "request_url": k, "method": kk, "times": vv.RequestNum, - "total_time": toS(vv.TotalTime), - "max_time": toS(vv.MaxTime), - "min_time": toS(vv.MinTime), - "avg_time": toS(time.Duration(int64(vv.TotalTime) / vv.RequestNum)), + "total_time": utils.ToShortTimeFormat(vv.TotalTime), + "max_time": utils.ToShortTimeFormat(vv.MaxTime), + "min_time": utils.ToShortTimeFormat(vv.MinTime), + "avg_time": utils.ToShortTimeFormat(time.Duration(int64(vv.TotalTime) / vv.RequestNum)), } resultLists = append(resultLists, result) } diff --git a/pkg/toolbox/statistics_test.go b/pkg/server/web/statistics_test.go similarity index 98% rename from pkg/toolbox/statistics_test.go rename to pkg/server/web/statistics_test.go index ac29476c..7c83e15a 100644 --- a/pkg/toolbox/statistics_test.go +++ b/pkg/server/web/statistics_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package toolbox +package web import ( "encoding/json" diff --git a/pkg/swagger/swagger.go b/pkg/server/web/swagger/swagger.go similarity index 100% rename from pkg/swagger/swagger.go rename to pkg/server/web/swagger/swagger.go diff --git a/pkg/template.go b/pkg/server/web/template.go similarity index 99% rename from pkg/template.go rename to pkg/server/web/template.go index 8edd9dc1..a4b8db99 100644 --- a/pkg/template.go +++ b/pkg/server/web/template.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "errors" @@ -27,8 +27,8 @@ import ( "strings" "sync" - "github.com/astaxie/beego/pkg/logs" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/logs" + "github.com/astaxie/beego/pkg/infrastructure/utils" ) var ( diff --git a/pkg/template_test.go b/pkg/server/web/template_test.go similarity index 99% rename from pkg/template_test.go rename to pkg/server/web/template_test.go index 134c2cb2..b542494d 100644 --- a/pkg/template_test.go +++ b/pkg/server/web/template_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "bytes" diff --git a/pkg/templatefunc.go b/pkg/server/web/templatefunc.go similarity index 99% rename from pkg/templatefunc.go rename to pkg/server/web/templatefunc.go index 6f02b8d6..6d132bf0 100644 --- a/pkg/templatefunc.go +++ b/pkg/server/web/templatefunc.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "errors" diff --git a/pkg/templatefunc_test.go b/pkg/server/web/templatefunc_test.go similarity index 99% rename from pkg/templatefunc_test.go rename to pkg/server/web/templatefunc_test.go index b4c19c2e..df5cfa40 100644 --- a/pkg/templatefunc_test.go +++ b/pkg/server/web/templatefunc_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "html/template" diff --git a/pkg/tree.go b/pkg/server/web/tree.go similarity index 99% rename from pkg/tree.go rename to pkg/server/web/tree.go index 785ba6a6..7213a0c6 100644 --- a/pkg/tree.go +++ b/pkg/server/web/tree.go @@ -12,15 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "path" "regexp" "strings" - "github.com/astaxie/beego/pkg/context" - "github.com/astaxie/beego/pkg/utils" + "github.com/astaxie/beego/pkg/infrastructure/utils" + + "github.com/astaxie/beego/pkg/server/web/context" ) var ( diff --git a/pkg/tree_test.go b/pkg/server/web/tree_test.go similarity index 99% rename from pkg/tree_test.go rename to pkg/server/web/tree_test.go index 8758e0c0..d3091de0 100644 --- a/pkg/tree_test.go +++ b/pkg/server/web/tree_test.go @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "strings" "testing" - "github.com/astaxie/beego/pkg/context" + "github.com/astaxie/beego/pkg/server/web/context" ) type testinfo struct { diff --git a/pkg/unregroute_test.go b/pkg/server/web/unregroute_test.go similarity index 99% rename from pkg/unregroute_test.go rename to pkg/server/web/unregroute_test.go index 08b1b77b..c675ae7d 100644 --- a/pkg/unregroute_test.go +++ b/pkg/server/web/unregroute_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package beego +package web import ( "net/http" diff --git a/pkg/toolbox/task.go b/pkg/task/task.go similarity index 99% rename from pkg/toolbox/task.go rename to pkg/task/task.go index fb2c5f16..04185d8e 100644 --- a/pkg/toolbox/task.go +++ b/pkg/task/task.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package toolbox +package task import ( "log" diff --git a/pkg/toolbox/task_test.go b/pkg/task/task_test.go similarity index 99% rename from pkg/toolbox/task_test.go rename to pkg/task/task_test.go index b63f4391..c7360b39 100644 --- a/pkg/toolbox/task_test.go +++ b/pkg/task/task_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package toolbox +package task import ( "errors"