diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ee7e0b5a4bcdce78ab893c2e86b437848e946d8d..5035ae941cefac8bcef6608009826b1d7de231a3 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 1425a729ee96ccf1e956192ce88b2cc15a44095b..c8f2174c1b727d6a879b260e1953781cea79fa9b 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 94fc61dc17fbd0e7a4e33d3e6806aca1f9172784..60712c2fe482f55ba0de4b89bc065393d15435b5 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 b7dad8fc6edcd4f2a5e6326cf1ca7e7b06386b9d..df2ba37f9bf077e643f610ca9a90fd1d59201c3a 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 68a934bfc03d41609740ff0cf2d2726873a55336..2cd205037774392edd8ea563f8604dddd781b7b5 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 8de331ab7ed241170449f18f6010b522082f92ed..0020615751228833776fd4587cf9e33a06eeb50d 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 038b2ebe01d233267d234704c6745d4df55cc098..10ff72b0b6198ed0dc77442f265c22fa409713b8 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 7390ea941f356c81be8f3996f67ce44ea3d9dc94..bd6ede4eb28c5dc664ce4b569840727215d31b96 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 6cc4d6b0347d2418bd664d682ca8c1cd1c550166..93376843542be1e8cb0e0784ed10a018d3bf0aea 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 8849a9ad00af29b8e2fd9e2a7fe023babb432eec..469378033fd7b80c451d5d470d8ba2859a09c28a 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 e7f7316fbdf97524ab6e820abe85097bd3363a4f..917d47204e7822aca44753ac50184177ec84dca2 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 2964e6c57a53e1d9b16680c6effe10cda888639e..2964a4a2a2b37dce2b2e3109bc671b5677db046d 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 0062b857faf9dee64df900e31f08949124fe73b2..19e6cd238239fb37a98ba95abbd84fe8068be9e4 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 905c818940d449a699e487cb22db58260a90f7bb..5905325d348dcf40d2cbd6ced6fe3413b969208d 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 0a53ad317374ee6988b5973bd4934bd9adf348b4..8a5cfb1040afddec0a771bf32a0d165b234ce480 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 4a561a2773c86c0cd4eb5446a7415e129fb498f7..0043ba76c0e5f7ef136ee4da8bebc942660af7bb 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 66246ec405df802a4cf0bdc2fe3f4dacc02b4c47..d8d8c6c12e6dc46e6690b8cfcca23afb414b64b9 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 f9d379ce0a6a248ca8f19502661cf47f6fe52a1b..8cb936be52f7bd783a4d440890ac6523da91c615 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 afc428f223d4cb555d7258ef13012a12cb598abb..e27e7f3aec1d5395ed745e4f5d31e086f26bea4c 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 b3ef7415ec3224fd819bf66c6a87378e8277cd3d..a367a6e2f4a669f69c43174d18f89150cafd425a 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 2c754a3e12646f99bc7d371b4eb4241779b86995..fde7abf80d9685f7568195768703dede5b93a794 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 0b6968b793e23a8af69b07cc52068c26e7243758..1a2ee5416e2861f5111585f1cdcdb16f53abedef 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 8f6d48078fb524215b83d29142daef6ea2177442..9e89e5da9af6c948446f7485aeb7be9c39051bdf 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 fb2b473d38e8e02847bd5b9e3ad397aa209b0f03..175b26be2dc6a9e4501448842471fb43bfae4712 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 aad62c18321942ba49afd07a8b5ff919c7531f12..1b55b989d0a8c8f5b0cbd35b083d94748557aa85 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 97221a0700b42d42ba323303cded81a2f6004f93..d0c5c5376d31608bdd35c898d33ff89ba01887f6 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 47f20854f4f5558467a4dc91a39c77f628200485..7acb7d46bf16830492a15b23cc0a05455fa86dd5 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 0649ab9fd619918918d0037d061f667db3696462..4d19931256c847323657298b25fcd6397008b6a9 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 b6d3a2d9c9c04bf74f69c1ed9f24bb828a7b3426..c21352a8d744d4c5af0abec4f11a24395cd35d79 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 c62fd901f204abb640f99d552aa79104e4911783..3f740594a87afe23df4335d36273fc8a58322fa2 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 8fcd2e069c3544806ada7b11fa312ec249a8967b..8a60c36b6085f916cdd7eb236abb45f55bd9cda8 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 d7dc39159dd41fd4b4e95eae216084a968a507ad..634b189294b36adbd123df604e69194fd04f071c 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 3a50fcaebe7dcbe37164a73115cba0d6c9029c1c..906505de1904d1aca68564ce88ff99e4a0852695 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 92410eb25cc143bd836fb59cd7d6f4beb39c162f..c253914783d2aeab1276dc6fe75086bd19fb39eb 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 cbe5c9a1beaf39518fbf220a9d625b995f74948d..92374e02f70838600775d155b5376942bcccda2e 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 06ba12f25b95123fd95439350903c16662828b44..eb34e7594be7edb3960561e72f491e6e2229f9cd 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 a1cdbbb02a7885e00a733ef51d3055674b4bd24f..2e4378c8742f6fe8b7e97085b8ec02034374d676 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 - -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 +// 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 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 569ffb0dacfe0b027b7cdb0756f917b5a8d97f81..f80388f9392cc1a3e29f111b61ec5c50ab19b41c 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 5d8e47de7787003bde8e61e04d55c8c6444a2232..83155b348f409fd96eccf688ccb313751a1b4bb0 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 876077e1d613d274f4e5bf5d74ae0613a76ce1df..bd28411fcbe50779fda43a5b1bb90ef7fb62ad2f 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 da87986f1e5bbffe717cb8424ce3adc231069917..75a42145e05b37127ce193ca422eac3663ae1fe6 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 9b5ec791fc1eee10181856763d59445394b6b0e4..3413e0a5c2534927dcdc3045f2c62c2394d0a978 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 b78289335d2fd1ff252c0910bbd7ce0a542e8e49..4cd0df1fb4030fc431d5ff5b8b7762738b12ab83 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 5c77e88f127c640dfe3b58eba6b6a2cbe2c7c0cb..9a3b698a4ac647d50095ae20a1c01d0de03884a7 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 0e76457fc0a8286eb7b3c582c62f0987e560003f..2437d6c794748e6283d10151242a5d55a8cc36a3 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 e3544b3ad46cd7a8dd93dba41a1f201b4d37249b..a91f09fa07e2771ee195dfefb5f856f077ab2aa3 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 06e40ede73f7976cdae4d0cc80827155ba423993..c40cf6baba57090f7a67e95561f3f8805e274364 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 07a20c4eeace9661cf546e55df7152c42546d3c2..530b063767e668f0ababce580cd6b93c464b4acb 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 6c1464f253a03f23fe451977b499f022f4ead3fb..02e6f9959e900ac89222448ecd02231d43c4ed1d 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 5c91b2ed1696f6012821e7ea9cfb967912174eed..c2631584bcdb1c240f260b69f100dae937f4797d 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 b824a93883b3cd478d0c13423de1fdefbb15f9d8..378cfc9f37cde212bc01c1a2d2df0581178b6d23 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 e43d70a0f8200e3d858e5335b726453f04783ff2..96e6efa3a3b765e860a156eae87785ff1211c081 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 7fab842ae6439e75df9b4928662c5ac11d3239ee..0758c43f00f842ba201bd409f9557da622835ce0 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 c641a4bf6f90d40c5ed7f08430e3e2d12703dc66..2dadd317030fe2c3eaf477a7d3547f24087ef28b 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 688c0e361a7ea226a2c60b404c1fcec31fb1ae95..adcf647bdfb2e0876101149103b70c64293f5e0b 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 b68ee012f686e65a88664023208aa78c39714836..e775102c8a9b760878c780e1635fe55a559c1f77 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 db5bb2c767d9d18febbdf980f32c1781c4457342..ef466eab74c24165530825c519033d816013ff62 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 dcdfae85f543fa93a30489b39d6f29d7b946cbad..40487d769d924e2d7c9cb5ac792478de30b91716 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 6721539a1e3d89ea96c4bbace3f98ee454062728..1f6ebaa7416122f51584db7c193653fa649777e6 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 bd31741fc202e98a0cfe1dcfb145afb95ca9783e..0dc3520ac97ab03a06b6f213540230ba0f6dfeee 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 5b70afa82587cdfd2bb0b33be982bc4b9a8eb78a..906e1c4b2059a144738ec417d7e8db8ece82431f 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 f950b8358a440e28d3c8c288afe8c59773418c86..77d0c5c2bb27f02ab7a5e9deac481ad728d623e3 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 80797aa927bdac838b79565ccd7a7362918bf6b0..f4e6c4d49f3bbe5dc0df6c177329ce2107eeaa2a 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 7b52a3000c3ae00736c6c6f7ecef8e740c37853d..4c9643dc6be2e811ee6e2055765d3e61ce8b06a8 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 718f5e7a1078e3a47be3bcf6fe6867fd2f2498e5..86a2ba5d9dd0e2a0233163b7c9b6e2664bfd2f61 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 0000000000000000000000000000000000000000..579b292a2da58420df5ea63554abb43365c71c46 --- /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 534a371ee796c2d8311aa241b3a0bafe100b1cf3..94152b89da59ed19bebc7d130860c61e498dd3a7 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 4d8b256f9e865232ad19b69b5918f1de076ce3dd..aace3d9e51ad6e71ec7ed6a20b32b9faadffddaf 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 5094aeed2fd4789ca383ad1313e023b34c22425b..acc67aeb1b809b2aa49365f02c9bb44f8a0b8807 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 cdcdef33f247c83a59ec5aa29fe2cc45230a8944..de8c9455fd71c62de8a4fdd29f0ee50ca618d797 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 ea71ce4e7355b80f04443b22aa39d8671e72b84f..e61084a5b061193854f1c9c843f57c321644e0cc 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 c08ae5282a7c3456e89f1039b005faccdf644386..76e7b85ea5ed64e3d8b084286d62c5f2c15f3208 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 c31152ea377ade14aea1f5fd3f89f5141a4338e8..53351c11ba2929a95cd8795c1965635f23fdc80e 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 62fc26cf877eae16ef65a89b361eb67f74064548..2ae1fb8fe6d6708d82d76bb801801e24735d9968 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 73d3361b827e409775d4bdc09b4d8f6b2871f27e..36cba386e5a008cad99f23b2fc2b703b4f8e22b4 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 e8bde70523ae14019863221295aeb7baaa92efb8..3abe255e419027e6092e98a481da2e82a61eeba7 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 c810a9e3ccffcfd6a1f179fd1b2c523a04415989..1d6de695f69a613ef55f888eb562861f049fbf5e 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 f7b325a94b8b31e9dcddcde72f5941ed22c84b22..78e0a6d60ce4a092dbb7f7b2d19686ee3c6e6594 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 5ff85f436c00219df23dfc26f4048f8bac61f85e..b8272f647f1108d76e8e5e13a92eb1c3b1f81145 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 d96f964c8607e317ead8143706720883e13c2835..a96dacdd1cdb0017ec0c01bba446c438f1a3c681 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 f3989a764f8f3a781426575fceec74bdf5c691cc..6b71d61723303c4731596cd9c8bce435b83f0fc3 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 97f1e964f4a32f53b77595919e90c9530de90cac..46da362941439cbc2ca6f07b5f7323e675b98a48 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 0000000000000000000000000000000000000000..0ab10bfdc7ff7cfbef42662a5cf5a25ea4635c7f --- /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 aff984c041b53a2bfda985991a9717eaa2c35799..b62fb70d27c82af4981ee7519fb601bb677a0049 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 378aa9538a74b5db81fd7b57bbdcf8d542b3386e..2685a9856b871337686e3102f2dd9fd0b3c1b964 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 911cb8480a50ff9241445185505616419bd1aa2f..8d3acb24227b99222a48e83d9ae272ab376426eb 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 7b1d4405419165062e50e1d491a3d6480867bff8..ba56030b4d42591c170d407ca63b434bad4bc93b 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 d84b8df2d3c5fbc0e6d9bb17a9c700ed5f637b14..209cd97da986a9a11b1e375bb81037025ec4b8d9 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 47a20c8a85ef3a35622db2bc53d4a72b32dbea27..a3a8dca6a95a11f3fac8c2c4bb6e0beac762773c 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 6cc081f30f7b89a1ccd90bd443796cd6c355d115..e50596b4362a2d171bafecacb181f797fed4af8c 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 18bf2bece195753c8316cc7ca05567dbb36ed200..800eededbad797009edd27d4ef22e75faef7963c 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 664d35a706e9f0e9929a8696f6fc3cfd4766519f..60659fdd5bcac296df8248c284a76ac2c170db86 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 e6ee91503c1e1ee3b5b81bf720fc779b22f4b926..dd5663f973c39e40999ce8a0006a5f52a5803b4b 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 750ea7a9b289620eb1223bd7daf4b95c2f54a0b5..04f44324e883f61c60b555633043dfd6097339ee 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 8f4b46e3c344f81026c2b760b598900394eaf897..f4231c7381229c0fb42848ca45e7cdccdb59bb2b 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 822892bc43cdeab5e1927b7b4be5f6d93492fee0..08887839b9d7172f4ba9bef1a0a638d2ab02039b 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 f1f86088b9519bb563cf10ab863b11d4f90a2d1a..44d5f71ef48459c4974eab8cd8573023cd3008fe 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 3a1bcb0723687d5a15ab59ed26b37ccc816fa6e0..eea505348488a321339712e27c629f4e19b4a433 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 a6485a17e26c444d4fd441298f4fa42ea73f1a0a..55f6435d6cb7d94fe5bb23c82a9dd6613e8b97a1 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 d5e9608dc9d42f4a56bfc90c4edf29e308b11eb6..2deef54e734115fbe4b03e9657c1aeab0164540e 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 41cc6f6e0dd45ba89195101b0c6982dda12a237f..5457457a008437ab3c454d064a0748576f75cc50 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 3f778cdcf8e284258b8ee8e82b9b64f31a1817ee..13194733191c6c5541ed1a9e303d7917c63fade1 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 ca2878ab25c7b1e9bdf83f9ed8fdfcf24c383c31..9393e9c7b9aa6c66fe361fbc53a610048d9c866f 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 bda18f4b1b36eb9b5a5e43e1c5cb3d7279edf2cd..e59f38c52190a602fb7743ae56b5e75878bc00ad 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 bdf33b4f211a9f78623ff885e4437610dc9341ad..39d60041f18a74037325ad6f0115e15af085653b 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 b5b09a2f81bae1c77dfe62480bd681acccafdb81..530a72ff5988f62a956341490aa412a53ecaeafa 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 bee45d7bfe0a94533720f1bbd7f38c0b90ade2d5..ce63a0be0c7a1355164476c4faecdd62cb4b5069 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 4af240f1c258ab1f107599954cccf2720f0e94b3..2099f99d16c51cfb6fca1d87b03dbb9692bc360f 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 6b25d7e33218b4de55c4e1416d27fa01e2194c91..9b70753e555a6e9b9ba0915a8f83f28700bdf6d1 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 8a7862f61443634159230af6b31aa57330d9ada6..14ad1484d7714df3c08dac70fbf5c9c5aa7fd0d0 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 f8b17fc5c970bf0225f2f23a455271d0d3513e85..7b9942f4147053c830e65dd3cedb190bec794a08 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 e46c13ec27a65f33dba42fa2b8c06093db35e533..0725a2f856b3851320809da5a77540ab75bd90dc 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 fd73dfb38482d99fc1902ca18fa1f1d4108666d1..ccc3a1fc0b09bd297fc04156642c012233212fd5 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 ac29476c0a6af2252ece63f52f776868cb0e8afe..7c83e15a0699818ac02b59be46e8b7d39302e86d 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 8edd9dc180c29076d52f13115f1dd15613092287..a4b8db993fb5165c38a2eaf8c46f7f3c9fc9fe21 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 134c2cb2bb68721310a6a880e129dd85dfbe388d..b542494dc219e61f38bce24cf14951d83cbfaa75 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 6f02b8d65ac3d844064df97717615d3bbbd2deca..6d132bf0232803028d02e8da9255c4b816b6dc03 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 b4c19c2ef78ad18f537c4c54265d70e2f8352354..df5cfa40910fbe7b919ce44ff92740ef4d990083 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 785ba6a6a26acb24a652fe76d6541d329112d207..7213a0c642ae76f34ee92037bf8d9362a0de3141 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 8758e0c01563d13dceaec1fb9ef82952363a8946..d3091de006887c39c6da15f1b970d93bf720a66b 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 08b1b77b226321bd27cf8907af1df73c59455f4e..c675ae7df5a2d7241110dcffe970666bcf76e380 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 fb2c5f168eadf24d537240979c2763e72967f02f..04185d8e217976e99f6960fa3299b34ccb376a58 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 b63f439130b6768742268596acb2456f6a1adc46..c7360b39b81c64b3b63d36c9cdf00f5567192395 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"