main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. RelativePath: "/version",
  28. ToUrl: "http://localhost:31000/example/api/version",
  29. })
  30. go func() {
  31. if err := app.Start(); err != nil {
  32. panic(err)
  33. }
  34. }()
  35. defer func() {
  36. if err := app.Finish(); err != nil {
  37. panic(err)
  38. }
  39. }()
  40. death := DEATH.NewDeath(syscall.SIGINT, syscall.SIGTERM)
  41. _ = death.WaitForDeath()
  42. }