28 lines
515 B
Go
28 lines
515 B
Go
package routers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"recipe-manager/data"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
type RecipeRouter struct {
|
|
data *data.Data
|
|
}
|
|
|
|
func NewRecipeRouter(data *data.Data) *RecipeRouter {
|
|
return &RecipeRouter{
|
|
data: data,
|
|
}
|
|
}
|
|
|
|
func (rr *RecipeRouter) Route(r *chi.Mux) {
|
|
r.Route("/recipes", func(r chi.Router) {
|
|
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Add("Content-Type", "application/json")
|
|
json.NewEncoder(w).Encode(rr.data.GetRecipe())
|
|
})
|
|
})
|
|
}
|