Redmage/server/routes/api/api.go

25 lines
647 B
Go
Raw Normal View History

2024-04-07 12:11:25 +07:00
package api
2024-04-07 23:41:00 +07:00
import (
"github.com/go-chi/chi/v5"
chimiddleware "github.com/go-chi/chi/v5/middleware"
"github.com/tigorlazuardi/redmage/config"
2024-04-07 23:41:00 +07:00
"github.com/tigorlazuardi/redmage/db/queries/subreddits"
"github.com/tigorlazuardi/redmage/server/routes/middleware"
)
2024-04-07 12:11:25 +07:00
2024-04-07 23:41:00 +07:00
type API struct {
Subreddits *subreddits.Queries
Config *config.Config
2024-04-07 23:41:00 +07:00
}
func (api *API) Register(router chi.Router) {
router.Use(chimiddleware.RequestID)
2024-04-07 12:11:25 +07:00
router.Get("/", HealthCheck)
router.Get("/health", HealthCheck)
2024-04-07 23:41:00 +07:00
router.Route("/subreddits", func(r chi.Router) {
r.Use(chimiddleware.RequestLogger(middleware.ChiLogger{}))
r.Get("/", api.ListSubreddits)
})
2024-04-07 12:11:25 +07:00
}