From 4ba1f9aeac0d78388190d79ea6bbc3726aa72207 Mon Sep 17 00:00:00 2001 From: Gregory Salaun Date: Sat, 15 Apr 2023 18:20:06 +0700 Subject: [PATCH] update --- api/server.go | 6 +++--- database/sqlite.go | 1 + main.go | 27 ++++++++++++++------------- racer.db | Bin 24576 -> 0 bytes 4 files changed, 18 insertions(+), 16 deletions(-) delete mode 100644 racer.db diff --git a/api/server.go b/api/server.go index 8b1d3f0..cc9f148 100644 --- a/api/server.go +++ b/api/server.go @@ -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") diff --git a/database/sqlite.go b/database/sqlite.go index b5da249..ba16db8 100644 --- a/database/sqlite.go +++ b/database/sqlite.go @@ -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) + } diff --git a/main.go b/main.go index 3e28e85..5249e09 100644 --- a/main.go +++ b/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() { diff --git a/racer.db b/racer.db deleted file mode 100644 index cf18a8bab07987ac244587d54ea0017f15d35109..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 24576 zcmeI&O>YuG7zglKXsNXl^x|G@GT9TP%VvR6+j_Ao#wNU|ZR1O#WXg`P5q9b9tQHR% zO%ERYQho!!jPc^ZSqio+_;T`q{|W34&(1!x{GMr(&9e8P>Pk*u_@c)oEs@Ja)5uLq z2_dP`TkVEzL2aY=xM}0gZ}ur-HLs=BfW;L?(qGbV(^pnLt1cP@AOHafKmY;|fB*#M zQ{eexN-yi$JJ)mgvFjW+1#9u3>F_R>+-Wj7{G7V|u(GpXp}X}vmB)0}Fxse7V>s5x zo}HYdA8HFrx~^*{1IZ4%d^lpbSsbO@-?>$-j8COm!*vYmdXl%fpnc)?m>AHPd_Y+! zeb;LV-s7G$4b@?%7idsN^`zV5rV;j|estOAqi5H1KH6bH$Dps6Xmyy#mhGHrNM8t* zz3H(YKRZ+`mvgk<*r)Y_YE{jwW@!6j@aqA-x_p(T&*ZrYVp)Xm&l+JGf%_&lw`sig zJ%b+lewXH6CYSUZtJ?dOvx2Eov0$=hqtL>1*`^1dR&ErZEZ+S@N?%*ko(xMD9Cg*L zSTo>9A@|f8nf#cXC}-?oHUc%(nYoj^wxqAFY9I5b%V9LF80`}iS&VVm_?PQK4*IbI zoGboctq|$T?ypk>s#;M!M~mDvc;5|tN1gC95`>2{a;UZ8hoTkBY$~O|?}pNil8%>i zwA$2CRcTxCV8;>h5DOjGj|bJCh3D~Z5RbQoANJ!xUv~IZ+Aj0jA#2aL;NgmGPD`7{ zfHRe6{0|@(-J7eMel!R`00Izz00bZa0SG_<0uX=z1m;*Ey8qWQUx|95K>z{}fB*y_ z009U<00Izz00bZ~PXfzYQrCt*5=vZ*z89YV&r@~rT_6Af2tWV=5P$##AOHafKmY<$ z0@3sTMCK~Vd{P@U2tWV=5P$##AOHafKmY;|fWUtxAQP8Jtwz$%(yCo3+Qm}dUe6cG zv{2q&-`Xygtn$`oX{)eiU*ERvKONtZR?T%hx80FeG}fveRQFx0U~k%e>rv&FbzIz7 z&)u