You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.6 KiB
64 lines
1.6 KiB
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)
|
|
}
|