|
|
@@ -1,7 +1,51 @@
|
|
|
package main
|
|
|
|
|
|
-import "git.sxidc.com/go-framework/baize/convenient/gateway"
|
|
|
+import (
|
|
|
+ "git.sxidc.com/go-framework/baize"
|
|
|
+ "git.sxidc.com/go-framework/baize/convenient/gateway"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/binding"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/core/api"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/core/application"
|
|
|
+ DEATH "github.com/vrecan/death"
|
|
|
+ "net/http"
|
|
|
+ "syscall"
|
|
|
+)
|
|
|
|
|
|
func main() {
|
|
|
- gateway.NewGateway()
|
|
|
+ app := baize.NewApplication(application.Config{
|
|
|
+ ApiConfig: application.ApiConfig{
|
|
|
+ UrlPrefix: "/gateway/api",
|
|
|
+ Port: "11000",
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ app.Api().
|
|
|
+ PrefixRouter().
|
|
|
+ RegisterVersionedRouter("v1")
|
|
|
+
|
|
|
+ prefixRootBinder := binding.NewBinder(app.ChooseRouter(api.RouterPrefix, ""), app.Infrastructure())
|
|
|
+
|
|
|
+ gw := gateway.NewGateway()
|
|
|
+ defer gateway.DestroyGateway(gw)
|
|
|
+
|
|
|
+ gw.BindPassThrough(prefixRootBinder, &gateway.PassThrough{
|
|
|
+ HttpMethod: http.MethodGet,
|
|
|
+ RelativePath: "/version",
|
|
|
+ ToUrl: "http://localhost:31000/example/api/version",
|
|
|
+ })
|
|
|
+
|
|
|
+ go func() {
|
|
|
+ if err := app.Start(); err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ defer func() {
|
|
|
+ if err := app.Finish(); err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ death := DEATH.NewDeath(syscall.SIGINT, syscall.SIGTERM)
|
|
|
+ _ = death.WaitForDeath()
|
|
|
}
|