config.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. Sigkey string
  39. }
  40. func coinInit() {
  41. runtime.GOMAXPROCS(CPUNUM)
  42. flag.PrintDefaults()
  43. flag.Parse()
  44. if _, err := tml.DecodeFile(*configPath, &Gconfig); err != nil {
  45. fmt.Println(err)
  46. os.Exit(0)
  47. }
  48. fmt.Printf("%+v\n", Gconfig)
  49. var err error
  50. log, err = Log.New(Gconfig.Log.Logpath, Gconfig.Log.Loglevel)
  51. if err != nil {
  52. log.Error(err.Error())
  53. os.Exit(0)
  54. }
  55. initChanHandler(CPUNUM)
  56. // if db.initBoltDb() == false {
  57. // log.Error("init bolt db error")
  58. // os.Exit(0)
  59. // }
  60. for _, cointype := range Gconfig.CoinType.Type {
  61. coin, err := template.New(cointype)
  62. if err != nil {
  63. log.Error(err.Error())
  64. os.Exit(0)
  65. }
  66. if coin.InitDriver(nil) == false {
  67. log.Error("InitDriver error.driver name:%s", cointype)
  68. os.Exit(0)
  69. }
  70. }
  71. }