update
This commit is contained in:
parent
2ed6c81827
commit
4ba1f9aeac
@ -20,16 +20,16 @@ func NewServer(listenAddr string) *Server {
|
||||
func (s *Server) Start() error {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
r := gin.Default()
|
||||
SetupRoutes(r)
|
||||
s.SetupRoutes(r)
|
||||
fmt.Println("Server is running on port:", config.HTTPPort)
|
||||
err := r.Run(":" + config.HTTPPort)
|
||||
err := r.Run(s.listenAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetupRoutes(app *gin.Engine) {
|
||||
func (s *Server) SetupRoutes(app *gin.Engine) {
|
||||
|
||||
api := app.Group("/api")
|
||||
v1 := api.Group("/v1")
|
||||
|
@ -17,4 +17,5 @@ func SQLiteDBConnect() {
|
||||
fmt.Println("[Database] Database successfully connected")
|
||||
//If set true then print all executed queries to the console
|
||||
db.LogMode(true)
|
||||
|
||||
}
|
||||
|
27
main.go
27
main.go
@ -2,11 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rouggy.com/rouggy/RaceBot/api"
|
||||
"git.rouggy.com/rouggy/RaceBot/config"
|
||||
"git.rouggy.com/rouggy/RaceBot/database"
|
||||
"git.rouggy.com/rouggy/RaceBot/models"
|
||||
"git.rouggy.com/rouggy/RaceBot/router"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -14,19 +14,20 @@ func main() {
|
||||
config.Load()
|
||||
|
||||
database.SQLiteDBConnect()
|
||||
defer database.GetDB().Close()
|
||||
defer func(db *gorm.DB) {
|
||||
err := db.Close()
|
||||
if err != nil {
|
||||
fmt.Println("Could not close the database")
|
||||
}
|
||||
}(database.GetDB())
|
||||
|
||||
SQLiteMigrate()
|
||||
ServeApplication()
|
||||
|
||||
}
|
||||
|
||||
func ServeApplication() {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
r := gin.Default()
|
||||
router.SetupRoutes(r)
|
||||
fmt.Println("Server is running on port:", config.HTTPPort)
|
||||
r.Run(":" + config.HTTPPort)
|
||||
|
||||
server := api.NewServer(":" + config.HTTPPort)
|
||||
err := server.Start()
|
||||
if err != nil {
|
||||
fmt.Println("Could not start server")
|
||||
}
|
||||
}
|
||||
|
||||
func SQLiteMigrate() {
|
||||
|
Reference in New Issue
Block a user