mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-02 16:28:39 +08:00
rename ngin to rest
This commit is contained in:
parent
e133ffd820
commit
0897f60c5d
@ -9,7 +9,7 @@ run:
|
||||
- example
|
||||
- kmq
|
||||
- kq
|
||||
- ngin
|
||||
- rest
|
||||
- rq
|
||||
- rpcx
|
||||
# - service
|
||||
|
@ -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())
|
||||
|
@ -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,
|
||||
|
@ -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
|
@ -7,7 +7,7 @@ import (
|
||||
"net/http/httputil"
|
||||
|
||||
"zero/core/logx"
|
||||
"zero/ngin/internal"
|
||||
"zero/rest/internal"
|
||||
|
||||
"github.com/dgrijalva/jwt-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 = "://"
|
@ -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"
|
@ -18,7 +18,7 @@ import (
|
||||
"time"
|
||||
|
||||
"zero/core/codec"
|
||||
"zero/ngin/httpx"
|
||||
"zero/rest/httpx"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"zero/ngin/httpx"
|
||||
"zero/rest/httpx"
|
||||
)
|
||||
|
||||
const gzipEncoding = "gzip"
|
@ -10,7 +10,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"zero/core/codec"
|
||||
"zero/ngin/httpx"
|
||||
"zero/rest/httpx"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
@ -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
|
@ -8,7 +8,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"zero/ngin/internal"
|
||||
"zero/rest/internal"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
@ -3,7 +3,7 @@ package handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"zero/ngin/internal"
|
||||
"zero/rest/internal"
|
||||
)
|
||||
|
||||
func MaxBytesHandler(n int64) func(http.Handler) http.Handler {
|
@ -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 {
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"zero/core/metric"
|
||||
"zero/core/timex"
|
||||
"zero/ngin/internal/security"
|
||||
"zero/rest/internal/security"
|
||||
)
|
||||
|
||||
const serverNamespace = "http_server"
|
@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
|
||||
"zero/ngin/internal"
|
||||
"zero/rest/internal"
|
||||
)
|
||||
|
||||
func RecoverHandler(next http.Handler) http.Handler {
|
@ -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"
|
@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"zero/core/mapping"
|
||||
"zero/ngin/internal/context"
|
||||
"zero/rest/internal/context"
|
||||
)
|
||||
|
||||
const (
|
@ -10,7 +10,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"zero/ngin/internal/router"
|
||||
"zero/rest/internal/router"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"zero/core/search"
|
||||
"zero/ngin/internal/context"
|
||||
"zero/rest/internal/context"
|
||||
)
|
||||
|
||||
const (
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"zero/ngin/internal/context"
|
||||
"zero/rest/internal/context"
|
||||
)
|
||||
|
||||
type mockedResponseWriter struct {
|
@ -15,7 +15,7 @@ import (
|
||||
"zero/core/codec"
|
||||
"zero/core/iox"
|
||||
"zero/core/logx"
|
||||
"zero/ngin/httpx"
|
||||
"zero/rest/httpx"
|
||||
)
|
||||
|
||||
const (
|
@ -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
|
||||
}
|
@ -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"
|
||||
)
|
@ -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,4 +1,4 @@
|
||||
package ngin
|
||||
package rest
|
||||
|
||||
import "net/http"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package config
|
||||
|
||||
import "zero/ngin"
|
||||
import "zero/rest"
|
||||
|
||||
type Config struct {
|
||||
ngin.NgConf
|
||||
rest.RtConf
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -3,7 +3,7 @@ package handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"zero/ngin/httpx"
|
||||
"zero/rest/httpx"
|
||||
)
|
||||
|
||||
type (
|
||||
|
@ -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: "/",
|
||||
|
@ -13,12 +13,12 @@ const (
|
||||
configTemplate = `package config
|
||||
|
||||
import (
|
||||
"zero/ngin"
|
||||
"zero/rest"
|
||||
{{.authImport}}
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ngin.NgConf
|
||||
rest.RtConf
|
||||
}
|
||||
`
|
||||
)
|
||||
|
@ -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)))
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user