33 lines
524 B
Go
33 lines
524 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
func main() {
|
|
connectDB()
|
|
|
|
router := chi.NewRouter()
|
|
|
|
router.Use(logMiddleware)
|
|
router.Use(authMiddleware)
|
|
|
|
// routes
|
|
router.Get("/quotes", getQuotes)
|
|
router.Post("/quotes", createQuote)
|
|
router.Put("/quotes/{id}", updateQuote)
|
|
router.Delete("/quotes/{id}", deleteQuote)
|
|
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8080"
|
|
}
|
|
|
|
fmt.Println("started and listening on localhost:" + port)
|
|
http.ListenAndServe(":"+port, router)
|
|
}
|