config.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package main
  2. import (
  3. "commonapi"
  4. "flag"
  5. "fmt"
  6. Log "mlog"
  7. "os"
  8. "runtime"
  9. //"github.com/bolt-master"
  10. tml "github.com/toml-master"
  11. )
  12. var (
  13. configPath = flag.String("f", "./transcollect.toml", "configfile")
  14. Gconfig config
  15. log *Log.Logger
  16. CPUNUM = runtime.NumCPU()
  17. BucketSC string = "SC"
  18. )
  19. type config struct {
  20. Title string
  21. Log loginfo `toml:"log"`
  22. DB databaseinfo `toml:"db"`
  23. HttpServer httpServer `toml:"httpserver"`
  24. CoinType cointype
  25. }
  26. type loginfo struct {
  27. Loglevel string
  28. Logpath string
  29. }
  30. type httpServer struct {
  31. HttpBindAddr string
  32. }
  33. type databaseinfo struct {
  34. DbPath string
  35. }
  36. type cointype struct {
  37. Type []string
  38. }
  39. func sysInit() {
  40. runtime.GOMAXPROCS(CPUNUM)
  41. flag.PrintDefaults()
  42. flag.Parse()
  43. if _, err := tml.DecodeFile(*configPath, &Gconfig); err != nil {
  44. fmt.Println(err)
  45. os.Exit(0)
  46. }
  47. fmt.Printf("%+v\n", Gconfig)
  48. var err error
  49. log, err = Log.New(Gconfig.Log.Logpath, Gconfig.Log.Loglevel)
  50. if err != nil {
  51. log.Error(err.Error())
  52. os.Exit(0)
  53. }
  54. initChanHandler(CPUNUM)
  55. for _, cointype := range Gconfig.CoinType.Type {
  56. coin, err := commonapi.New(cointype)
  57. if err != nil {
  58. log.Error(err.Error())
  59. os.Exit(0)
  60. }
  61. if coin.InitDriver(nil) == false {
  62. log.Error("InitDriver error.driver name:%s", cointype)
  63. os.Exit(0)
  64. }
  65. }
  66. }