Added environment variables
This commit is contained in:
59
main.go
59
main.go
@@ -2,11 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"novatech/config"
|
||||
"novatech/models"
|
||||
"novatech/routes"
|
||||
"novatech/shared"
|
||||
|
||||
"github.com/VoidArtanis/go-rest-boilerplate/routes"
|
||||
"github.com/VoidArtanis/go-rest-boilerplate/shared"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/qor/admin"
|
||||
@@ -15,45 +17,40 @@ import (
|
||||
var DB *gorm.DB
|
||||
|
||||
func main() {
|
||||
// Initialize the database connection
|
||||
DB, err := gorm.Open("postgres", "host=localhost user=postgres dbname=postgres sslmode=disable password=root")
|
||||
|
||||
|
||||
// LOAD APPLICATION CONFIGURATION
|
||||
err := config.Load()
|
||||
if err != nil {
|
||||
fmt.Println("Error opening database:", err)
|
||||
return
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer DB.Close()
|
||||
|
||||
// AutoMigrate the User model
|
||||
DB.AutoMigrate(&models.User{})
|
||||
|
||||
// Initialize Admin interface
|
||||
Admin := admin.New(&admin.AdminConfig{DB: DB})
|
||||
|
||||
// Allow Admin to manage User resource
|
||||
Admin.AddResource(&models.User{})
|
||||
|
||||
// Initialize HTTP request multiplexer
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// Mount admin interface to mux
|
||||
Admin.MountTo("/admin", mux)
|
||||
|
||||
// Start the admin server in a separate goroutine
|
||||
go func() {
|
||||
fmt.Println("Admin server listening on :9000")
|
||||
http.ListenAndServe(":9000", mux)
|
||||
}()
|
||||
|
||||
// Db Connect and Close
|
||||
shared.Init()
|
||||
defer shared.CloseDb()
|
||||
|
||||
// Initialize Admin interface
|
||||
Admin := admin.New(&admin.AdminConfig{DB: shared.GetDb()})
|
||||
// Allow Admin to manage User resource
|
||||
Admin.AddResource(&models.User{})
|
||||
// Initialize HTTP request multiplexer
|
||||
mux := http.NewServeMux()
|
||||
// Mount admin interface to mux
|
||||
Admin.MountTo("/admin", mux)
|
||||
|
||||
// Start the admin server in a separate goroutine
|
||||
go func() {
|
||||
port := config.AppConfig.Service.Port
|
||||
fmt.Println("Admin server listening on :" + port)
|
||||
http.ListenAndServe(":" + port, mux)
|
||||
}()
|
||||
|
||||
// Initialize Gin
|
||||
r := gin.Default()
|
||||
routes.InitRouter(r)
|
||||
|
||||
// Start the Gin server on another port
|
||||
fmt.Println("Application server listening on :8080")
|
||||
r.Run(":8080")
|
||||
port := config.AppConfig.AdminService.Port
|
||||
fmt.Println("Application server listening on :" + port)
|
||||
r.Run(":" + port)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user