mirror of
https://github.com/trafficlunar/api.git
synced 2026-06-27 22:24:08 +00:00
feat: add router
This commit is contained in:
parent
cb61a2a8b7
commit
2357f645ce
4 changed files with 35 additions and 1 deletions
29
internal/server/router.go
Normal file
29
internal/server/router.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
)
|
||||
|
||||
func NewRouter() {
|
||||
r := chi.NewRouter()
|
||||
|
||||
// Middleware
|
||||
r.Use(middleware.RequestID)
|
||||
r.Use(middleware.RealIP)
|
||||
r.Use(middleware.Logger)
|
||||
r.Use(middleware.Recoverer)
|
||||
r.Use(middleware.Timeout(60 * time.Second))
|
||||
|
||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "https://axolotlmaid.com", http.StatusPermanentRedirect)
|
||||
})
|
||||
|
||||
slog.Info("Starting server", slog.Any("port", os.Getenv("PORT")))
|
||||
http.ListenAndServe(":"+os.Getenv("PORT"), r)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue