rename ngin to rest
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"zero/ngin"
|
||||
"zero/rest"
|
||||
"zero/rpcx"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ngin.NgConf
|
||||
rest.RtConf
|
||||
Rpc rpcx.RpcClientConf
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"zero/ngin"
|
||||
"zero/rest"
|
||||
"zero/rpcx"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ngin.NgConf
|
||||
rest.RtConf
|
||||
Rpc rpcx.RpcClientConf
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,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()
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user