kevin 3 лет назад
Родитель
Сommit
0897f60c5d
78 измененных файлов с 118 добавлено и 111 удалено
  1. 1 1
      .golangci.yml
  2. 1 0
      core/discov/subscriber_test.go
  3. 2 2
      example/graceful/dns/api/config/config.go
  4. 2 2
      example/graceful/dns/api/graceful.go
  5. 1 1
      example/graceful/dns/api/handler/gracefulhandler.go
  6. 3 3
      example/graceful/dns/api/handler/routes.go
  7. 2 2
      example/graceful/etcd/api/config/config.go
  8. 2 2
      example/graceful/etcd/api/graceful.go
  9. 1 1
      example/graceful/etcd/api/handler/gracefulhandler.go
  10. 3 3
      example/graceful/etcd/api/handler/routes.go
  11. 4 4
      example/http/breaker/server.go
  12. 4 4
      example/http/demo/main.go
  13. 5 5
      example/http/post/main.go
  14. 4 4
      example/http/shedding/main.go
  15. 6 6
      example/http/signature/server/server.go
  16. 9 9
      example/jwt/user/user.go
  17. 3 3
      example/load/simulate/server/server.go
  18. 4 4
      example/tracing/edge/main.go
  19. 8 2
      rest/config.go
  20. 0 0
      rest/etc/config.json
  21. 1 1
      rest/handler/authhandler.go
  22. 0 0
      rest/handler/authhandler_test.go
  23. 2 2
      rest/handler/breakerhandler.go
  24. 0 0
      rest/handler/breakerhandler_test.go
  25. 2 2
      rest/handler/contentsecurityhandler.go
  26. 1 1
      rest/handler/contentsecurityhandler_test.go
  27. 0 0
      rest/handler/cryptionhandler.go
  28. 0 0
      rest/handler/cryptionhandler_test.go
  29. 1 1
      rest/handler/gunziphandler.go
  30. 1 1
      rest/handler/gunziphandler_test.go
  31. 1 1
      rest/handler/loghandler.go
  32. 1 1
      rest/handler/loghandler_test.go
  33. 1 1
      rest/handler/maxbyteshandler.go
  34. 0 0
      rest/handler/maxbyteshandler_test.go
  35. 1 1
      rest/handler/maxconnshandler.go
  36. 0 0
      rest/handler/maxconnshandler_test.go
  37. 0 0
      rest/handler/metrichandler.go
  38. 0 0
      rest/handler/metrichandler_test.go
  39. 1 1
      rest/handler/prommetrichandler.go
  40. 0 0
      rest/handler/prommetrichandler_test.go
  41. 1 1
      rest/handler/recoverhandler.go
  42. 0 0
      rest/handler/recoverhandler_test.go
  43. 2 2
      rest/handler/sheddinghandler.go
  44. 0 0
      rest/handler/sheddinghandler_test.go
  45. 0 0
      rest/handler/timeouthandler.go
  46. 0 0
      rest/handler/timeouthandler_test.go
  47. 0 0
      rest/handler/tracinghandler.go
  48. 0 0
      rest/handler/tracinghandler_test.go
  49. 0 0
      rest/httpx/constants.go
  50. 1 1
      rest/httpx/requests.go
  51. 1 1
      rest/httpx/requests_test.go
  52. 0 0
      rest/httpx/responses.go
  53. 0 0
      rest/httpx/responses_test.go
  54. 0 0
      rest/internal/context/params.go
  55. 0 0
      rest/internal/log.go
  56. 0 0
      rest/internal/log_test.go
  57. 1 1
      rest/internal/router/patrouter.go
  58. 1 1
      rest/internal/router/patrouter_test.go
  59. 0 0
      rest/internal/router/router.go
  60. 1 1
      rest/internal/security/contentsecurity.go
  61. 0 0
      rest/internal/security/withcoderesponsewriter.go
  62. 0 0
      rest/internal/server.go
  63. 0 0
      rest/internal/starter.go
  64. 0 0
      rest/internal/tokenparser.go
  65. 0 0
      rest/internal/tokenparser_test.go
  66. 0 0
      rest/internal/util.go
  67. 0 0
      rest/internal/util_test.go
  68. 5 5
      rest/ngin.go
  69. 3 3
      rest/ngin_test.go
  70. 6 6
      rest/server.go
  71. 1 1
      rest/types.go
  72. 2 2
      tools/goctl/api/demo/config/config.go
  73. 2 2
      tools/goctl/api/demo/demo.go
  74. 1 1
      tools/goctl/api/demo/handler/getuserhandler.go
  75. 3 3
      tools/goctl/api/demo/handler/handlers.go
  76. 2 2
      tools/goctl/api/gogen/genconfig.go
  77. 2 2
      tools/goctl/api/gogen/genmain.go
  78. 5 5
      tools/goctl/api/gogen/genroutes.go

+ 1 - 1
.golangci.yml

@@ -9,7 +9,7 @@ run:
     - example
     - kmq
     - kq
-    - ngin
+    - rest
     - rq
     - rpcx
     #    - service

+ 1 - 0
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())

+ 2 - 2
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
 }

+ 2 - 2
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)

+ 1 - 1
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 {

+ 3 - 3
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",

+ 2 - 2
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
 }

+ 2 - 2
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)

+ 1 - 1
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 {

+ 3 - 3
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",

+ 4 - 4
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) {

+ 4 - 4
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,

+ 5 - 5
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,

+ 4 - 4
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,

+ 6 - 6
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,

+ 9 - 9
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()

+ 3 - 3
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) {

+ 4 - 4
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,

+ 8 - 2
ngin/config.go → 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

+ 0 - 0
ngin/etc/config.json → rest/etc/config.json


+ 1 - 1
ngin/handler/authhandler.go → 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"
 )

+ 0 - 0
ngin/handler/authhandler_test.go → rest/handler/authhandler_test.go


+ 2 - 2
ngin/handler/breakerhandler.go → 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 = "://"

+ 0 - 0
ngin/handler/breakerhandler_test.go → rest/handler/breakerhandler_test.go


+ 2 - 2
ngin/handler/contentsecurityhandler.go → 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"

+ 1 - 1
ngin/handler/contentsecurityhandler_test.go → 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"
 )

+ 0 - 0
ngin/handler/cryptionhandler.go → rest/handler/cryptionhandler.go


+ 0 - 0
ngin/handler/cryptionhandler_test.go → rest/handler/cryptionhandler_test.go


+ 1 - 1
ngin/handler/gunziphandler.go → rest/handler/gunziphandler.go

@@ -5,7 +5,7 @@ import (
 	"net/http"
 	"strings"
 
-	"zero/ngin/httpx"
+	"zero/rest/httpx"
 )
 
 const gzipEncoding = "gzip"

+ 1 - 1
ngin/handler/gunziphandler_test.go → 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"
 )

+ 1 - 1
ngin/handler/loghandler.go → 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

+ 1 - 1
ngin/handler/loghandler_test.go → rest/handler/loghandler_test.go

@@ -8,7 +8,7 @@ import (
 	"testing"
 	"time"
 
-	"zero/ngin/internal"
+	"zero/rest/internal"
 
 	"github.com/stretchr/testify/assert"
 )

+ 1 - 1
ngin/handler/maxbyteshandler.go → 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 {

+ 0 - 0
ngin/handler/maxbyteshandler_test.go → rest/handler/maxbyteshandler_test.go


+ 1 - 1
ngin/handler/maxconnshandler.go → 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 {

+ 0 - 0
ngin/handler/maxconnshandler_test.go → rest/handler/maxconnshandler_test.go


+ 0 - 0
ngin/handler/metrichandler.go → rest/handler/metrichandler.go


+ 0 - 0
ngin/handler/metrichandler_test.go → rest/handler/metrichandler_test.go


+ 1 - 1
ngin/handler/prommetrichandler.go → 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"

+ 0 - 0
ngin/handler/prommetrichandler_test.go → rest/handler/prommetrichandler_test.go


+ 1 - 1
ngin/handler/recoverhandler.go → 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 {

+ 0 - 0
ngin/handler/recoverhandler_test.go → rest/handler/recoverhandler_test.go


+ 2 - 2
ngin/handler/sheddinghandler.go → 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"

+ 0 - 0
ngin/handler/sheddinghandler_test.go → rest/handler/sheddinghandler_test.go


+ 0 - 0
ngin/handler/timeouthandler.go → rest/handler/timeouthandler.go


+ 0 - 0
ngin/handler/timeouthandler_test.go → rest/handler/timeouthandler_test.go


+ 0 - 0
ngin/handler/tracinghandler.go → rest/handler/tracinghandler.go


+ 0 - 0
ngin/handler/tracinghandler_test.go → rest/handler/tracinghandler_test.go


+ 0 - 0
ngin/httpx/constants.go → rest/httpx/constants.go


+ 1 - 1
ngin/httpx/requests.go → rest/httpx/requests.go

@@ -6,7 +6,7 @@ import (
 	"strings"
 
 	"zero/core/mapping"
-	"zero/ngin/internal/context"
+	"zero/rest/internal/context"
 )
 
 const (

+ 1 - 1
ngin/httpx/requests_test.go → 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"
 )

+ 0 - 0
ngin/httpx/responses.go → rest/httpx/responses.go


+ 0 - 0
ngin/httpx/responses_test.go → rest/httpx/responses_test.go


+ 0 - 0
ngin/internal/context/params.go → rest/internal/context/params.go


+ 0 - 0
ngin/internal/log.go → rest/internal/log.go


+ 0 - 0
ngin/internal/log_test.go → rest/internal/log_test.go


+ 1 - 1
ngin/internal/router/patrouter.go → rest/internal/router/patrouter.go

@@ -6,7 +6,7 @@ import (
 	"strings"
 
 	"zero/core/search"
-	"zero/ngin/internal/context"
+	"zero/rest/internal/context"
 )
 
 const (

+ 1 - 1
ngin/internal/router/patrouter_test.go → 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 {

+ 0 - 0
ngin/internal/router/router.go → rest/internal/router/router.go


+ 1 - 1
ngin/internal/security/contentsecurity.go → 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 (

+ 0 - 0
ngin/internal/security/withcoderesponsewriter.go → rest/internal/security/withcoderesponsewriter.go


+ 0 - 0
ngin/internal/server.go → rest/internal/server.go


+ 0 - 0
ngin/internal/starter.go → rest/internal/starter.go


+ 0 - 0
ngin/internal/tokenparser.go → rest/internal/tokenparser.go


+ 0 - 0
ngin/internal/tokenparser_test.go → rest/internal/tokenparser_test.go


+ 0 - 0
ngin/internal/util.go → rest/internal/util.go


+ 0 - 0
ngin/internal/util_test.go → rest/internal/util_test.go


+ 5 - 5
ngin/ngin.go → 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
 	}

+ 3 - 3
ngin/ngin_test.go → 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"
 )

+ 6 - 6
ngin/server.go → 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,
 	}

+ 1 - 1
ngin/types.go → rest/types.go

@@ -1,4 +1,4 @@
-package ngin
+package rest
 
 import "net/http"
 

+ 2 - 2
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
 }

+ 2 - 2
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)

+ 1 - 1
tools/goctl/api/demo/handler/getuserhandler.go

@@ -3,7 +3,7 @@ package handler
 import (
 	"net/http"
 
-	"zero/ngin/httpx"
+	"zero/rest/httpx"
 )
 
 type (

+ 3 - 3
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:    "/",

+ 2 - 2
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
 }
 `
 )

+ 2 - 2
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)))

+ 5 - 5
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 {