main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "git.sxidc.com/go-framework/baize"
  4. "git.sxidc.com/go-framework/baize/convenient/gateway"
  5. "git.sxidc.com/go-framework/baize/framework/binding"
  6. "git.sxidc.com/go-framework/baize/framework/core/api"
  7. "git.sxidc.com/go-framework/baize/framework/core/application"
  8. DEATH "github.com/vrecan/death"
  9. "net/http"
  10. "syscall"
  11. )
  12. func main() {
  13. app := baize.NewApplication(application.Config{
  14. ApiConfig: application.ApiConfig{
  15. UrlPrefix: "/gateway/api",
  16. Port: "11000",
  17. },
  18. })
  19. app.Api().
  20. PrefixRouter().
  21. RegisterVersionedRouter("v1")
  22. prefixRootBinder := binding.NewBinder(app.ChooseRouter(api.RouterPrefix, ""), app.Infrastructure())
  23. gw := gateway.NewGateway()
  24. defer gateway.DestroyGateway(gw)
  25. gw.BindPassThrough(prefixRootBinder, &gateway.PassThrough{
  26. HttpMethod: http.MethodGet,
  27. SimplePassThrough: &gateway.SimplePassThrough{
  28. RelativePath: "/version",
  29. ToUrl: "http://localhost:31000/example/api/version",
  30. },
  31. })
  32. go func() {
  33. if err := app.Start(); err != nil {
  34. panic(err)
  35. }
  36. }()
  37. defer func() {
  38. if err := app.Finish(); err != nil {
  39. panic(err)
  40. }
  41. }()
  42. death := DEATH.NewDeath(syscall.SIGINT, syscall.SIGTERM)
  43. _ = death.WaitForDeath()
  44. }