|
|
@@ -5,6 +5,11 @@ import (
|
|
|
"git.sxidc.com/go-framework/baize"
|
|
|
"git.sxidc.com/go-framework/baize/api"
|
|
|
"git.sxidc.com/go-framework/baize/application"
|
|
|
+ "git.sxidc.com/go-framework/baize/binding"
|
|
|
+ "git.sxidc.com/go-framework/baize/binding/request"
|
|
|
+ "git.sxidc.com/go-framework/baize/binding/response"
|
|
|
+ "git.sxidc.com/go-framework/baize/domain"
|
|
|
+ "git.sxidc.com/go-framework/baize/infrastructure"
|
|
|
DEATH "github.com/vrecan/death"
|
|
|
"net/http"
|
|
|
"syscall"
|
|
|
@@ -28,19 +33,27 @@ func main() {
|
|
|
fmt.Println("Global Before2")
|
|
|
c.Next()
|
|
|
fmt.Println("Global After2")
|
|
|
- }).
|
|
|
- AddRoute(http.MethodGet, "/ping", func(c *api.Context) {
|
|
|
- c.String(http.StatusOK, "pong")
|
|
|
- }, func(c *api.Context) {
|
|
|
- fmt.Println("Root Route Before1")
|
|
|
- c.Next()
|
|
|
- fmt.Println("Root Route After1")
|
|
|
- }, func(c *api.Context) {
|
|
|
- fmt.Println("Root Route Before2")
|
|
|
- c.Next()
|
|
|
- fmt.Println("Root Route After2")
|
|
|
})
|
|
|
|
|
|
+ rootBinder := app.Binder(application.RouterRoot, "")
|
|
|
+
|
|
|
+ binding.GetBind(rootBinder, &binding.SimpleBindItem[any]{
|
|
|
+ Path: "/ping",
|
|
|
+ ResponseFunc: response.NoResponse,
|
|
|
+ ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
|
|
|
+ c.String(http.StatusOK, "pong")
|
|
|
+ return nil, nil
|
|
|
+ },
|
|
|
+ }, func(c *api.Context) {
|
|
|
+ fmt.Println("Root Route Before1")
|
|
|
+ c.Next()
|
|
|
+ fmt.Println("Root Route After1")
|
|
|
+ }, func(c *api.Context) {
|
|
|
+ fmt.Println("Root Route Before2")
|
|
|
+ c.Next()
|
|
|
+ fmt.Println("Root Route After2")
|
|
|
+ })
|
|
|
+
|
|
|
app.Api().
|
|
|
PrefixRouter().
|
|
|
RegisterVersionedRouter("v1", func(c *api.Context) {
|
|
|
@@ -51,19 +64,27 @@ func main() {
|
|
|
fmt.Println("Global Before2")
|
|
|
c.Next()
|
|
|
fmt.Println("Global After2")
|
|
|
- }).
|
|
|
- AddRoute(http.MethodGet, "/ping", func(c *api.Context) {
|
|
|
- c.String(http.StatusOK, "pong")
|
|
|
- }, func(c *api.Context) {
|
|
|
- fmt.Println("Versioned Route Before1")
|
|
|
- c.Next()
|
|
|
- fmt.Println("Versioned Route After1")
|
|
|
- }, func(c *api.Context) {
|
|
|
- fmt.Println("Versioned Route Before2")
|
|
|
- c.Next()
|
|
|
- fmt.Println("Versioned Route After2")
|
|
|
})
|
|
|
|
|
|
+ prefixRootBinder := app.Binder(application.RouterPrefix, "v1")
|
|
|
+
|
|
|
+ binding.GetBind(prefixRootBinder, &binding.SimpleBindItem[any]{
|
|
|
+ Path: "/ping",
|
|
|
+ ResponseFunc: response.NoResponse,
|
|
|
+ ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
|
|
|
+ c.String(http.StatusOK, "pong")
|
|
|
+ return nil, nil
|
|
|
+ },
|
|
|
+ }, func(c *api.Context) {
|
|
|
+ fmt.Println("Versioned Route Before1")
|
|
|
+ c.Next()
|
|
|
+ fmt.Println("Versioned Route After1")
|
|
|
+ }, func(c *api.Context) {
|
|
|
+ fmt.Println("Versioned Route Before2")
|
|
|
+ c.Next()
|
|
|
+ fmt.Println("Versioned Route After2")
|
|
|
+ })
|
|
|
+
|
|
|
go func() {
|
|
|
if err := app.Start(); err != nil {
|
|
|
panic(err)
|