sys_init.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package system
  2. import (
  3. "fmt"
  4. "github.com/gogf/gf/v2/frame/g"
  5. )
  6. type DbInitIsInitReq struct {
  7. g.Meta `path:"/dbInit/isInit" tags:"系统初始化" method:"get" summary:"系统初始化"`
  8. }
  9. type DbInitIsInitRes bool
  10. type DbInitGetEnvInfoReq struct {
  11. g.Meta `path:"/dbInit/getEnvInfo" tags:"系统初始化" method:"get" summary:"获取环境信息"`
  12. }
  13. type DbInitGetEnvInfoRes g.Map
  14. type DbInitCreateDbReq struct {
  15. g.Meta `path:"/dbInit/createDb" tags:"系统初始化" method:"post" summary:"创建配置文件"`
  16. DbHost string `json:"dbHost" p:"dbHost" v:"required#数据库地址必须"`
  17. DbPort int `json:"dbPort" p:"dbPort" v:"required#数据库端口必须"`
  18. DbUser string `json:"dbUser" p:"dbUser" v:"required#数据库用户名称必须"`
  19. DbPass string `json:"dbPass"`
  20. DbName string `json:"dbName" p:"dbName" v:"required#数据库名称必须"`
  21. DbCharset string `json:"dbCharset" p:"dbCharset" v:"required#数据库编码必须"`
  22. RedisAddress string `json:"redisAddress" p:"redisAddress" v:"required#Redis地址必须"`
  23. RedisPort int `json:"redisPort" p:"redisPort" v:"required#Redis端口必须"`
  24. RedisDb int `json:"redisDb" p:"redisDb" v:"required#Redis索引必须"`
  25. RedisPass string `json:"redisPass"`
  26. }
  27. type DbInitCreateDbRes bool
  28. func (req *DbInitCreateDbReq) ToDbInitConfig() *DbInitConfig {
  29. return &DbInitConfig{
  30. Database: Database{
  31. Default: DbDefault{
  32. Host: req.DbHost,
  33. Port: req.DbPort,
  34. User: req.DbUser,
  35. Pass: req.DbPass,
  36. Name: req.DbName,
  37. Type: "mysql",
  38. Role: "master",
  39. Debug: true,
  40. Charset: req.DbCharset,
  41. DryRun: false,
  42. MaxIdle: 10,
  43. MaxOpen: 10,
  44. MaxLifetime: 10,
  45. },
  46. },
  47. Redis: Redis{
  48. Default: RedisDefault{
  49. Address: fmt.Sprintf("%s:%d", req.RedisAddress, req.RedisPort),
  50. Db: req.RedisDb,
  51. Pass: req.RedisPass,
  52. IdleTimeout: 600,
  53. MaxActive: 100,
  54. },
  55. },
  56. }
  57. }
  58. // 程序初始化yaml配置文件
  59. type DbInitConfig struct {
  60. Database Database `json:"database" yaml:"database"`
  61. Redis Redis `json:"redis" yaml:"redis"`
  62. }
  63. type Database struct {
  64. Default DbDefault `json:"default" yaml:"default"`
  65. }
  66. type DbDefault struct {
  67. Host string `json:"host" yaml:"host"`
  68. Port int `json:"port" yaml:"port"`
  69. User string `json:"user" yaml:"user"`
  70. Pass string `json:"pass" yaml:"pass"`
  71. Name string `json:"name" yaml:"name"`
  72. Type string `json:"type" yaml:"type"`
  73. Role string `json:"role" yaml:"role"`
  74. Debug bool `json:"debug" yaml:"debug"`
  75. Charset string `json:"charset" yaml:"charset"`
  76. DryRun bool `json:"dryRun" yaml:"dryRun"`
  77. MaxIdle int `json:"maxIdle" yaml:"maxIdle"`
  78. MaxOpen int `json:"maxOpen" yaml:"maxOpen"`
  79. MaxLifetime int `json:"maxLifetime" yaml:"maxLifetime"`
  80. }
  81. type Redis struct {
  82. Default RedisDefault `json:"default" yaml:"default"`
  83. }
  84. type RedisDefault struct {
  85. Address string `json:"address" yaml:"address"`
  86. Db int `json:"db" yaml:"db"`
  87. Pass string `json:"pass" yaml:"pass"`
  88. IdleTimeout int `json:"idleTimeout" yaml:"idleTimeout"`
  89. MaxActive int `json:"maxActive" yaml:"maxActive"`
  90. }