conf.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package conf
  2. import (
  3. "flag"
  4. "go-common/library/cache/memcache"
  5. "go-common/library/cache/redis"
  6. "go-common/library/database/sql"
  7. ecode "go-common/library/ecode/tip"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/trace"
  11. "github.com/BurntSushi/toml"
  12. )
  13. // global var
  14. var (
  15. confPath string
  16. // Conf config
  17. Conf = &Config{}
  18. )
  19. // Config config set
  20. type Config struct {
  21. // elk
  22. Log *log.Config
  23. // http
  24. BM *HTTPServers
  25. // tracer
  26. Tracer *trace.Config
  27. // redis
  28. Redis *redis.Config
  29. // memcache
  30. Memcache *memcache.Config
  31. // MySQL
  32. MySQL *sql.Config
  33. // ecode
  34. Ecode *ecode.Config
  35. }
  36. // HTTPServers Http Servers
  37. type HTTPServers struct {
  38. Outer *bm.ServerConfig
  39. Inner *bm.ServerConfig
  40. Local *bm.ServerConfig
  41. }
  42. func init() {
  43. flag.StringVar(&confPath, "conf", "./stress-test.toml", "default config path")
  44. }
  45. // Init init conf
  46. func Init() error {
  47. if confPath != "" {
  48. return local()
  49. }
  50. s := `# This is a TOML document. Boom
  51. version = "1.0.0"
  52. user = "nobody"
  53. pid = "/tmp/stress.pid"
  54. dir = "./"
  55. perf = "0.0.0.0:6420"
  56. trace = false
  57. debug = false
  58. [log]
  59. #dir = "/data/log/stress"
  60. #[log.agent]
  61. # taskID = "000161"
  62. # proto = "unixgram"
  63. # addr = "/var/run/lancer/collector.sock"
  64. # chan = 10240
  65. [bm]
  66. [bm.inner]
  67. addr = "0.0.0.0:9001"
  68. timeout = "1s"
  69. [bm.local]
  70. addr = "0.0.0.0:9002"
  71. timeout = "1s"`
  72. _, err := toml.Decode(s, &Conf)
  73. return err
  74. }
  75. func local() (err error) {
  76. _, err = toml.DecodeFile(confPath, &Conf)
  77. return
  78. }