config.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package config
  4. import "encoding/json"
  5. type LogConfig struct {
  6. Path string `mapstructure:"path"`
  7. Level string `mapstructure:"level"`
  8. MaxSize json.Number `mapstructure:"max_size"`
  9. MaxBackups json.Number `mapstructure:"max_backups"`
  10. MaxAge json.Number `mapstructure:"max_age"`
  11. Stacktrace string `mapstructure:"stacktrace"`
  12. }
  13. type MysqlConfig struct {
  14. User string `mapstructure:"user"`
  15. Password string `mapstructure:"password"`
  16. Addr string `mapstructure:"addr"`
  17. Db string `mapstructure:"db"`
  18. Charset string `mapstructure:"charset"`
  19. MaxIdle json.Number `mapstructure:"max_idle"`
  20. MaxConn json.Number `mapstructure:"max_conn"`
  21. LogMode string `mapstructure:"log_mode"`
  22. }
  23. type RedisConfig struct {
  24. Addrs string `mapstructure:"addrs"`
  25. Password string `mapstructure:"password"`
  26. Db json.Number `mapstructure:"db"`
  27. PoolSize json.Number `mapstructure:"pool_size"`
  28. MinIdleConns json.Number `mapstructure:"min_idle_conns"`
  29. MaxRetries json.Number `mapstructure:"max_retries"`
  30. IsCluster string `mapstructure:"is_cluster"`
  31. }
  32. type ElasticConfig struct {
  33. Addrs string `mapstructure:"addrs"`
  34. Sniff string `mapstructure:"sniff"`
  35. }
  36. type RPCNode struct {
  37. ServiceName string `mapstructure:"service_name"`
  38. ServicePort json.Number `mapstructure:"service_port"`
  39. ServiceIp string `mapstructure:"service_ip"`
  40. MysqlDb string `mapstructure:"mysql_db"`
  41. RedisDb json.Number `mapstructure:"redis_db"`
  42. LogLevel string `mapstructure:"log_level"`
  43. LogStacktrace string `mapstructure:"log_stacktrace"`
  44. }
  45. type KeepaliveConfig struct {
  46. ClientTime json.Number `mapstructure:"client_time"`
  47. ClientTimeout json.Number `mapstructure:"client_timeout"`
  48. ServerTime json.Number `mapstructure:"server_time"`
  49. ServerTimeout json.Number `mapstructure:"server_timeout"`
  50. ServerMiniTime json.Number `mapstructure:"server_mini_time"`
  51. }
  52. type RPCConfig struct {
  53. Prefix string `mapstructure:"prefix"`
  54. Keepalive KeepaliveConfig `mapstructure:"keepalive"`
  55. AdmTask RPCNode `mapstructure:"adm_task"`
  56. }
  57. type MongoConfig struct {
  58. User string `mapstructure:"user"`
  59. Password string `mapstructure:"password"`
  60. Addr string `mapstructure:"addr"`
  61. }
  62. type OssConfig struct {
  63. Endpoint string `mapstructure:"endpoint"`
  64. Id string `mapstructure:"id"`
  65. Secret string `mapstructure:"secret"`
  66. Bucket string `mapstructure:"bucket"`
  67. }
  68. type Configure struct {
  69. // 基础配置
  70. RunMode string `mapstructure:"run_mode" mapstructure:"run_mode"`
  71. Log LogConfig `mapstructure:"log"`
  72. // 按需配置
  73. Mysql MysqlConfig `mapstructure:"mysql"`
  74. Mongo MongoConfig `mapstructure:"mongo"`
  75. Redis RedisConfig `mapstructure:"redis"`
  76. Elastic ElasticConfig `mapstructure:"elastic"`
  77. Oss OssConfig `mapstructure:"oss"`
  78. // 所要启用的服务
  79. Rpc RPCConfig `mapstructure:"rpc"`
  80. FeildLoopTime json.Number `mapstructure:"feild_loop_time"`
  81. }