init Project ✌️✌️
This commit is contained in:
commit
8a6dc19bdd
42 changed files with 249179 additions and 0 deletions
28
server/routers/recipe.go
Normal file
28
server/routers/recipe.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
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())
|
||||
})
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue