...

Text file src/github.com/go-chi/chi/_examples/rest/routes.json

Documentation: github.com/go-chi/chi/_examples/rest

     1{
     2  "router": {
     3    "middlewares": [
     4      {
     5        "pkg": "github.com/go-chi/chi/middleware",
     6        "func": "RequestID",
     7        "comment": "RequestID is a middleware that injects a request ID into the context of each\nrequest. A request ID is a string of the form \"host.example.com/random-0001\",\nwhere \"random\" is a base62 random string that uniquely identifies this go\nprocess, and where the last number is an atomically incremented request\ncounter.\n",
     8        "file": "github.com/go-chi/chi/middleware/request_id.go",
     9        "line": 63
    10      },
    11      {
    12        "pkg": "github.com/go-chi/chi/middleware",
    13        "func": "Logger",
    14        "comment": "Logger is a middleware that logs the start and end of each request, along\nwith some useful data about what was requested, what the response status was,\nand how long it took to return. When standard output is a TTY, Logger will\nprint in color, otherwise it will print in black and white. Logger prints a\nrequest ID if one is provided.\n\nAlternatively, look at https://github.com/pressly/lg and the `lg.RequestLogger`\nmiddleware pkg.\n",
    15        "file": "github.com/go-chi/chi/middleware/logger.go",
    16        "line": 26
    17      },
    18      {
    19        "pkg": "github.com/go-chi/chi/middleware",
    20        "func": "Recoverer",
    21        "comment": "Recoverer is a middleware that recovers from panics, logs the panic (and a\nbacktrace), and returns a HTTP 500 (Internal Server Error) status if\npossible. Recoverer prints a request ID if one is provided.\n\nAlternatively, look at https://github.com/pressly/lg middleware pkgs.\n",
    22        "file": "github.com/go-chi/chi/middleware/recoverer.go",
    23        "line": 18
    24      },
    25      {
    26        "pkg": "github.com/go-chi/chi/middleware",
    27        "func": "URLFormat",
    28        "comment": "URLFormat is a middleware that parses the url extension from a request path and stores it\non the context as a string under the key `middleware.URLFormatCtxKey`. The middleware will\ntrim the suffix from the routing path and continue routing.\n\nRouters should not include a url parameter for the suffix when using this middleware.\n\nSample usage.. for url paths: `/articles/1`, `/articles/1.json` and `/articles/1.xml`\n\n func routes() http.Handler {\n   r := chi.NewRouter()\n   r.Use(middleware.URLFormat)\n\n   r.Get(\"/articles/{id}\", ListArticles)\n\n   return r\n }\n\n func ListArticles(w http.ResponseWriter, r *http.Request) {\n\t  urlFormat, _ := r.Context().Value(middleware.URLFormatCtxKey).(string)\n\n\t  switch urlFormat {\n\t  case \"json\":\n\t  \trender.JSON(w, r, articles)\n\t  case \"xml:\"\n\t  \trender.XML(w, r, articles)\n\t  default:\n\t  \trender.JSON(w, r, articles)\n\t  }\n}\n",
    29        "file": "github.com/go-chi/chi/middleware/url_format.go",
    30        "line": 45
    31      },
    32      {
    33        "pkg": "github.com/go-chi/render",
    34        "func": "SetContentType.func1",
    35        "comment": "",
    36        "file": "github.com/go-chi/render/content_type.go",
    37        "line": 49,
    38        "anonymous": true
    39      }
    40    ],
    41    "routes": {
    42      "/": {
    43        "handlers": {
    44          "GET": {
    45            "middlewares": [],
    46            "method": "GET",
    47            "pkg": "",
    48            "func": "main.main.func1",
    49            "comment": "",
    50            "file": "github.com/go-chi/chi/_examples/rest/main.go",
    51            "line": 69,
    52            "anonymous": true
    53          }
    54        }
    55      },
    56      "/admin/*": {
    57        "router": {
    58          "middlewares": [
    59            {
    60              "pkg": "",
    61              "func": "main.AdminOnly",
    62              "comment": "AdminOnly middleware restricts access to just administrators.\n",
    63              "file": "github.com/go-chi/chi/_examples/rest/main.go",
    64              "line": 238
    65            }
    66          ],
    67          "routes": {
    68            "/": {
    69              "handlers": {
    70                "GET": {
    71                  "middlewares": [],
    72                  "method": "GET",
    73                  "pkg": "",
    74                  "func": "main.adminRouter.func1",
    75                  "comment": "",
    76                  "file": "github.com/go-chi/chi/_examples/rest/main.go",
    77                  "line": 225,
    78                  "anonymous": true
    79                }
    80              }
    81            },
    82            "/accounts": {
    83              "handlers": {
    84                "GET": {
    85                  "middlewares": [],
    86                  "method": "GET",
    87                  "pkg": "",
    88                  "func": "main.adminRouter.func2",
    89                  "comment": "",
    90                  "file": "github.com/go-chi/chi/_examples/rest/main.go",
    91                  "line": 228,
    92                  "anonymous": true
    93                }
    94              }
    95            },
    96            "/users/{userId}": {
    97              "handlers": {
    98                "GET": {
    99                  "middlewares": [],
   100                  "method": "GET",
   101                  "pkg": "",
   102                  "func": "main.adminRouter.func3",
   103                  "comment": "",
   104                  "file": "github.com/go-chi/chi/_examples/rest/main.go",
   105                  "line": 231,
   106                  "anonymous": true
   107                }
   108              }
   109            }
   110          }
   111        }
   112      },
   113      "/articles/*": {
   114        "router": {
   115          "middlewares": [],
   116          "routes": {
   117            "/": {
   118              "handlers": {
   119                "GET": {
   120                  "middlewares": [
   121                    {
   122                      "pkg": "",
   123                      "func": "main.paginate",
   124                      "comment": "paginate is a stub, but very possible to implement middleware logic\nto handle the request params for handling a paginated request.\n",
   125                      "file": "github.com/go-chi/chi/_examples/rest/main.go",
   126                      "line": 251
   127                    }
   128                  ],
   129                  "method": "GET",
   130                  "pkg": "",
   131                  "func": "main.ListArticles",
   132                  "comment": "",
   133                  "file": "github.com/go-chi/chi/_examples/rest/main.go",
   134                  "line": 117
   135                },
   136                "POST": {
   137                  "middlewares": [],
   138                  "method": "POST",
   139                  "pkg": "",
   140                  "func": "main.CreateArticle",
   141                  "comment": "CreateArticle persists the posted Article and returns it\nback to the client as an acknowledgement.\n",
   142                  "file": "github.com/go-chi/chi/_examples/rest/main.go",
   143                  "line": 158
   144                }
   145              }
   146            },
   147            "/search": {
   148              "handlers": {
   149                "GET": {
   150                  "middlewares": [],
   151                  "method": "GET",
   152                  "pkg": "",
   153                  "func": "main.SearchArticles",
   154                  "comment": "SearchArticles searches the Articles data for a matching article.\nIt's just a stub, but you get the idea.\n",
   155                  "file": "github.com/go-chi/chi/_examples/rest/main.go",
   156                  "line": 152
   157                }
   158              }
   159            },
   160            "/{articleID}/*": {
   161              "router": {
   162                "middlewares": [
   163                  {
   164                    "pkg": "",
   165                    "func": "main.ArticleCtx",
   166                    "comment": "ArticleCtx middleware is used to load an Article object from\nthe URL parameters passed through as the request. In case\nthe Article could not be found, we stop here and return a 404.\n",
   167                    "file": "github.com/go-chi/chi/_examples/rest/main.go",
   168                    "line": 127
   169                  }
   170                ],
   171                "routes": {
   172                  "/": {
   173                    "handlers": {
   174                      "DELETE": {
   175                        "middlewares": [],
   176                        "method": "DELETE",
   177                        "pkg": "",
   178                        "func": "main.DeleteArticle",
   179                        "comment": "DeleteArticle removes an existing Article from our persistent store.\n",
   180                        "file": "github.com/go-chi/chi/_examples/rest/main.go",
   181                        "line": 204
   182                      },
   183                      "GET": {
   184                        "middlewares": [],
   185                        "method": "GET",
   186                        "pkg": "",
   187                        "func": "main.GetArticle",
   188                        "comment": "GetArticle returns the specific Article. You'll notice it just\nfetches the Article right off the context, as its understood that\nif we made it this far, the Article must be on the context. In case\nits not due to a bug, then it will panic, and our Recoverer will save us.\n",
   189                        "file": "github.com/go-chi/chi/_examples/rest/main.go",
   190                        "line": 176
   191                      },
   192                      "PUT": {
   193                        "middlewares": [],
   194                        "method": "PUT",
   195                        "pkg": "",
   196                        "func": "main.UpdateArticle",
   197                        "comment": "UpdateArticle updates an existing Article in our persistent store.\n",
   198                        "file": "github.com/go-chi/chi/_examples/rest/main.go",
   199                        "line": 189
   200                      }
   201                    }
   202                  }
   203                }
   204              }
   205            },
   206            "/{articleSlug:[a-z-]+}": {
   207              "handlers": {
   208                "GET": {
   209                  "middlewares": [
   210                    {
   211                      "pkg": "",
   212                      "func": "main.ArticleCtx",
   213                      "comment": "ArticleCtx middleware is used to load an Article object from\nthe URL parameters passed through as the request. In case\nthe Article could not be found, we stop here and return a 404.\n",
   214                      "file": "github.com/go-chi/chi/_examples/rest/main.go",
   215                      "line": 127
   216                    }
   217                  ],
   218                  "method": "GET",
   219                  "pkg": "",
   220                  "func": "main.GetArticle",
   221                  "comment": "GetArticle returns the specific Article. You'll notice it just\nfetches the Article right off the context, as its understood that\nif we made it this far, the Article must be on the context. In case\nits not due to a bug, then it will panic, and our Recoverer will save us.\n",
   222                  "file": "github.com/go-chi/chi/_examples/rest/main.go",
   223                  "line": 176
   224                }
   225              }
   226            }
   227          }
   228        }
   229      },
   230      "/panic": {
   231        "handlers": {
   232          "GET": {
   233            "middlewares": [],
   234            "method": "GET",
   235            "pkg": "",
   236            "func": "main.main.func3",
   237            "comment": "",
   238            "file": "github.com/go-chi/chi/_examples/rest/main.go",
   239            "line": 77,
   240            "anonymous": true
   241          }
   242        }
   243      },
   244      "/ping": {
   245        "handlers": {
   246          "GET": {
   247            "middlewares": [],
   248            "method": "GET",
   249            "pkg": "",
   250            "func": "main.main.func2",
   251            "comment": "",
   252            "file": "github.com/go-chi/chi/_examples/rest/main.go",
   253            "line": 73,
   254            "anonymous": true
   255          }
   256        }
   257      }
   258    }
   259  }
   260}

View as plain text