A More Secure Internet Connection for Your Home https://fen.gg
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
1.3 KiB

  1. package model
  2. //
  3. // Fengg Security Gateway Server Application
  4. // Copyright (C) 2020 Lukas Matt <support@fen.gg>
  5. //
  6. // This program is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. //
  18. import (
  19. "os"
  20. "github.com/rs/zerolog"
  21. "github.com/jmoiron/sqlx"
  22. _ "github.com/lib/pq"
  23. )
  24. var logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, NoColor: true})
  25. func Logger(customLogger zerolog.Logger) {
  26. logger = customLogger.With().Str("package", "model").Logger()
  27. }
  28. var dbDriver, dbConnect string
  29. // DatabaseAuth sets the authentication credentials for sqlx.
  30. func DatabaseAuth(driver string, connect string) {
  31. dbDriver = driver
  32. dbConnect = connect
  33. }
  34. // Database returns the sqlx.DB pointer.
  35. // Remember to close the connection if you are done!
  36. func Database() (*sqlx.DB, error) {
  37. return sqlx.Connect(dbDriver, dbConnect)
  38. }