我目前為我的 REST API 設(shè)置了路由:使用 mux本地主機(jī):8080/user/{id} 本地主機(jī):8080/space/{id}server.Router.HandleFunc("/users", middlewares.SetMiddlewareJSON(server.GetUsers)).Methods("GET")server.Router.HandleFunc("/posts", middlewares.SetMiddlewareJSON(server.GetPosts)).Methods("GET")設(shè)置中間件函數(shù)func SetMiddlewareJSON(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") next(w, r) }}我將如何將它們組合成本地主機(jī):8080/user/1/post/{id}該項(xiàng)目的存儲(chǔ)庫(kù)在這里: https ://github.com/Robbie-Thomas/fullstack
多個(gè)參數(shù) REST API 調(diào)用
呼喚遠(yuǎn)方
2022-05-10 16:25:35