init.go 1006 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import (
  3. "fieldproject_common/config"
  4. "fieldproject_common/db"
  5. "fmt"
  6. "go.uber.org/zap"
  7. "os"
  8. "utils/log"
  9. )
  10. // InitDb @Description
  11. // @Author J 2022/7/26 15:20
  12. func InitDb() error {
  13. var (
  14. err error
  15. )
  16. dbcfg := config.Conf.DB
  17. err = db.NewDb(db.Drivename(dbcfg.Drivename),
  18. db.Dsn(dbcfg.Dsn),
  19. db.MaxIdleConnection(dbcfg.MaxIdle),
  20. db.MaxOpenConnection(dbcfg.MaxConn),
  21. db.MaxQueryTime(dbcfg.MaxQueryTime.Duration),
  22. )
  23. if err != nil {
  24. return err
  25. }
  26. log.Debug("InitDb Success", zap.String("drive", dbcfg.Drivename), zap.String("DSN", dbcfg.Dsn))
  27. return nil
  28. }
  29. // InitLog @Description
  30. // @Author J 2022/7/26 15:30
  31. func InitLog() {
  32. logcfg := config.Conf.Log
  33. err := log.InitLog(
  34. log.Path(logcfg.LogPath),
  35. log.Level(logcfg.LogLevel),
  36. log.Compress(logcfg.Compress),
  37. log.MaxSize(logcfg.MaxSize),
  38. log.MaxBackups(logcfg.MaxBackups),
  39. log.MaxAge(logcfg.MaxAge),
  40. log.Format(logcfg.Format),
  41. )
  42. if err != nil {
  43. fmt.Printf("InitLog failed: %v\n", err)
  44. os.Exit(1)
  45. }
  46. }