Feat(ktm-booking): Initial commit
Some checks failed
ktm-booking-bot/ktm-booking-bot/pipeline/head Something is wrong with the build of this commit
Some checks failed
ktm-booking-bot/ktm-booking-bot/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
64
backend/cmd/server/main.go
Normal file
64
backend/cmd/server/main.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
_ "git.samuelpua.com/telboon/ktm-train-bot/backend/docs"
|
||||
"git.samuelpua.com/telboon/ktm-train-bot/backend/internal/common"
|
||||
"git.samuelpua.com/telboon/ktm-train-bot/backend/internal/ktmtrainbot"
|
||||
"git.samuelpua.com/telboon/ktm-train-bot/backend/internal/user"
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/joho/godotenv"
|
||||
httpSwagger "github.com/swaggo/http-swagger"
|
||||
)
|
||||
|
||||
// Root Handler - Test
|
||||
// @Summary This is test
|
||||
// @Description Description
|
||||
// @Tags Base
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} string
|
||||
// @Failure 404 {object} string
|
||||
// @Router / [get]
|
||||
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("hello world"))
|
||||
}
|
||||
|
||||
// @title KTM Train Booking Bot
|
||||
// @version 1.0
|
||||
// @description API for frontend - built on Go-chi
|
||||
// @BasePath /
|
||||
// @contact.name Samuel Pua
|
||||
// @contact.url https://git.samuelpua.com/telboon
|
||||
func main() {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
environment := os.Getenv("ENVIRONMENT")
|
||||
|
||||
db := common.InitDB()
|
||||
db.AutoMigrate(&user.User{})
|
||||
db.AutoMigrate(&user.Profile{})
|
||||
db.AutoMigrate(&user.Session{})
|
||||
db.AutoMigrate(&ktmtrainbot.Booking{})
|
||||
|
||||
r := chi.NewRouter()
|
||||
|
||||
if environment == "dev" {
|
||||
r.Mount("/docs", httpSwagger.WrapHandler)
|
||||
}
|
||||
|
||||
r.Mount("/api/v1/user", user.UserRoutes(db))
|
||||
r.Mount("/api/v1/ktmtrainbot", ktmtrainbot.KTMTrainBotRoutes(db))
|
||||
|
||||
r.Get("/", rootHandler)
|
||||
r.Get("/health", healthHandler)
|
||||
|
||||
server_str := ":8000"
|
||||
log.Printf("Starting server at %s\n", server_str)
|
||||
http.ListenAndServe(server_str, r)
|
||||
}
|
||||
Reference in New Issue
Block a user