This commit is contained in:
2023-08-07 10:14:38 -04:00
parent a30b1769b3
commit 5dd3fa9451
18 changed files with 548 additions and 276 deletions

30
main.go
View File

@@ -3,13 +3,11 @@ package main
import (
"flag"
"git.siteworxpro.com/gun-manager/Handlers/Guns"
"git.siteworxpro.com/gun-manager/Handlers/Photo"
"git.siteworxpro.com/gun-manager/sql"
"github.com/gorilla/mux"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"log"
"net/http"
"os"
"time"
)
func main() {
@@ -29,18 +27,18 @@ func main() {
log.Fatal(err)
}
r := mux.NewRouter()
r.HandleFunc("/", Guns.Get).Methods("GET")
r.HandleFunc("/photo/{id}/{fileName}", Photo.Get).Methods("GET")
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"localhost"},
AllowMethods: nil,
}))
srv := &http.Server{
Handler: r,
Addr: "0.0.0.0:8000",
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
e.GET("/gun", Guns.Get)
e.GET("/gun/:id", Guns.GetById)
e.POST("/gun", Guns.Post)
e.GET("/gun/photo/:id/:filename", Guns.GetPhoto)
log.Println("Starting Server: 0.0.0.0:8000")
log.Fatal(srv.ListenAndServe())
e.Logger.Fatal(e.Start(":8000"))
}