config.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. Log "mlog"
  6. "os"
  7. "runtime"
  8. "template"
  9. //"github.com/bolt-master"
  10. tml "github.com/toml-master"
  11. )
  12. var (
  13. configPath = flag.String("f", "./coinproxy.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 coinInit() {
  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. // if db.initBoltDb() == false {
  56. // log.Error("init bolt db error")
  57. // os.Exit(0)
  58. // }
  59. for _, cointype := range Gconfig.CoinType.Type {
  60. coin, err := template.New(cointype)
  61. if err != nil {
  62. log.Error(err.Error())
  63. os.Exit(0)
  64. }
  65. if coin.InitDriver(nil) == false {
  66. log.Error("InitDriver error.driver name:%s", cointype)
  67. os.Exit(0)
  68. }
  69. }
  70. }