Files
gun-manager-backend/main.go

56 lines
1.1 KiB
Go

package main
import (
"flag"
"git.siteworxpro.com/gun-manager/Handlers/Guns"
"git.siteworxpro.com/gun-manager/sql"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"log"
"os"
)
func main() {
var dbFile string
flag.StringVar(&dbFile, "database", "", "the database file to load")
flag.Parse()
if dbFile == "" {
flag.Usage()
os.Exit(1)
}
_, err := sql.NewDb(dbFile)
if err != nil {
log.Fatal(err)
}
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{
"http://127.0.0.1:5173",
"http://localhost:5173",
"http://127.0.0.1:4173",
"http://127.0.0.1:8000",
},
AllowMethods: nil,
}))
e.Static("/", "dist")
e.GET("/gun", Guns.Get)
e.PUT("/gun/:id", Guns.UpdateGun)
e.GET("/gun/:id", Guns.GetById)
e.DELETE("/gun/:id", Guns.DeleteById)
e.POST("/gun", Guns.Post)
e.GET("/gun/photo/:id/:filename", Guns.GetPhoto)
e.POST("/gun/photo/:id", Guns.PostPhoto)
e.DELETE("/gun/photo/:id", Guns.DeletePhoto)
e.GET("/gun/photo/:id/:size/:filename", Guns.GetPhotoResize)
e.Logger.Fatal(e.Start(":8000"))
}