main.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/tsdrm/go-tool/config"
  5. "github.com/tsdrm/go-tool/log"
  6. "userline"
  7. )
  8. func main() {
  9. var conf = "config.conf"
  10. var cfg = config.NewConfig()
  11. var err = cfg.Config(conf)
  12. if err != nil {
  13. fmt.Printf("Main read config: %v error: %v", conf, err)
  14. log.E("Main read config: %v error: %v", conf, err)
  15. return
  16. }
  17. cfg.Print()
  18. err = log.RedirectFile(cfg.String("LOG_PATH"))
  19. if err != nil {
  20. log.W("Main redirect log to file: %v error: %v", cfg.String("LOG_PATH"), err)
  21. return
  22. }
  23. userline.HOST_ADDR = cfg.String("HOST_ADDR")
  24. // dial to mongodb
  25. err = userline.Dial(cfg.String("DB_CONN"), cfg.String("DB_NAME"))
  26. if err != nil {
  27. log.E("Main dial mongodb with DB_CONN: %v, DB_NAME: %v error: %v", cfg.String("DB_CONN"), cfg.String("DB_NAME"), err)
  28. return
  29. }
  30. log.D("Main dial mongodb with DB_CONN: %v, DB_NAME: %v success", cfg.String("DB_CONN"), cfg.String("DB_NAME"))
  31. // register http handler
  32. log.D("Main server will start !!!")
  33. // start
  34. userline.GetNum()
  35. log.D("Main server will stop !!!")
  36. }