| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package main
- 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() {
- 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,
- SimplePassThrough: &gateway.SimplePassThrough{
- 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()
- }
|