mongoconf.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package servercfg
  2. import (
  3. "github.com/gravitl/netmaker/config"
  4. "os"
  5. )
  6. func GetMongoUser() string {
  7. user := "mongoadmin"
  8. if os.Getenv("MONGO_ADMIN") != "" {
  9. user = os.Getenv("MONGO_ADMIN")
  10. } else if config.Config.MongoConn.User != "" {
  11. user = config.Config.MongoConn.User
  12. }
  13. return user
  14. }
  15. func GetMongoPass() string {
  16. pass := "mongopass"
  17. if os.Getenv("MONGO_PASS") != "" {
  18. pass = os.Getenv("MONGO_PASS")
  19. } else if config.Config.MongoConn.Pass != "" {
  20. pass = config.Config.MongoConn.Pass
  21. }
  22. return pass
  23. }
  24. func GetMongoHost() string {
  25. host := "127.0.0.1"
  26. if os.Getenv("MONGO_HOST") != "" {
  27. host = os.Getenv("MONGO_HOST")
  28. } else if config.Config.MongoConn.Host != "" {
  29. host = config.Config.MongoConn.Host
  30. }
  31. return host
  32. }
  33. func GetMongoPort() string {
  34. port := "27017"
  35. if os.Getenv("MONGO_PORT") != "" {
  36. port = os.Getenv("MONGO_PORT")
  37. } else if config.Config.MongoConn.Port != "" {
  38. port = config.Config.MongoConn.Port
  39. }
  40. return port
  41. }
  42. func GetMongoOpts() string {
  43. opts := "/?authSource=admin"
  44. if os.Getenv("MONGO_OPTS") != "" {
  45. opts = os.Getenv("MONGO_OPTS")
  46. } else if config.Config.MongoConn.Opts != "" {
  47. opts = config.Config.MongoConn.Opts
  48. }
  49. return opts
  50. }