main.go 988 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import (
  3. "git.sxidc.com/go-framework/baize"
  4. "git.sxidc.com/go-framework/baize/application"
  5. DEATH "github.com/vrecan/death"
  6. "syscall"
  7. )
  8. type Hello struct {
  9. What string `json:"what"`
  10. }
  11. func main() {
  12. app := baize.NewApplication(application.Config{
  13. ApiConfig: application.ApiConfig{
  14. UrlPrefix: "test",
  15. Port: "10000",
  16. },
  17. })
  18. versionedRouter := app.Api().PrefixRouter().RegisterVersionedRouter("v1")
  19. binding.GetBind(versionedRouter, &binding.SimpleBindItem[any, map[string]any]{
  20. Path: "/version",
  21. ResponseFunc: response.SendMapResponse,
  22. BusinessFunc: func(c *binding_context.Context, inputModel any) (map[string]any, error) {
  23. return map[string]any{
  24. "version": "v1.0.0",
  25. }, nil
  26. },
  27. })
  28. go func() {
  29. err := app.Start()
  30. if err != nil {
  31. panic(err)
  32. }
  33. }()
  34. defer func() {
  35. err := app.Finish()
  36. if err != nil {
  37. panic(err)
  38. }
  39. }()
  40. death := DEATH.NewDeath(syscall.SIGINT, syscall.SIGTERM)
  41. _ = death.WaitForDeath()
  42. }