xtablo-source/go_backend/main.go
Arthur Belleville 50ba9b340b
Modify backend
2025-03-15 08:46:51 +01:00

57 lines
1.4 KiB
Go

package main
import (
"flag"
"net/http"
"time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
chi "github.com/go-chi/chi/v5"
)
// Here we are implementing the NotImplemented handler. Whenever an API endpoint is hit
// we will simply return the message "Not Implemented"
var NotImplemented = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Not Implemented"))
})
func main() {
// Prepare logger
zerolog.TimeFieldFormat = time.DateTime
var (
isDev = flag.Bool("dev", false, "run in development mode")
)
flag.Parse()
mux := chi.NewRouter()
if *isDev {
registerDevRoutes(mux)
} else {
registerProdRoutes(mux)
}
// Our API is going to consist of three routes
// /status - which we will call to make sure that our API is up and running
// /products - which will retrieve a list of products that the user can leave feedback on
// /products/{slug}/feedback - which will capture user feedback on products
mux.Get("/status", NotImplemented)
mux.Get("/products", NotImplemented)
mux.Post("/products/{slug}/feedback", NotImplemented)
server := &http.Server{
Addr: "0.0.0.0:8443",
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: time.Minute,
}
log.Info().Msg("Listening on port 8443...")
if err := server.ListenAndServe(); err != nil {
log.Error().Msg(err.Error())
panic(err)
}
}