rename ngin to rest
This commit is contained in:
@@ -9,7 +9,7 @@ run:
|
|||||||
- example
|
- example
|
||||||
- kmq
|
- kmq
|
||||||
- kq
|
- kq
|
||||||
- ngin
|
- rest
|
||||||
- rq
|
- rq
|
||||||
- rpcx
|
- rpcx
|
||||||
# - service
|
# - service
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ func TestContainer(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.True(t, c.dirty.True())
|
assert.True(t, c.dirty.True())
|
||||||
assert.ElementsMatch(t, test.expect, c.getValues())
|
assert.ElementsMatch(t, test.expect, c.getValues())
|
||||||
assert.False(t, c.dirty.True())
|
assert.False(t, c.dirty.True())
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
"zero/rpcx"
|
"zero/rpcx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ngin.NgConf
|
rest.RtConf
|
||||||
Rpc rpcx.RpcClientConf
|
Rpc rpcx.RpcClientConf
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"zero/example/graceful/dns/api/config"
|
"zero/example/graceful/dns/api/config"
|
||||||
"zero/example/graceful/dns/api/handler"
|
"zero/example/graceful/dns/api/handler"
|
||||||
"zero/example/graceful/dns/api/svc"
|
"zero/example/graceful/dns/api/svc"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
"zero/rpcx"
|
"zero/rpcx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ func main() {
|
|||||||
Client: client,
|
Client: client,
|
||||||
}
|
}
|
||||||
|
|
||||||
engine := ngin.MustNewEngine(c.NgConf)
|
engine := rest.MustNewEngine(c.RtConf)
|
||||||
defer engine.Stop()
|
defer engine.Stop()
|
||||||
|
|
||||||
handler.RegisterHandlers(engine, ctx)
|
handler.RegisterHandlers(engine, ctx)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
"zero/example/graceful/dns/api/svc"
|
"zero/example/graceful/dns/api/svc"
|
||||||
"zero/example/graceful/dns/api/types"
|
"zero/example/graceful/dns/api/types"
|
||||||
"zero/example/graceful/dns/rpc/graceful"
|
"zero/example/graceful/dns/rpc/graceful"
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
func gracefulHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
func gracefulHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"zero/example/graceful/dns/api/svc"
|
"zero/example/graceful/dns/api/svc"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterHandlers(engine *ngin.Engine, ctx *svc.ServiceContext) {
|
func RegisterHandlers(engine *rest.Engine, ctx *svc.ServiceContext) {
|
||||||
engine.AddRoutes([]ngin.Route{
|
engine.AddRoutes([]rest.Route{
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/api/graceful",
|
Path: "/api/graceful",
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
"zero/rpcx"
|
"zero/rpcx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ngin.NgConf
|
rest.RtConf
|
||||||
Rpc rpcx.RpcClientConf
|
Rpc rpcx.RpcClientConf
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"zero/example/graceful/etcd/api/config"
|
"zero/example/graceful/etcd/api/config"
|
||||||
"zero/example/graceful/etcd/api/handler"
|
"zero/example/graceful/etcd/api/handler"
|
||||||
"zero/example/graceful/etcd/api/svc"
|
"zero/example/graceful/etcd/api/svc"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
"zero/rpcx"
|
"zero/rpcx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ func main() {
|
|||||||
Client: client,
|
Client: client,
|
||||||
}
|
}
|
||||||
|
|
||||||
engine := ngin.MustNewEngine(c.NgConf)
|
engine := rest.MustNewEngine(c.RtConf)
|
||||||
defer engine.Stop()
|
defer engine.Stop()
|
||||||
|
|
||||||
handler.RegisterHandlers(engine, ctx)
|
handler.RegisterHandlers(engine, ctx)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
"zero/example/graceful/etcd/api/svc"
|
"zero/example/graceful/etcd/api/svc"
|
||||||
"zero/example/graceful/etcd/api/types"
|
"zero/example/graceful/etcd/api/types"
|
||||||
"zero/example/graceful/etcd/rpc/graceful"
|
"zero/example/graceful/etcd/rpc/graceful"
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
func gracefulHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
func gracefulHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"zero/example/graceful/etcd/api/svc"
|
"zero/example/graceful/etcd/api/svc"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterHandlers(engine *ngin.Engine, ctx *svc.ServiceContext) {
|
func RegisterHandlers(engine *rest.Engine, ctx *svc.ServiceContext) {
|
||||||
engine.AddRoutes([]ngin.Route{
|
engine.AddRoutes([]rest.Route{
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/api/graceful",
|
Path: "/api/graceful",
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ import (
|
|||||||
"zero/core/service"
|
"zero/core/service"
|
||||||
"zero/core/stat"
|
"zero/core/stat"
|
||||||
"zero/core/syncx"
|
"zero/core/syncx"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logx.Disable()
|
logx.Disable()
|
||||||
stat.SetReporter(nil)
|
stat.SetReporter(nil)
|
||||||
server := ngin.MustNewEngine(ngin.NgConf{
|
server := rest.MustNewEngine(rest.RtConf{
|
||||||
ServiceConf: service.ServiceConf{
|
ServiceConf: service.ServiceConf{
|
||||||
Name: "breaker",
|
Name: "breaker",
|
||||||
Log: logx.LogConf{
|
Log: logx.LogConf{
|
||||||
@@ -28,7 +28,7 @@ func main() {
|
|||||||
Timeout: 3000,
|
Timeout: 3000,
|
||||||
})
|
})
|
||||||
latch := syncx.NewLimit(10)
|
latch := syncx.NewLimit(10)
|
||||||
server.AddRoute(ngin.Route{
|
server.AddRoute(rest.Route{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/heavy",
|
Path: "/heavy",
|
||||||
Handler: func(w http.ResponseWriter, r *http.Request) {
|
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,
|
Method: http.MethodGet,
|
||||||
Path: "/good",
|
Path: "/good",
|
||||||
Handler: func(w http.ResponseWriter, r *http.Request) {
|
Handler: func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
|
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/core/service"
|
"zero/core/service"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -47,7 +47,7 @@ func handle(w http.ResponseWriter, r *http.Request) {
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
engine := ngin.MustNewEngine(ngin.NgConf{
|
engine := rest.MustNewEngine(rest.RtConf{
|
||||||
ServiceConf: service.ServiceConf{
|
ServiceConf: service.ServiceConf{
|
||||||
Log: logx.LogConf{
|
Log: logx.LogConf{
|
||||||
Mode: "console",
|
Mode: "console",
|
||||||
@@ -61,7 +61,7 @@ func main() {
|
|||||||
|
|
||||||
engine.Use(first)
|
engine.Use(first)
|
||||||
engine.Use(second)
|
engine.Use(second)
|
||||||
engine.AddRoute(ngin.Route{
|
engine.AddRoute(rest.Route{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
Handler: handle,
|
Handler: handle,
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import (
|
|||||||
|
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/core/service"
|
"zero/core/service"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -37,7 +37,7 @@ func handlePost(w http.ResponseWriter, r *http.Request) {
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
engine := ngin.MustNewEngine(ngin.NgConf{
|
engine := rest.MustNewEngine(rest.RtConf{
|
||||||
ServiceConf: service.ServiceConf{
|
ServiceConf: service.ServiceConf{
|
||||||
Log: logx.LogConf{
|
Log: logx.LogConf{
|
||||||
Mode: "console",
|
Mode: "console",
|
||||||
@@ -51,12 +51,12 @@ func main() {
|
|||||||
})
|
})
|
||||||
defer engine.Stop()
|
defer engine.Stop()
|
||||||
|
|
||||||
engine.AddRoute(ngin.Route{
|
engine.AddRoute(rest.Route{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
Handler: handleGet,
|
Handler: handleGet,
|
||||||
})
|
})
|
||||||
engine.AddRoute(ngin.Route{
|
engine.AddRoute(rest.Route{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
Handler: handlePost,
|
Handler: handlePost,
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import (
|
|||||||
|
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/core/service"
|
"zero/core/service"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -42,7 +42,7 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
logx.Disable()
|
logx.Disable()
|
||||||
engine := ngin.MustNewEngine(ngin.NgConf{
|
engine := rest.MustNewEngine(rest.RtConf{
|
||||||
ServiceConf: service.ServiceConf{
|
ServiceConf: service.ServiceConf{
|
||||||
Log: logx.LogConf{
|
Log: logx.LogConf{
|
||||||
Mode: "console",
|
Mode: "console",
|
||||||
@@ -54,7 +54,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
defer engine.Stop()
|
defer engine.Stop()
|
||||||
|
|
||||||
engine.AddRoute(ngin.Route{
|
engine.AddRoute(rest.Route{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
Handler: handle,
|
Handler: handle,
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import (
|
|||||||
|
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/core/service"
|
"zero/core/service"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
var keyPem = flag.String("prikey", "private.pem", "the private key file")
|
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() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
engine := ngin.MustNewEngine(ngin.NgConf{
|
engine := rest.MustNewEngine(rest.RtConf{
|
||||||
ServiceConf: service.ServiceConf{
|
ServiceConf: service.ServiceConf{
|
||||||
Log: logx.LogConf{
|
Log: logx.LogConf{
|
||||||
Path: "logs",
|
Path: "logs",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Port: 3333,
|
Port: 3333,
|
||||||
Signature: ngin.SignatureConf{
|
Signature: rest.SignatureConf{
|
||||||
Strict: true,
|
Strict: true,
|
||||||
PrivateKeys: []ngin.PrivateKeyConf{
|
PrivateKeys: []rest.PrivateKeyConf{
|
||||||
{
|
{
|
||||||
Fingerprint: "bvw8YlnSqb+PoMf3MBbLdQ==",
|
Fingerprint: "bvw8YlnSqb+PoMf3MBbLdQ==",
|
||||||
KeyFile: *keyPem,
|
KeyFile: *keyPem,
|
||||||
@@ -50,7 +50,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
defer engine.Stop()
|
defer engine.Stop()
|
||||||
|
|
||||||
engine.AddRoute(ngin.Route{
|
engine.AddRoute(rest.Route{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/a/b",
|
Path: "/a/b",
|
||||||
Handler: handle,
|
Handler: handle,
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"zero/core/conf"
|
"zero/core/conf"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
|
|
||||||
"github.com/dgrijalva/jwt-go"
|
"github.com/dgrijalva/jwt-go"
|
||||||
"github.com/dgrijalva/jwt-go/request"
|
"github.com/dgrijalva/jwt-go/request"
|
||||||
@@ -20,7 +20,7 @@ const jwtUserField = "user"
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Config struct {
|
Config struct {
|
||||||
ngin.NgConf
|
rest.RtConf
|
||||||
AccessSecret string
|
AccessSecret string
|
||||||
AccessExpire int64 `json:",default=1209600"` // 2 weeks
|
AccessExpire int64 `json:",default=1209600"` // 2 weeks
|
||||||
RefreshSecret string
|
RefreshSecret string
|
||||||
@@ -79,27 +79,27 @@ func main() {
|
|||||||
var c Config
|
var c Config
|
||||||
conf.MustLoad("user.json", &c)
|
conf.MustLoad("user.json", &c)
|
||||||
|
|
||||||
engine, err := ngin.NewEngine(c.NgConf)
|
engine, err := rest.NewEngine(c.RtConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer engine.Stop()
|
defer engine.Stop()
|
||||||
|
|
||||||
engine.AddRoute(ngin.Route{
|
engine.AddRoute(rest.Route{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/login",
|
Path: "/login",
|
||||||
Handler: LoginHandler(c),
|
Handler: LoginHandler(c),
|
||||||
})
|
})
|
||||||
engine.AddRoute(ngin.Route{
|
engine.AddRoute(rest.Route{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/resource",
|
Path: "/resource",
|
||||||
Handler: ProtectedHandler,
|
Handler: ProtectedHandler,
|
||||||
}, ngin.WithJwt(c.AccessSecret))
|
}, rest.WithJwt(c.AccessSecret))
|
||||||
engine.AddRoute(ngin.Route{
|
engine.AddRoute(rest.Route{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/refresh",
|
Path: "/refresh",
|
||||||
Handler: RefreshHandler(c),
|
Handler: RefreshHandler(c),
|
||||||
}, ngin.WithJwt(c.RefreshSecret))
|
}, rest.WithJwt(c.RefreshSecret))
|
||||||
|
|
||||||
fmt.Println("Now listening...")
|
fmt.Println("Now listening...")
|
||||||
engine.Start()
|
engine.Start()
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/core/service"
|
"zero/core/service"
|
||||||
"zero/core/stat"
|
"zero/core/stat"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
const duration = time.Millisecond
|
const duration = time.Millisecond
|
||||||
@@ -25,7 +25,7 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
logx.Disable()
|
logx.Disable()
|
||||||
engine := ngin.MustNewEngine(ngin.NgConf{
|
engine := rest.MustNewEngine(rest.RtConf{
|
||||||
ServiceConf: service.ServiceConf{
|
ServiceConf: service.ServiceConf{
|
||||||
Log: logx.LogConf{
|
Log: logx.LogConf{
|
||||||
Mode: "console",
|
Mode: "console",
|
||||||
@@ -36,7 +36,7 @@ func main() {
|
|||||||
CpuThreshold: 800,
|
CpuThreshold: 800,
|
||||||
})
|
})
|
||||||
defer engine.Stop()
|
defer engine.Stop()
|
||||||
engine.AddRoute(ngin.Route{
|
engine.AddRoute(rest.Route{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
Handler: func(w http.ResponseWriter, r *http.Request) {
|
Handler: func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/core/service"
|
"zero/core/service"
|
||||||
"zero/example/tracing/remote/portal"
|
"zero/example/tracing/remote/portal"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
"zero/rpcx"
|
"zero/rpcx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ func main() {
|
|||||||
var c rpcx.RpcClientConf
|
var c rpcx.RpcClientConf
|
||||||
conf.MustLoad(*configFile, &c)
|
conf.MustLoad(*configFile, &c)
|
||||||
client = rpcx.MustNewClient(c)
|
client = rpcx.MustNewClient(c)
|
||||||
engine := ngin.MustNewEngine(ngin.NgConf{
|
engine := rest.MustNewEngine(rest.RtConf{
|
||||||
ServiceConf: service.ServiceConf{
|
ServiceConf: service.ServiceConf{
|
||||||
Log: logx.LogConf{
|
Log: logx.LogConf{
|
||||||
Mode: "console",
|
Mode: "console",
|
||||||
@@ -52,7 +52,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
defer engine.Stop()
|
defer engine.Stop()
|
||||||
|
|
||||||
engine.AddRoute(ngin.Route{
|
engine.AddRoute(rest.Route{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
Handler: handle,
|
Handler: handle,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package ngin
|
package rest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
@@ -18,7 +18,13 @@ type (
|
|||||||
PrivateKeys []PrivateKeyConf
|
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
|
service.ServiceConf
|
||||||
Host string `json:",default=0.0.0.0"`
|
Host string `json:",default=0.0.0.0"`
|
||||||
Port int
|
Port int
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
|
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/ngin/internal"
|
"zero/rest/internal"
|
||||||
|
|
||||||
"github.com/dgrijalva/jwt-go"
|
"github.com/dgrijalva/jwt-go"
|
||||||
)
|
)
|
||||||
@@ -8,8 +8,8 @@ import (
|
|||||||
"zero/core/breaker"
|
"zero/core/breaker"
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/core/stat"
|
"zero/core/stat"
|
||||||
"zero/ngin/internal"
|
"zero/rest/internal"
|
||||||
"zero/ngin/internal/security"
|
"zero/rest/internal/security"
|
||||||
)
|
)
|
||||||
|
|
||||||
const breakerSeparator = "://"
|
const breakerSeparator = "://"
|
||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
|
|
||||||
"zero/core/codec"
|
"zero/core/codec"
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
"zero/ngin/internal/security"
|
"zero/rest/internal/security"
|
||||||
)
|
)
|
||||||
|
|
||||||
const contentSecurity = "X-Content-Security"
|
const contentSecurity = "X-Content-Security"
|
||||||
@@ -18,7 +18,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"zero/core/codec"
|
"zero/core/codec"
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
const gzipEncoding = "gzip"
|
const gzipEncoding = "gzip"
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"zero/core/codec"
|
"zero/core/codec"
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/core/timex"
|
"zero/core/timex"
|
||||||
"zero/core/utils"
|
"zero/core/utils"
|
||||||
"zero/ngin/internal"
|
"zero/rest/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
const slowThreshold = time.Millisecond * 500
|
const slowThreshold = time.Millisecond * 500
|
||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"zero/ngin/internal"
|
"zero/rest/internal"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@@ -3,7 +3,7 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"zero/ngin/internal"
|
"zero/rest/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MaxBytesHandler(n int64) func(http.Handler) http.Handler {
|
func MaxBytesHandler(n int64) func(http.Handler) http.Handler {
|
||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
|
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/core/syncx"
|
"zero/core/syncx"
|
||||||
"zero/ngin/internal"
|
"zero/rest/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MaxConns(n int) func(http.Handler) http.Handler {
|
func MaxConns(n int) func(http.Handler) http.Handler {
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
"zero/core/metric"
|
"zero/core/metric"
|
||||||
"zero/core/timex"
|
"zero/core/timex"
|
||||||
"zero/ngin/internal/security"
|
"zero/rest/internal/security"
|
||||||
)
|
)
|
||||||
|
|
||||||
const serverNamespace = "http_server"
|
const serverNamespace = "http_server"
|
||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
|
||||||
"zero/ngin/internal"
|
"zero/rest/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RecoverHandler(next http.Handler) http.Handler {
|
func RecoverHandler(next http.Handler) http.Handler {
|
||||||
@@ -7,8 +7,8 @@ import (
|
|||||||
"zero/core/load"
|
"zero/core/load"
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/core/stat"
|
"zero/core/stat"
|
||||||
"zero/ngin/internal"
|
"zero/rest/internal"
|
||||||
"zero/ngin/internal/security"
|
"zero/rest/internal/security"
|
||||||
)
|
)
|
||||||
|
|
||||||
const serviceType = "api"
|
const serviceType = "api"
|
||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"zero/core/mapping"
|
"zero/core/mapping"
|
||||||
"zero/ngin/internal/context"
|
"zero/rest/internal/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"zero/ngin/internal/router"
|
"zero/rest/internal/router"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"zero/core/search"
|
"zero/core/search"
|
||||||
"zero/ngin/internal/context"
|
"zero/rest/internal/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"zero/ngin/internal/context"
|
"zero/rest/internal/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mockedResponseWriter struct {
|
type mockedResponseWriter struct {
|
||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
"zero/core/codec"
|
"zero/core/codec"
|
||||||
"zero/core/iox"
|
"zero/core/iox"
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package ngin
|
package rest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/ngin/handler"
|
"zero/rest/handler"
|
||||||
"zero/ngin/internal/router"
|
"zero/rest/internal/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
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...)
|
engine, err := NewEngine(c, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -31,7 +31,7 @@ func MustNewEngine(c NgConf, opts ...RunOption) *Engine {
|
|||||||
return 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 {
|
if err := c.SetUp(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ngin
|
package rest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -7,8 +7,8 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
router2 "zero/ngin/internal/router"
|
router2 "zero/rest/internal/router"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ngin
|
package rest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@@ -9,9 +9,9 @@ import (
|
|||||||
"zero/core/codec"
|
"zero/core/codec"
|
||||||
"zero/core/load"
|
"zero/core/load"
|
||||||
"zero/core/stat"
|
"zero/core/stat"
|
||||||
"zero/ngin/handler"
|
"zero/rest/handler"
|
||||||
"zero/ngin/internal"
|
"zero/rest/internal"
|
||||||
"zero/ngin/internal/router"
|
"zero/rest/internal/router"
|
||||||
|
|
||||||
"github.com/justinas/alice"
|
"github.com/justinas/alice"
|
||||||
)
|
)
|
||||||
@@ -25,7 +25,7 @@ type (
|
|||||||
Middleware func(next http.HandlerFunc) http.HandlerFunc
|
Middleware func(next http.HandlerFunc) http.HandlerFunc
|
||||||
|
|
||||||
server struct {
|
server struct {
|
||||||
conf NgConf
|
conf RtConf
|
||||||
routes []featuredRoutes
|
routes []featuredRoutes
|
||||||
unauthorizedCallback handler.UnauthorizedCallback
|
unauthorizedCallback handler.UnauthorizedCallback
|
||||||
unsignedCallback handler.UnsignedCallback
|
unsignedCallback handler.UnsignedCallback
|
||||||
@@ -35,7 +35,7 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func newServer(c NgConf) *server {
|
func newServer(c RtConf) *server {
|
||||||
srv := &server{
|
srv := &server{
|
||||||
conf: c,
|
conf: c,
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ngin
|
package rest
|
||||||
|
|
||||||
import "net/http"
|
import "net/http"
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import "zero/ngin"
|
import "zero/rest"
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ngin.NgConf
|
rest.RtConf
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
|
|
||||||
"zero/core/conf"
|
"zero/core/conf"
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
"zero/tools/goctl/api/demo/config"
|
"zero/tools/goctl/api/demo/config"
|
||||||
"zero/tools/goctl/api/demo/handler"
|
"zero/tools/goctl/api/demo/handler"
|
||||||
)
|
)
|
||||||
@@ -17,7 +17,7 @@ func main() {
|
|||||||
var c config.Config
|
var c config.Config
|
||||||
conf.MustLoad(*configFile, &c)
|
conf.MustLoad(*configFile, &c)
|
||||||
|
|
||||||
engine := ngin.MustNewEngine(c.NgConf)
|
engine := rest.MustNewEngine(c.RtConf)
|
||||||
defer engine.Stop()
|
defer engine.Stop()
|
||||||
|
|
||||||
handler.RegisterHandlers(engine)
|
handler.RegisterHandlers(engine)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"zero/ngin/httpx"
|
"zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterHandlers(engine *ngin.Engine) {
|
func RegisterHandlers(engine *rest.Engine) {
|
||||||
engine.AddRoutes([]ngin.Route{
|
engine.AddRoutes([]rest.Route{
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ const (
|
|||||||
configTemplate = `package config
|
configTemplate = `package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"zero/ngin"
|
"zero/rest"
|
||||||
{{.authImport}}
|
{{.authImport}}
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ngin.NgConf
|
rest.RtConf
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func main() {
|
|||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
|
||||||
engine := ngin.MustNewEngine(c.NgConf)
|
engine := rest.MustNewEngine(c.RtConf)
|
||||||
defer engine.Stop()
|
defer engine.Stop()
|
||||||
|
|
||||||
handler.RegisterHandlers(engine, ctx)
|
handler.RegisterHandlers(engine, ctx)
|
||||||
@@ -75,7 +75,7 @@ func genMain(dir string, api *spec.ApiSpec) error {
|
|||||||
func genMainImports(parentPkg string) string {
|
func genMainImports(parentPkg string) string {
|
||||||
imports := []string{
|
imports := []string{
|
||||||
`"zero/core/conf"`,
|
`"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, configDir)))
|
||||||
imports = append(imports, fmt.Sprintf("\"%s\"", path.Join(parentPkg, handlerDir)))
|
imports = append(imports, fmt.Sprintf("\"%s\"", path.Join(parentPkg, handlerDir)))
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ import (
|
|||||||
{{.importPackages}}
|
{{.importPackages}}
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterHandlers(engine *ngin.Engine, serverCtx *svc.ServiceContext) {
|
func RegisterHandlers(engine *rest.Engine, serverCtx *svc.ServiceContext) {
|
||||||
{{.routesAdditions}}
|
{{.routesAdditions}}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
routesAdditionTemplate = `
|
routesAdditionTemplate = `
|
||||||
engine.AddRoutes([]ngin.Route{
|
engine.AddRoutes([]rest.Route{
|
||||||
{{.routes}}
|
{{.routes}}
|
||||||
}{{.jwt}}{{.signature}})
|
}{{.jwt}}{{.signature}})
|
||||||
`
|
`
|
||||||
@@ -80,11 +80,11 @@ func genRoutes(dir string, api *spec.ApiSpec) error {
|
|||||||
}
|
}
|
||||||
jwt := ""
|
jwt := ""
|
||||||
if g.jwtEnabled {
|
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 := ""
|
signature := ""
|
||||||
if g.signatureEnabled {
|
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{
|
if err := gt.Execute(&builder, map[string]string{
|
||||||
"routes": strings.TrimSpace(gbuilder.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 {
|
func genRouteImports(parentPkg string, api *spec.ApiSpec) string {
|
||||||
var importSet = collection.NewSet()
|
var importSet = collection.NewSet()
|
||||||
importSet.AddStr(`"zero/ngin"`)
|
importSet.AddStr(`"zero/rest"`)
|
||||||
importSet.AddStr(fmt.Sprintf("\"%s\"", path.Join(parentPkg, contextDir)))
|
importSet.AddStr(fmt.Sprintf("\"%s\"", path.Join(parentPkg, contextDir)))
|
||||||
for _, group := range api.Service.Groups {
|
for _, group := range api.Service.Groups {
|
||||||
for _, route := range group.Routes {
|
for _, route := range group.Routes {
|
||||||
|
|||||||
Reference in New Issue
Block a user