You've already forked gun-manager-backend
49 lines
1003 B
Go
49 lines
1003 B
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{"localhost"},
|
|
AllowMethods: nil,
|
|
}))
|
|
|
|
e.GET("/gun", Guns.Get)
|
|
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"))
|
|
}
|