From 0897f60c5d00969891731190a7f74c72a33df03d Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 31 Jul 2020 11:14:48 +0800 Subject: [PATCH] rename ngin to rest --- .golangci.yml | 2 +- core/discov/subscriber_test.go | 1 + example/graceful/dns/api/config/config.go | 4 ++-- example/graceful/dns/api/graceful.go | 4 ++-- .../dns/api/handler/gracefulhandler.go | 2 +- example/graceful/dns/api/handler/routes.go | 6 +++--- example/graceful/etcd/api/config/config.go | 4 ++-- example/graceful/etcd/api/graceful.go | 4 ++-- .../etcd/api/handler/gracefulhandler.go | 2 +- example/graceful/etcd/api/handler/routes.go | 6 +++--- example/http/breaker/server.go | 8 ++++---- example/http/demo/main.go | 8 ++++---- example/http/post/main.go | 10 +++++----- example/http/shedding/main.go | 8 ++++---- example/http/signature/server/server.go | 12 ++++++------ example/jwt/user/user.go | 18 +++++++++--------- example/load/simulate/server/server.go | 6 +++--- example/tracing/edge/main.go | 8 ++++---- {ngin => rest}/config.go | 10 ++++++++-- {ngin => rest}/etc/config.json | 0 {ngin => rest}/handler/authhandler.go | 2 +- {ngin => rest}/handler/authhandler_test.go | 0 {ngin => rest}/handler/breakerhandler.go | 4 ++-- {ngin => rest}/handler/breakerhandler_test.go | 0 .../handler/contentsecurityhandler.go | 4 ++-- .../handler/contentsecurityhandler_test.go | 2 +- {ngin => rest}/handler/cryptionhandler.go | 0 {ngin => rest}/handler/cryptionhandler_test.go | 0 {ngin => rest}/handler/gunziphandler.go | 2 +- {ngin => rest}/handler/gunziphandler_test.go | 2 +- {ngin => rest}/handler/loghandler.go | 2 +- {ngin => rest}/handler/loghandler_test.go | 2 +- {ngin => rest}/handler/maxbyteshandler.go | 2 +- {ngin => rest}/handler/maxbyteshandler_test.go | 0 {ngin => rest}/handler/maxconnshandler.go | 2 +- {ngin => rest}/handler/maxconnshandler_test.go | 0 {ngin => rest}/handler/metrichandler.go | 0 {ngin => rest}/handler/metrichandler_test.go | 0 {ngin => rest}/handler/prommetrichandler.go | 2 +- .../handler/prommetrichandler_test.go | 0 {ngin => rest}/handler/recoverhandler.go | 2 +- {ngin => rest}/handler/recoverhandler_test.go | 0 {ngin => rest}/handler/sheddinghandler.go | 4 ++-- {ngin => rest}/handler/sheddinghandler_test.go | 0 {ngin => rest}/handler/timeouthandler.go | 0 {ngin => rest}/handler/timeouthandler_test.go | 0 {ngin => rest}/handler/tracinghandler.go | 0 {ngin => rest}/handler/tracinghandler_test.go | 0 {ngin => rest}/httpx/constants.go | 0 {ngin => rest}/httpx/requests.go | 2 +- {ngin => rest}/httpx/requests_test.go | 2 +- {ngin => rest}/httpx/responses.go | 0 {ngin => rest}/httpx/responses_test.go | 0 {ngin => rest}/internal/context/params.go | 0 {ngin => rest}/internal/log.go | 0 {ngin => rest}/internal/log_test.go | 0 {ngin => rest}/internal/router/patrouter.go | 2 +- .../internal/router/patrouter_test.go | 2 +- {ngin => rest}/internal/router/router.go | 0 .../internal/security/contentsecurity.go | 2 +- .../security/withcoderesponsewriter.go | 0 {ngin => rest}/internal/server.go | 0 {ngin => rest}/internal/starter.go | 0 {ngin => rest}/internal/tokenparser.go | 0 {ngin => rest}/internal/tokenparser_test.go | 0 {ngin => rest}/internal/util.go | 0 {ngin => rest}/internal/util_test.go | 0 {ngin => rest}/ngin.go | 10 +++++----- {ngin => rest}/ngin_test.go | 6 +++--- {ngin => rest}/server.go | 12 ++++++------ {ngin => rest}/types.go | 2 +- tools/goctl/api/demo/config/config.go | 4 ++-- tools/goctl/api/demo/demo.go | 4 ++-- tools/goctl/api/demo/handler/getuserhandler.go | 2 +- tools/goctl/api/demo/handler/handlers.go | 6 +++--- tools/goctl/api/gogen/genconfig.go | 4 ++-- tools/goctl/api/gogen/genmain.go | 4 ++-- tools/goctl/api/gogen/genroutes.go | 10 +++++----- 78 files changed, 118 insertions(+), 111 deletions(-) rename {ngin => rest}/config.go (74%) rename {ngin => rest}/etc/config.json (100%) rename {ngin => rest}/handler/authhandler.go (99%) rename {ngin => rest}/handler/authhandler_test.go (100%) rename {ngin => rest}/handler/breakerhandler.go (94%) rename {ngin => rest}/handler/breakerhandler_test.go (100%) rename {ngin => rest}/handler/contentsecurityhandler.go (97%) rename {ngin => rest}/handler/contentsecurityhandler_test.go (99%) rename {ngin => rest}/handler/cryptionhandler.go (100%) rename {ngin => rest}/handler/cryptionhandler_test.go (100%) rename {ngin => rest}/handler/gunziphandler.go (96%) rename {ngin => rest}/handler/gunziphandler_test.go (98%) rename {ngin => rest}/handler/loghandler.go (99%) rename {ngin => rest}/handler/loghandler_test.go (98%) rename {ngin => rest}/handler/maxbyteshandler.go (96%) rename {ngin => rest}/handler/maxbyteshandler_test.go (100%) rename {ngin => rest}/handler/maxconnshandler.go (97%) rename {ngin => rest}/handler/maxconnshandler_test.go (100%) rename {ngin => rest}/handler/metrichandler.go (100%) rename {ngin => rest}/handler/metrichandler_test.go (100%) rename {ngin => rest}/handler/prommetrichandler.go (97%) rename {ngin => rest}/handler/prommetrichandler_test.go (100%) rename {ngin => rest}/handler/recoverhandler.go (94%) rename {ngin => rest}/handler/recoverhandler_test.go (100%) rename {ngin => rest}/handler/sheddinghandler.go (95%) rename {ngin => rest}/handler/sheddinghandler_test.go (100%) rename {ngin => rest}/handler/timeouthandler.go (100%) rename {ngin => rest}/handler/timeouthandler_test.go (100%) rename {ngin => rest}/handler/tracinghandler.go (100%) rename {ngin => rest}/handler/tracinghandler_test.go (100%) rename {ngin => rest}/httpx/constants.go (100%) rename {ngin => rest}/httpx/requests.go (98%) rename {ngin => rest}/httpx/requests_test.go (99%) rename {ngin => rest}/httpx/responses.go (100%) rename {ngin => rest}/httpx/responses_test.go (100%) rename {ngin => rest}/internal/context/params.go (100%) rename {ngin => rest}/internal/log.go (100%) rename {ngin => rest}/internal/log_test.go (100%) rename {ngin => rest}/internal/router/patrouter.go (98%) rename {ngin => rest}/internal/router/patrouter_test.go (99%) rename {ngin => rest}/internal/router/router.go (100%) rename {ngin => rest}/internal/security/contentsecurity.go (99%) rename {ngin => rest}/internal/security/withcoderesponsewriter.go (100%) rename {ngin => rest}/internal/server.go (100%) rename {ngin => rest}/internal/starter.go (100%) rename {ngin => rest}/internal/tokenparser.go (100%) rename {ngin => rest}/internal/tokenparser_test.go (100%) rename {ngin => rest}/internal/util.go (100%) rename {ngin => rest}/internal/util_test.go (100%) rename {ngin => rest}/ngin.go (94%) rename {ngin => rest}/ngin_test.go (95%) rename {ngin => rest}/server.go (97%) rename {ngin => rest}/types.go (96%) diff --git a/.golangci.yml b/.golangci.yml index d726d16a..cf53afb7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,7 +9,7 @@ run: - example - kmq - kq - - ngin + - rest - rq - rpcx # - service diff --git a/core/discov/subscriber_test.go b/core/discov/subscriber_test.go index 564945e4..6a147c3a 100644 --- a/core/discov/subscriber_test.go +++ b/core/discov/subscriber_test.go @@ -184,6 +184,7 @@ func TestContainer(t *testing.T) { }) } } + assert.True(t, c.dirty.True()) assert.ElementsMatch(t, test.expect, c.getValues()) assert.False(t, c.dirty.True()) diff --git a/example/graceful/dns/api/config/config.go b/example/graceful/dns/api/config/config.go index 6ae5af47..daf38faa 100644 --- a/example/graceful/dns/api/config/config.go +++ b/example/graceful/dns/api/config/config.go @@ -1,11 +1,11 @@ package config import ( - "zero/ngin" + "zero/rest" "zero/rpcx" ) type Config struct { - ngin.NgConf + rest.RtConf Rpc rpcx.RpcClientConf } diff --git a/example/graceful/dns/api/graceful.go b/example/graceful/dns/api/graceful.go index a9c0efea..70ed8f20 100644 --- a/example/graceful/dns/api/graceful.go +++ b/example/graceful/dns/api/graceful.go @@ -7,7 +7,7 @@ import ( "zero/example/graceful/dns/api/config" "zero/example/graceful/dns/api/handler" "zero/example/graceful/dns/api/svc" - "zero/ngin" + "zero/rest" "zero/rpcx" ) @@ -24,7 +24,7 @@ func main() { Client: client, } - engine := ngin.MustNewEngine(c.NgConf) + engine := rest.MustNewEngine(c.RtConf) defer engine.Stop() handler.RegisterHandlers(engine, ctx) diff --git a/example/graceful/dns/api/handler/gracefulhandler.go b/example/graceful/dns/api/handler/gracefulhandler.go index 1332a1d0..830857c2 100644 --- a/example/graceful/dns/api/handler/gracefulhandler.go +++ b/example/graceful/dns/api/handler/gracefulhandler.go @@ -12,7 +12,7 @@ import ( "zero/example/graceful/dns/api/svc" "zero/example/graceful/dns/api/types" "zero/example/graceful/dns/rpc/graceful" - "zero/ngin/httpx" + "zero/rest/httpx" ) func gracefulHandler(ctx *svc.ServiceContext) http.HandlerFunc { diff --git a/example/graceful/dns/api/handler/routes.go b/example/graceful/dns/api/handler/routes.go index 6d2dca1c..45f95d02 100644 --- a/example/graceful/dns/api/handler/routes.go +++ b/example/graceful/dns/api/handler/routes.go @@ -5,11 +5,11 @@ import ( "net/http" "zero/example/graceful/dns/api/svc" - "zero/ngin" + "zero/rest" ) -func RegisterHandlers(engine *ngin.Engine, ctx *svc.ServiceContext) { - engine.AddRoutes([]ngin.Route{ +func RegisterHandlers(engine *rest.Engine, ctx *svc.ServiceContext) { + engine.AddRoutes([]rest.Route{ { Method: http.MethodGet, Path: "/api/graceful", diff --git a/example/graceful/etcd/api/config/config.go b/example/graceful/etcd/api/config/config.go index 6ae5af47..daf38faa 100644 --- a/example/graceful/etcd/api/config/config.go +++ b/example/graceful/etcd/api/config/config.go @@ -1,11 +1,11 @@ package config import ( - "zero/ngin" + "zero/rest" "zero/rpcx" ) type Config struct { - ngin.NgConf + rest.RtConf Rpc rpcx.RpcClientConf } diff --git a/example/graceful/etcd/api/graceful.go b/example/graceful/etcd/api/graceful.go index 539ec141..7553e4e5 100644 --- a/example/graceful/etcd/api/graceful.go +++ b/example/graceful/etcd/api/graceful.go @@ -7,7 +7,7 @@ import ( "zero/example/graceful/etcd/api/config" "zero/example/graceful/etcd/api/handler" "zero/example/graceful/etcd/api/svc" - "zero/ngin" + "zero/rest" "zero/rpcx" ) @@ -24,7 +24,7 @@ func main() { Client: client, } - engine := ngin.MustNewEngine(c.NgConf) + engine := rest.MustNewEngine(c.RtConf) defer engine.Stop() handler.RegisterHandlers(engine, ctx) diff --git a/example/graceful/etcd/api/handler/gracefulhandler.go b/example/graceful/etcd/api/handler/gracefulhandler.go index 04d49c1d..bea35a76 100644 --- a/example/graceful/etcd/api/handler/gracefulhandler.go +++ b/example/graceful/etcd/api/handler/gracefulhandler.go @@ -12,7 +12,7 @@ import ( "zero/example/graceful/etcd/api/svc" "zero/example/graceful/etcd/api/types" "zero/example/graceful/etcd/rpc/graceful" - "zero/ngin/httpx" + "zero/rest/httpx" ) func gracefulHandler(ctx *svc.ServiceContext) http.HandlerFunc { diff --git a/example/graceful/etcd/api/handler/routes.go b/example/graceful/etcd/api/handler/routes.go index a519075b..e067a308 100644 --- a/example/graceful/etcd/api/handler/routes.go +++ b/example/graceful/etcd/api/handler/routes.go @@ -5,11 +5,11 @@ import ( "net/http" "zero/example/graceful/etcd/api/svc" - "zero/ngin" + "zero/rest" ) -func RegisterHandlers(engine *ngin.Engine, ctx *svc.ServiceContext) { - engine.AddRoutes([]ngin.Route{ +func RegisterHandlers(engine *rest.Engine, ctx *svc.ServiceContext) { + engine.AddRoutes([]rest.Route{ { Method: http.MethodGet, Path: "/api/graceful", diff --git a/example/http/breaker/server.go b/example/http/breaker/server.go index dee0df39..cd2e4ebe 100644 --- a/example/http/breaker/server.go +++ b/example/http/breaker/server.go @@ -9,13 +9,13 @@ import ( "zero/core/service" "zero/core/stat" "zero/core/syncx" - "zero/ngin" + "zero/rest" ) func main() { logx.Disable() stat.SetReporter(nil) - server := ngin.MustNewEngine(ngin.NgConf{ + server := rest.MustNewEngine(rest.RtConf{ ServiceConf: service.ServiceConf{ Name: "breaker", Log: logx.LogConf{ @@ -28,7 +28,7 @@ func main() { Timeout: 3000, }) latch := syncx.NewLimit(10) - server.AddRoute(ngin.Route{ + server.AddRoute(rest.Route{ Method: http.MethodGet, Path: "/heavy", Handler: func(w http.ResponseWriter, r *http.Request) { @@ -47,7 +47,7 @@ func main() { } }, }) - server.AddRoute(ngin.Route{ + server.AddRoute(rest.Route{ Method: http.MethodGet, Path: "/good", Handler: func(w http.ResponseWriter, r *http.Request) { diff --git a/example/http/demo/main.go b/example/http/demo/main.go index 1c42e1d2..fbc4d70a 100644 --- a/example/http/demo/main.go +++ b/example/http/demo/main.go @@ -6,8 +6,8 @@ import ( "zero/core/logx" "zero/core/service" - "zero/ngin" - "zero/ngin/httpx" + "zero/rest" + "zero/rest/httpx" ) var ( @@ -47,7 +47,7 @@ func handle(w http.ResponseWriter, r *http.Request) { func main() { flag.Parse() - engine := ngin.MustNewEngine(ngin.NgConf{ + engine := rest.MustNewEngine(rest.RtConf{ ServiceConf: service.ServiceConf{ Log: logx.LogConf{ Mode: "console", @@ -61,7 +61,7 @@ func main() { engine.Use(first) engine.Use(second) - engine.AddRoute(ngin.Route{ + engine.AddRoute(rest.Route{ Method: http.MethodGet, Path: "/", Handler: handle, diff --git a/example/http/post/main.go b/example/http/post/main.go index 45b5f72e..3e41efb0 100644 --- a/example/http/post/main.go +++ b/example/http/post/main.go @@ -7,8 +7,8 @@ import ( "zero/core/logx" "zero/core/service" - "zero/ngin" - "zero/ngin/httpx" + "zero/rest" + "zero/rest/httpx" ) var ( @@ -37,7 +37,7 @@ func handlePost(w http.ResponseWriter, r *http.Request) { func main() { flag.Parse() - engine := ngin.MustNewEngine(ngin.NgConf{ + engine := rest.MustNewEngine(rest.RtConf{ ServiceConf: service.ServiceConf{ Log: logx.LogConf{ Mode: "console", @@ -51,12 +51,12 @@ func main() { }) defer engine.Stop() - engine.AddRoute(ngin.Route{ + engine.AddRoute(rest.Route{ Method: http.MethodGet, Path: "/", Handler: handleGet, }) - engine.AddRoute(ngin.Route{ + engine.AddRoute(rest.Route{ Method: http.MethodPost, Path: "/", Handler: handlePost, diff --git a/example/http/shedding/main.go b/example/http/shedding/main.go index d5cda076..01ad3c9d 100644 --- a/example/http/shedding/main.go +++ b/example/http/shedding/main.go @@ -8,8 +8,8 @@ import ( "zero/core/logx" "zero/core/service" - "zero/ngin" - "zero/ngin/httpx" + "zero/rest" + "zero/rest/httpx" ) var ( @@ -42,7 +42,7 @@ func main() { flag.Parse() logx.Disable() - engine := ngin.MustNewEngine(ngin.NgConf{ + engine := rest.MustNewEngine(rest.RtConf{ ServiceConf: service.ServiceConf{ Log: logx.LogConf{ Mode: "console", @@ -54,7 +54,7 @@ func main() { }) defer engine.Stop() - engine.AddRoute(ngin.Route{ + engine.AddRoute(rest.Route{ Method: http.MethodGet, Path: "/", Handler: handle, diff --git a/example/http/signature/server/server.go b/example/http/signature/server/server.go index 44c5152b..753261c3 100644 --- a/example/http/signature/server/server.go +++ b/example/http/signature/server/server.go @@ -7,8 +7,8 @@ import ( "zero/core/logx" "zero/core/service" - "zero/ngin" - "zero/ngin/httpx" + "zero/rest" + "zero/rest/httpx" ) var keyPem = flag.String("prikey", "private.pem", "the private key file") @@ -31,16 +31,16 @@ func handle(w http.ResponseWriter, r *http.Request) { func main() { flag.Parse() - engine := ngin.MustNewEngine(ngin.NgConf{ + engine := rest.MustNewEngine(rest.RtConf{ ServiceConf: service.ServiceConf{ Log: logx.LogConf{ Path: "logs", }, }, Port: 3333, - Signature: ngin.SignatureConf{ + Signature: rest.SignatureConf{ Strict: true, - PrivateKeys: []ngin.PrivateKeyConf{ + PrivateKeys: []rest.PrivateKeyConf{ { Fingerprint: "bvw8YlnSqb+PoMf3MBbLdQ==", KeyFile: *keyPem, @@ -50,7 +50,7 @@ func main() { }) defer engine.Stop() - engine.AddRoute(ngin.Route{ + engine.AddRoute(rest.Route{ Method: http.MethodPost, Path: "/a/b", Handler: handle, diff --git a/example/jwt/user/user.go b/example/jwt/user/user.go index cba8f02a..87d2cc24 100644 --- a/example/jwt/user/user.go +++ b/example/jwt/user/user.go @@ -9,8 +9,8 @@ import ( "time" "zero/core/conf" - "zero/ngin" - "zero/ngin/httpx" + "zero/rest" + "zero/rest/httpx" "github.com/dgrijalva/jwt-go" "github.com/dgrijalva/jwt-go/request" @@ -20,7 +20,7 @@ const jwtUserField = "user" type ( Config struct { - ngin.NgConf + rest.RtConf AccessSecret string AccessExpire int64 `json:",default=1209600"` // 2 weeks RefreshSecret string @@ -79,27 +79,27 @@ func main() { var c Config conf.MustLoad("user.json", &c) - engine, err := ngin.NewEngine(c.NgConf) + engine, err := rest.NewEngine(c.RtConf) if err != nil { log.Fatal(err) } defer engine.Stop() - engine.AddRoute(ngin.Route{ + engine.AddRoute(rest.Route{ Method: http.MethodPost, Path: "/login", Handler: LoginHandler(c), }) - engine.AddRoute(ngin.Route{ + engine.AddRoute(rest.Route{ Method: http.MethodGet, Path: "/resource", Handler: ProtectedHandler, - }, ngin.WithJwt(c.AccessSecret)) - engine.AddRoute(ngin.Route{ + }, rest.WithJwt(c.AccessSecret)) + engine.AddRoute(rest.Route{ Method: http.MethodPost, Path: "/refresh", Handler: RefreshHandler(c), - }, ngin.WithJwt(c.RefreshSecret)) + }, rest.WithJwt(c.RefreshSecret)) fmt.Println("Now listening...") engine.Start() diff --git a/example/load/simulate/server/server.go b/example/load/simulate/server/server.go index 0a2c4776..cbb05879 100644 --- a/example/load/simulate/server/server.go +++ b/example/load/simulate/server/server.go @@ -10,7 +10,7 @@ import ( "zero/core/logx" "zero/core/service" "zero/core/stat" - "zero/ngin" + "zero/rest" ) const duration = time.Millisecond @@ -25,7 +25,7 @@ func main() { }() logx.Disable() - engine := ngin.MustNewEngine(ngin.NgConf{ + engine := rest.MustNewEngine(rest.RtConf{ ServiceConf: service.ServiceConf{ Log: logx.LogConf{ Mode: "console", @@ -36,7 +36,7 @@ func main() { CpuThreshold: 800, }) defer engine.Stop() - engine.AddRoute(ngin.Route{ + engine.AddRoute(rest.Route{ Method: http.MethodGet, Path: "/", Handler: func(w http.ResponseWriter, r *http.Request) { diff --git a/example/tracing/edge/main.go b/example/tracing/edge/main.go index 8b530d11..87e4f4ec 100644 --- a/example/tracing/edge/main.go +++ b/example/tracing/edge/main.go @@ -9,8 +9,8 @@ import ( "zero/core/logx" "zero/core/service" "zero/example/tracing/remote/portal" - "zero/ngin" - "zero/ngin/httpx" + "zero/rest" + "zero/rest/httpx" "zero/rpcx" ) @@ -42,7 +42,7 @@ func main() { var c rpcx.RpcClientConf conf.MustLoad(*configFile, &c) client = rpcx.MustNewClient(c) - engine := ngin.MustNewEngine(ngin.NgConf{ + engine := rest.MustNewEngine(rest.RtConf{ ServiceConf: service.ServiceConf{ Log: logx.LogConf{ Mode: "console", @@ -52,7 +52,7 @@ func main() { }) defer engine.Stop() - engine.AddRoute(ngin.Route{ + engine.AddRoute(rest.Route{ Method: http.MethodGet, Path: "/", Handler: handle, diff --git a/ngin/config.go b/rest/config.go similarity index 74% rename from ngin/config.go rename to rest/config.go index ebbc1f87..dc9e9fa8 100644 --- a/ngin/config.go +++ b/rest/config.go @@ -1,4 +1,4 @@ -package ngin +package rest import ( "time" @@ -18,7 +18,13 @@ type ( PrivateKeys []PrivateKeyConf } - NgConf struct { + // why not name it as Conf, because we need to consider usage like: + // type Config struct { + // rpcx.RpcConf + // rest.RtConf + // } + // if with the name Conf, there will be two Conf inside Config. + RtConf struct { service.ServiceConf Host string `json:",default=0.0.0.0"` Port int diff --git a/ngin/etc/config.json b/rest/etc/config.json similarity index 100% rename from ngin/etc/config.json rename to rest/etc/config.json diff --git a/ngin/handler/authhandler.go b/rest/handler/authhandler.go similarity index 99% rename from ngin/handler/authhandler.go rename to rest/handler/authhandler.go index e784ecb0..4a1e0b6b 100644 --- a/ngin/handler/authhandler.go +++ b/rest/handler/authhandler.go @@ -7,7 +7,7 @@ import ( "net/http/httputil" "zero/core/logx" - "zero/ngin/internal" + "zero/rest/internal" "github.com/dgrijalva/jwt-go" ) diff --git a/ngin/handler/authhandler_test.go b/rest/handler/authhandler_test.go similarity index 100% rename from ngin/handler/authhandler_test.go rename to rest/handler/authhandler_test.go diff --git a/ngin/handler/breakerhandler.go b/rest/handler/breakerhandler.go similarity index 94% rename from ngin/handler/breakerhandler.go rename to rest/handler/breakerhandler.go index 50487148..79f1a673 100644 --- a/ngin/handler/breakerhandler.go +++ b/rest/handler/breakerhandler.go @@ -8,8 +8,8 @@ import ( "zero/core/breaker" "zero/core/logx" "zero/core/stat" - "zero/ngin/internal" - "zero/ngin/internal/security" + "zero/rest/internal" + "zero/rest/internal/security" ) const breakerSeparator = "://" diff --git a/ngin/handler/breakerhandler_test.go b/rest/handler/breakerhandler_test.go similarity index 100% rename from ngin/handler/breakerhandler_test.go rename to rest/handler/breakerhandler_test.go diff --git a/ngin/handler/contentsecurityhandler.go b/rest/handler/contentsecurityhandler.go similarity index 97% rename from ngin/handler/contentsecurityhandler.go rename to rest/handler/contentsecurityhandler.go index 8f78ff55..0051ae8f 100644 --- a/ngin/handler/contentsecurityhandler.go +++ b/rest/handler/contentsecurityhandler.go @@ -6,8 +6,8 @@ import ( "zero/core/codec" "zero/core/logx" - "zero/ngin/httpx" - "zero/ngin/internal/security" + "zero/rest/httpx" + "zero/rest/internal/security" ) const contentSecurity = "X-Content-Security" diff --git a/ngin/handler/contentsecurityhandler_test.go b/rest/handler/contentsecurityhandler_test.go similarity index 99% rename from ngin/handler/contentsecurityhandler_test.go rename to rest/handler/contentsecurityhandler_test.go index 85e84540..01bf071b 100644 --- a/ngin/handler/contentsecurityhandler_test.go +++ b/rest/handler/contentsecurityhandler_test.go @@ -18,7 +18,7 @@ import ( "time" "zero/core/codec" - "zero/ngin/httpx" + "zero/rest/httpx" "github.com/stretchr/testify/assert" ) diff --git a/ngin/handler/cryptionhandler.go b/rest/handler/cryptionhandler.go similarity index 100% rename from ngin/handler/cryptionhandler.go rename to rest/handler/cryptionhandler.go diff --git a/ngin/handler/cryptionhandler_test.go b/rest/handler/cryptionhandler_test.go similarity index 100% rename from ngin/handler/cryptionhandler_test.go rename to rest/handler/cryptionhandler_test.go diff --git a/ngin/handler/gunziphandler.go b/rest/handler/gunziphandler.go similarity index 96% rename from ngin/handler/gunziphandler.go rename to rest/handler/gunziphandler.go index 5788038d..f9bef9a5 100644 --- a/ngin/handler/gunziphandler.go +++ b/rest/handler/gunziphandler.go @@ -5,7 +5,7 @@ import ( "net/http" "strings" - "zero/ngin/httpx" + "zero/rest/httpx" ) const gzipEncoding = "gzip" diff --git a/ngin/handler/gunziphandler_test.go b/rest/handler/gunziphandler_test.go similarity index 98% rename from ngin/handler/gunziphandler_test.go rename to rest/handler/gunziphandler_test.go index a2a2b5e7..fd9b8096 100644 --- a/ngin/handler/gunziphandler_test.go +++ b/rest/handler/gunziphandler_test.go @@ -10,7 +10,7 @@ import ( "testing" "zero/core/codec" - "zero/ngin/httpx" + "zero/rest/httpx" "github.com/stretchr/testify/assert" ) diff --git a/ngin/handler/loghandler.go b/rest/handler/loghandler.go similarity index 99% rename from ngin/handler/loghandler.go rename to rest/handler/loghandler.go index 1bbe8694..e87bd16e 100644 --- a/ngin/handler/loghandler.go +++ b/rest/handler/loghandler.go @@ -13,7 +13,7 @@ import ( "zero/core/logx" "zero/core/timex" "zero/core/utils" - "zero/ngin/internal" + "zero/rest/internal" ) const slowThreshold = time.Millisecond * 500 diff --git a/ngin/handler/loghandler_test.go b/rest/handler/loghandler_test.go similarity index 98% rename from ngin/handler/loghandler_test.go rename to rest/handler/loghandler_test.go index d57ddf7d..d4569036 100644 --- a/ngin/handler/loghandler_test.go +++ b/rest/handler/loghandler_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "zero/ngin/internal" + "zero/rest/internal" "github.com/stretchr/testify/assert" ) diff --git a/ngin/handler/maxbyteshandler.go b/rest/handler/maxbyteshandler.go similarity index 96% rename from ngin/handler/maxbyteshandler.go rename to rest/handler/maxbyteshandler.go index 110ac7bc..80a7d831 100644 --- a/ngin/handler/maxbyteshandler.go +++ b/rest/handler/maxbyteshandler.go @@ -3,7 +3,7 @@ package handler import ( "net/http" - "zero/ngin/internal" + "zero/rest/internal" ) func MaxBytesHandler(n int64) func(http.Handler) http.Handler { diff --git a/ngin/handler/maxbyteshandler_test.go b/rest/handler/maxbyteshandler_test.go similarity index 100% rename from ngin/handler/maxbyteshandler_test.go rename to rest/handler/maxbyteshandler_test.go diff --git a/ngin/handler/maxconnshandler.go b/rest/handler/maxconnshandler.go similarity index 97% rename from ngin/handler/maxconnshandler.go rename to rest/handler/maxconnshandler.go index 8c43c2e9..e8f15792 100644 --- a/ngin/handler/maxconnshandler.go +++ b/rest/handler/maxconnshandler.go @@ -5,7 +5,7 @@ import ( "zero/core/logx" "zero/core/syncx" - "zero/ngin/internal" + "zero/rest/internal" ) func MaxConns(n int) func(http.Handler) http.Handler { diff --git a/ngin/handler/maxconnshandler_test.go b/rest/handler/maxconnshandler_test.go similarity index 100% rename from ngin/handler/maxconnshandler_test.go rename to rest/handler/maxconnshandler_test.go diff --git a/ngin/handler/metrichandler.go b/rest/handler/metrichandler.go similarity index 100% rename from ngin/handler/metrichandler.go rename to rest/handler/metrichandler.go diff --git a/ngin/handler/metrichandler_test.go b/rest/handler/metrichandler_test.go similarity index 100% rename from ngin/handler/metrichandler_test.go rename to rest/handler/metrichandler_test.go diff --git a/ngin/handler/prommetrichandler.go b/rest/handler/prommetrichandler.go similarity index 97% rename from ngin/handler/prommetrichandler.go rename to rest/handler/prommetrichandler.go index 66ce88ad..e0da0b35 100644 --- a/ngin/handler/prommetrichandler.go +++ b/rest/handler/prommetrichandler.go @@ -7,7 +7,7 @@ import ( "zero/core/metric" "zero/core/timex" - "zero/ngin/internal/security" + "zero/rest/internal/security" ) const serverNamespace = "http_server" diff --git a/ngin/handler/prommetrichandler_test.go b/rest/handler/prommetrichandler_test.go similarity index 100% rename from ngin/handler/prommetrichandler_test.go rename to rest/handler/prommetrichandler_test.go diff --git a/ngin/handler/recoverhandler.go b/rest/handler/recoverhandler.go similarity index 94% rename from ngin/handler/recoverhandler.go rename to rest/handler/recoverhandler.go index fed8ba02..967e260a 100644 --- a/ngin/handler/recoverhandler.go +++ b/rest/handler/recoverhandler.go @@ -5,7 +5,7 @@ import ( "net/http" "runtime/debug" - "zero/ngin/internal" + "zero/rest/internal" ) func RecoverHandler(next http.Handler) http.Handler { diff --git a/ngin/handler/recoverhandler_test.go b/rest/handler/recoverhandler_test.go similarity index 100% rename from ngin/handler/recoverhandler_test.go rename to rest/handler/recoverhandler_test.go diff --git a/ngin/handler/sheddinghandler.go b/rest/handler/sheddinghandler.go similarity index 95% rename from ngin/handler/sheddinghandler.go rename to rest/handler/sheddinghandler.go index 918cba23..ab1ae12f 100644 --- a/ngin/handler/sheddinghandler.go +++ b/rest/handler/sheddinghandler.go @@ -7,8 +7,8 @@ import ( "zero/core/load" "zero/core/logx" "zero/core/stat" - "zero/ngin/internal" - "zero/ngin/internal/security" + "zero/rest/internal" + "zero/rest/internal/security" ) const serviceType = "api" diff --git a/ngin/handler/sheddinghandler_test.go b/rest/handler/sheddinghandler_test.go similarity index 100% rename from ngin/handler/sheddinghandler_test.go rename to rest/handler/sheddinghandler_test.go diff --git a/ngin/handler/timeouthandler.go b/rest/handler/timeouthandler.go similarity index 100% rename from ngin/handler/timeouthandler.go rename to rest/handler/timeouthandler.go diff --git a/ngin/handler/timeouthandler_test.go b/rest/handler/timeouthandler_test.go similarity index 100% rename from ngin/handler/timeouthandler_test.go rename to rest/handler/timeouthandler_test.go diff --git a/ngin/handler/tracinghandler.go b/rest/handler/tracinghandler.go similarity index 100% rename from ngin/handler/tracinghandler.go rename to rest/handler/tracinghandler.go diff --git a/ngin/handler/tracinghandler_test.go b/rest/handler/tracinghandler_test.go similarity index 100% rename from ngin/handler/tracinghandler_test.go rename to rest/handler/tracinghandler_test.go diff --git a/ngin/httpx/constants.go b/rest/httpx/constants.go similarity index 100% rename from ngin/httpx/constants.go rename to rest/httpx/constants.go diff --git a/ngin/httpx/requests.go b/rest/httpx/requests.go similarity index 98% rename from ngin/httpx/requests.go rename to rest/httpx/requests.go index ab581a37..8b1b6cfc 100644 --- a/ngin/httpx/requests.go +++ b/rest/httpx/requests.go @@ -6,7 +6,7 @@ import ( "strings" "zero/core/mapping" - "zero/ngin/internal/context" + "zero/rest/internal/context" ) const ( diff --git a/ngin/httpx/requests_test.go b/rest/httpx/requests_test.go similarity index 99% rename from ngin/httpx/requests_test.go rename to rest/httpx/requests_test.go index 756b0b10..a6eb43a8 100644 --- a/ngin/httpx/requests_test.go +++ b/rest/httpx/requests_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "zero/ngin/internal/router" + "zero/rest/internal/router" "github.com/stretchr/testify/assert" ) diff --git a/ngin/httpx/responses.go b/rest/httpx/responses.go similarity index 100% rename from ngin/httpx/responses.go rename to rest/httpx/responses.go diff --git a/ngin/httpx/responses_test.go b/rest/httpx/responses_test.go similarity index 100% rename from ngin/httpx/responses_test.go rename to rest/httpx/responses_test.go diff --git a/ngin/internal/context/params.go b/rest/internal/context/params.go similarity index 100% rename from ngin/internal/context/params.go rename to rest/internal/context/params.go diff --git a/ngin/internal/log.go b/rest/internal/log.go similarity index 100% rename from ngin/internal/log.go rename to rest/internal/log.go diff --git a/ngin/internal/log_test.go b/rest/internal/log_test.go similarity index 100% rename from ngin/internal/log_test.go rename to rest/internal/log_test.go diff --git a/ngin/internal/router/patrouter.go b/rest/internal/router/patrouter.go similarity index 98% rename from ngin/internal/router/patrouter.go rename to rest/internal/router/patrouter.go index 007e23a9..2c7fdd08 100644 --- a/ngin/internal/router/patrouter.go +++ b/rest/internal/router/patrouter.go @@ -6,7 +6,7 @@ import ( "strings" "zero/core/search" - "zero/ngin/internal/context" + "zero/rest/internal/context" ) const ( diff --git a/ngin/internal/router/patrouter_test.go b/rest/internal/router/patrouter_test.go similarity index 99% rename from ngin/internal/router/patrouter_test.go rename to rest/internal/router/patrouter_test.go index aada9340..a7ad81f5 100644 --- a/ngin/internal/router/patrouter_test.go +++ b/rest/internal/router/patrouter_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" - "zero/ngin/internal/context" + "zero/rest/internal/context" ) type mockedResponseWriter struct { diff --git a/ngin/internal/router/router.go b/rest/internal/router/router.go similarity index 100% rename from ngin/internal/router/router.go rename to rest/internal/router/router.go diff --git a/ngin/internal/security/contentsecurity.go b/rest/internal/security/contentsecurity.go similarity index 99% rename from ngin/internal/security/contentsecurity.go rename to rest/internal/security/contentsecurity.go index d10ee336..bc3b9747 100644 --- a/ngin/internal/security/contentsecurity.go +++ b/rest/internal/security/contentsecurity.go @@ -15,7 +15,7 @@ import ( "zero/core/codec" "zero/core/iox" "zero/core/logx" - "zero/ngin/httpx" + "zero/rest/httpx" ) const ( diff --git a/ngin/internal/security/withcoderesponsewriter.go b/rest/internal/security/withcoderesponsewriter.go similarity index 100% rename from ngin/internal/security/withcoderesponsewriter.go rename to rest/internal/security/withcoderesponsewriter.go diff --git a/ngin/internal/server.go b/rest/internal/server.go similarity index 100% rename from ngin/internal/server.go rename to rest/internal/server.go diff --git a/ngin/internal/starter.go b/rest/internal/starter.go similarity index 100% rename from ngin/internal/starter.go rename to rest/internal/starter.go diff --git a/ngin/internal/tokenparser.go b/rest/internal/tokenparser.go similarity index 100% rename from ngin/internal/tokenparser.go rename to rest/internal/tokenparser.go diff --git a/ngin/internal/tokenparser_test.go b/rest/internal/tokenparser_test.go similarity index 100% rename from ngin/internal/tokenparser_test.go rename to rest/internal/tokenparser_test.go diff --git a/ngin/internal/util.go b/rest/internal/util.go similarity index 100% rename from ngin/internal/util.go rename to rest/internal/util.go diff --git a/ngin/internal/util_test.go b/rest/internal/util_test.go similarity index 100% rename from ngin/internal/util_test.go rename to rest/internal/util_test.go diff --git a/ngin/ngin.go b/rest/ngin.go similarity index 94% rename from ngin/ngin.go rename to rest/ngin.go index 33103acd..393493a7 100644 --- a/ngin/ngin.go +++ b/rest/ngin.go @@ -1,12 +1,12 @@ -package ngin +package rest import ( "log" "net/http" "zero/core/logx" - "zero/ngin/handler" - "zero/ngin/internal/router" + "zero/rest/handler" + "zero/rest/internal/router" ) type ( @@ -22,7 +22,7 @@ type ( } ) -func MustNewEngine(c NgConf, opts ...RunOption) *Engine { +func MustNewEngine(c RtConf, opts ...RunOption) *Engine { engine, err := NewEngine(c, opts...) if err != nil { log.Fatal(err) @@ -31,7 +31,7 @@ func MustNewEngine(c NgConf, opts ...RunOption) *Engine { return engine } -func NewEngine(c NgConf, opts ...RunOption) (*Engine, error) { +func NewEngine(c RtConf, opts ...RunOption) (*Engine, error) { if err := c.SetUp(); err != nil { return nil, err } diff --git a/ngin/ngin_test.go b/rest/ngin_test.go similarity index 95% rename from ngin/ngin_test.go rename to rest/ngin_test.go index eb0cbf86..27663288 100644 --- a/ngin/ngin_test.go +++ b/rest/ngin_test.go @@ -1,4 +1,4 @@ -package ngin +package rest import ( "fmt" @@ -7,8 +7,8 @@ import ( "net/http/httptest" "testing" - "zero/ngin/httpx" - router2 "zero/ngin/internal/router" + "zero/rest/httpx" + router2 "zero/rest/internal/router" "github.com/stretchr/testify/assert" ) diff --git a/ngin/server.go b/rest/server.go similarity index 97% rename from ngin/server.go rename to rest/server.go index 339971ed..e3f038d6 100644 --- a/ngin/server.go +++ b/rest/server.go @@ -1,4 +1,4 @@ -package ngin +package rest import ( "errors" @@ -9,9 +9,9 @@ import ( "zero/core/codec" "zero/core/load" "zero/core/stat" - "zero/ngin/handler" - "zero/ngin/internal" - "zero/ngin/internal/router" + "zero/rest/handler" + "zero/rest/internal" + "zero/rest/internal/router" "github.com/justinas/alice" ) @@ -25,7 +25,7 @@ type ( Middleware func(next http.HandlerFunc) http.HandlerFunc server struct { - conf NgConf + conf RtConf routes []featuredRoutes unauthorizedCallback handler.UnauthorizedCallback unsignedCallback handler.UnsignedCallback @@ -35,7 +35,7 @@ type ( } ) -func newServer(c NgConf) *server { +func newServer(c RtConf) *server { srv := &server{ conf: c, } diff --git a/ngin/types.go b/rest/types.go similarity index 96% rename from ngin/types.go rename to rest/types.go index f237b8ed..14602d36 100644 --- a/ngin/types.go +++ b/rest/types.go @@ -1,4 +1,4 @@ -package ngin +package rest import "net/http" diff --git a/tools/goctl/api/demo/config/config.go b/tools/goctl/api/demo/config/config.go index 5beaa249..ab02995e 100644 --- a/tools/goctl/api/demo/config/config.go +++ b/tools/goctl/api/demo/config/config.go @@ -1,7 +1,7 @@ package config -import "zero/ngin" +import "zero/rest" type Config struct { - ngin.NgConf + rest.RtConf } diff --git a/tools/goctl/api/demo/demo.go b/tools/goctl/api/demo/demo.go index 3c203a08..c7a9543e 100644 --- a/tools/goctl/api/demo/demo.go +++ b/tools/goctl/api/demo/demo.go @@ -4,7 +4,7 @@ import ( "flag" "zero/core/conf" - "zero/ngin" + "zero/rest" "zero/tools/goctl/api/demo/config" "zero/tools/goctl/api/demo/handler" ) @@ -17,7 +17,7 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - engine := ngin.MustNewEngine(c.NgConf) + engine := rest.MustNewEngine(c.RtConf) defer engine.Stop() handler.RegisterHandlers(engine) diff --git a/tools/goctl/api/demo/handler/getuserhandler.go b/tools/goctl/api/demo/handler/getuserhandler.go index 1baa717c..6dfaa748 100644 --- a/tools/goctl/api/demo/handler/getuserhandler.go +++ b/tools/goctl/api/demo/handler/getuserhandler.go @@ -3,7 +3,7 @@ package handler import ( "net/http" - "zero/ngin/httpx" + "zero/rest/httpx" ) type ( diff --git a/tools/goctl/api/demo/handler/handlers.go b/tools/goctl/api/demo/handler/handlers.go index 24e71299..04220fea 100644 --- a/tools/goctl/api/demo/handler/handlers.go +++ b/tools/goctl/api/demo/handler/handlers.go @@ -3,11 +3,11 @@ package handler import ( "net/http" - "zero/ngin" + "zero/rest" ) -func RegisterHandlers(engine *ngin.Engine) { - engine.AddRoutes([]ngin.Route{ +func RegisterHandlers(engine *rest.Engine) { + engine.AddRoutes([]rest.Route{ { Method: http.MethodGet, Path: "/", diff --git a/tools/goctl/api/gogen/genconfig.go b/tools/goctl/api/gogen/genconfig.go index 1bc808d0..129f3d02 100644 --- a/tools/goctl/api/gogen/genconfig.go +++ b/tools/goctl/api/gogen/genconfig.go @@ -13,12 +13,12 @@ const ( configTemplate = `package config import ( - "zero/ngin" + "zero/rest" {{.authImport}} ) type Config struct { - ngin.NgConf + rest.RtConf } ` ) diff --git a/tools/goctl/api/gogen/genmain.go b/tools/goctl/api/gogen/genmain.go index f03b95ab..750a5b75 100644 --- a/tools/goctl/api/gogen/genmain.go +++ b/tools/goctl/api/gogen/genmain.go @@ -30,7 +30,7 @@ func main() { ctx := svc.NewServiceContext(c) - engine := ngin.MustNewEngine(c.NgConf) + engine := rest.MustNewEngine(c.RtConf) defer engine.Stop() handler.RegisterHandlers(engine, ctx) @@ -75,7 +75,7 @@ func genMain(dir string, api *spec.ApiSpec) error { func genMainImports(parentPkg string) string { imports := []string{ `"zero/core/conf"`, - `"zero/ngin"`, + `"zero/rest"`, } imports = append(imports, fmt.Sprintf("\"%s\"", path.Join(parentPkg, configDir))) imports = append(imports, fmt.Sprintf("\"%s\"", path.Join(parentPkg, handlerDir))) diff --git a/tools/goctl/api/gogen/genroutes.go b/tools/goctl/api/gogen/genroutes.go index cc848334..79c40b93 100644 --- a/tools/goctl/api/gogen/genroutes.go +++ b/tools/goctl/api/gogen/genroutes.go @@ -26,12 +26,12 @@ import ( {{.importPackages}} ) -func RegisterHandlers(engine *ngin.Engine, serverCtx *svc.ServiceContext) { +func RegisterHandlers(engine *rest.Engine, serverCtx *svc.ServiceContext) { {{.routesAdditions}} } ` routesAdditionTemplate = ` - engine.AddRoutes([]ngin.Route{ + engine.AddRoutes([]rest.Route{ {{.routes}} }{{.jwt}}{{.signature}}) ` @@ -80,11 +80,11 @@ func genRoutes(dir string, api *spec.ApiSpec) error { } jwt := "" if g.jwtEnabled { - jwt = fmt.Sprintf(", ngin.WithJwt(serverCtx.Config.%s.AccessSecret)", g.authName) + jwt = fmt.Sprintf(", rest.WithJwt(serverCtx.Config.%s.AccessSecret)", g.authName) } signature := "" if g.signatureEnabled { - signature = fmt.Sprintf(", ngin.WithSignature(serverCtx.Config.%s.Signature)", g.authName) + signature = fmt.Sprintf(", rest.WithSignature(serverCtx.Config.%s.Signature)", g.authName) } if err := gt.Execute(&builder, map[string]string{ "routes": strings.TrimSpace(gbuilder.String()), @@ -130,7 +130,7 @@ func genRoutes(dir string, api *spec.ApiSpec) error { func genRouteImports(parentPkg string, api *spec.ApiSpec) string { var importSet = collection.NewSet() - importSet.AddStr(`"zero/ngin"`) + importSet.AddStr(`"zero/rest"`) importSet.AddStr(fmt.Sprintf("\"%s\"", path.Join(parentPkg, contextDir))) for _, group := range api.Service.Groups { for _, route := range group.Routes {