refactor: call database functions from app.Server.Database instead of directly from db
This commit is contained in:
19
main.go
19
main.go
@ -7,9 +7,9 @@ import (
|
||||
"github.com/fossyy/filekeeper/email"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/middleware"
|
||||
"github.com/fossyy/filekeeper/routes"
|
||||
"github.com/fossyy/filekeeper/routes/admin"
|
||||
"github.com/fossyy/filekeeper/routes/client"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@ -24,24 +24,15 @@ func main() {
|
||||
dbName := utils.Getenv("DB_NAME")
|
||||
|
||||
database := db.NewPostgresDB(dbUser, dbPass, dbHost, dbPort, dbName, db.DisableSSL)
|
||||
db.DB = database
|
||||
|
||||
smtpPort, _ := strconv.Atoi(utils.Getenv("SMTP_PORT"))
|
||||
mailServer := email.NewSmtpServer(utils.Getenv("SMTP_HOST"), smtpPort, utils.Getenv("SMTP_USER"), utils.Getenv("SMTP_PASSWORD"))
|
||||
|
||||
app.Server = app.NewClientServer(clientAddr, middleware.Handler(routes.SetupRoutes()), *logger.Logger(), database, mailServer)
|
||||
|
||||
//TODO: Move admin route to its own folder
|
||||
testRoute := http.NewServeMux()
|
||||
testRoute.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("Hello, World!"))
|
||||
return
|
||||
})
|
||||
|
||||
app.Admin = app.NewAdminServer(adminAddr, testRoute, database)
|
||||
app.Server = app.NewClientServer(clientAddr, middleware.Handler(client.SetupRoutes()), *logger.Logger(), database, mailServer)
|
||||
app.Admin = app.NewAdminServer(adminAddr, middleware.Handler(admin.SetupRoutes()), database)
|
||||
|
||||
go func() {
|
||||
fmt.Printf("Admin Web App Listening on http://%s\n\n", app.Admin.Addr)
|
||||
fmt.Printf("Admin Web App Listening on http://%s\n", app.Admin.Addr)
|
||||
err := app.Admin.ListenAndServe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Reference in New Issue
Block a user