MCPcopy
hub / github.com/go-chi/chi / adminRouter

Function adminRouter

_examples/rest/main.go:219–232  ·  view source on GitHub ↗

A completely separate router for administrator routes

()

Source from the content-addressed store, hash-verified

217
218// A completely separate router for administrator routes
219func adminRouter() chi.Router {
220 r := chi.NewRouter()
221 r.Use(AdminOnly)
222 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
223 w.Write([]byte("admin: index"))
224 })
225 r.Get("/accounts", func(w http.ResponseWriter, r *http.Request) {
226 w.Write([]byte("admin: list accounts.."))
227 })
228 r.Get("/users/{userId}", func(w http.ResponseWriter, r *http.Request) {
229 w.Write([]byte(fmt.Sprintf("admin: view user id %v", chi.URLParam(r, "userId"))))
230 })
231 return r
232}
233
234// AdminOnly middleware restricts access to just administrators.
235func AdminOnly(next http.Handler) http.Handler {

Callers 1

mainFunction · 0.85

Calls 4

UseMethod · 0.95
GetMethod · 0.95
URLParamMethod · 0.80
WriteMethod · 0.65

Tested by

no test coverage detected