rename ngin to rest
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user