main.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package main
  2. import (
  3. "git.sxidc.com/go-framework/baize"
  4. "git.sxidc.com/go-framework/baize/application"
  5. "git.sxidc.com/go-framework/baize/convenient/value_object"
  6. "git.sxidc.com/go-framework/baize/examples/example_domain/configuration"
  7. "git.sxidc.com/go-framework/baize/infrastructure"
  8. "git.sxidc.com/go-framework/baize/infrastructure/database/operations"
  9. DEATH "github.com/vrecan/death"
  10. "syscall"
  11. )
  12. // curl -X POST -H "Content-Type: application/json" -d '{"scope": "global", "group":"test", "value":"test-value"}' "http://localhost:10100/test/v1/configuration/create"
  13. // curl -X GET "http://localhost:10100/test/v1/configuration/query?scope=global&pageNo=1&pageSize=1"
  14. // curl -X POST -H "Content-Type: application/json" -d '{"scope": "global", "group":"test"}' "http://localhost:10100/test/v1/configuration/delete"
  15. func main() {
  16. app := baize.NewApplication(application.Config{
  17. ApiConfig: application.ApiConfig{
  18. UrlPrefix: "test",
  19. Port: "10100",
  20. },
  21. InfrastructureConfig: application.InfrastructureConfig{
  22. Database: infrastructure.DatabaseConfig{
  23. Operations: &operations.Config{
  24. UserName: "test",
  25. Password: "123456",
  26. Address: "localhost",
  27. Port: "30432",
  28. Database: "test",
  29. MaxConnections: 40,
  30. MaxIdleConnections: 10,
  31. },
  32. },
  33. },
  34. })
  35. defer func() {
  36. baize.DestroyApplication(app)
  37. }()
  38. app.Api().
  39. PrefixRouter().
  40. RegisterVersionedRouter("v1")
  41. value_object.BindSimple[configuration.Info](app.Binder("v1"), &value_object.Simple[configuration.Info]{
  42. ValueObject: &configuration.Entity{},
  43. TableName: configuration.TableName,
  44. DomainPath: "/configuration",
  45. CreateJsonBody: &configuration.CreateConfigurationJsonBody{},
  46. DeleteQueryParams: &configuration.DeleteConfigurationJsonBody{},
  47. QueryQueryParams: &configuration.GetConfigurationValuesQueryParams{},
  48. })
  49. go func() {
  50. err := app.Start()
  51. if err != nil {
  52. panic(err)
  53. }
  54. }()
  55. defer func() {
  56. err := app.Finish()
  57. if err != nil {
  58. panic(err)
  59. }
  60. }()
  61. death := DEATH.NewDeath(syscall.SIGINT, syscall.SIGTERM)
  62. _ = death.WaitForDeath()
  63. }