rename ngin to rest

This commit is contained in:
kevin
2020-07-31 11:14:48 +08:00
parent e133ffd820
commit 0897f60c5d
78 changed files with 118 additions and 111 deletions

View File

@@ -1,7 +1,7 @@
package config
import "zero/ngin"
import "zero/rest"
type Config struct {
ngin.NgConf
rest.RtConf
}

View File

@@ -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)

View File

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

View File

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

View File

@@ -13,12 +13,12 @@ const (
configTemplate = `package config
import (
"zero/ngin"
"zero/rest"
{{.authImport}}
)
type Config struct {
ngin.NgConf
rest.RtConf
}
`
)

View File

@@ -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)))

View File

@@ -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 {