Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/go-chi/chi
/ functions
Functions
435 in github.com/go-chi/chi
⨍
Functions
435
◇
Types & classes
60
↓ 2 callers
Function
longestPrefix
longestPrefix finds the length of the shared prefix of two strings
tree.go:822
↓ 2 callers
Method
maybeWriteHeader
()
middleware/wrap_writer.go:116
↓ 2 callers
Method
nextRoutePath
(rctx *Context)
mux.go:493
↓ 2 callers
Function
printPrettyStack
printPrettyStack prints a formatted stack trace to stderr. When useColor is false, ANSI colour codes are suppressed, which is useful for terminals tha
middleware/recoverer.go:61
↓ 2 callers
Function
replaceWildcards
replaceWildcards takes a route pattern and replaces all occurrences of "/*/" with "/". It iteratively runs until no wildcards remain to correctly hand
context.go:139
↓ 2 callers
Method
routes
()
tree.go:633
↓ 2 callers
Function
split
Split a string in two parts, cleaning any whitespace.
middleware/content_charset.go:37
↓ 2 callers
Function
testRequestWithAcceptedEncodings
(t *testing.T, ts *httptest.Server, method, path string, encodings ...string)
middleware/compress_test.go:206
↓ 2 callers
Method
updateRouteHandler
updateRouteHandler builds the single mux handler that is a chain of the middleware stack, as defined by calls to Use(), and the tree router (Mux) itse
mux.go:517
↓ 2 callers
Method
updateSubRoutes
Recursively update data on child routers.
mux.go:503
↓ 1 callers
Function
AllowContentEncoding
AllowContentEncoding enforces a whitelist of request Content-Encoding otherwise responds with a 415 Unsupported Media Type status.
middleware/content_encoding.go:10
↓ 1 callers
Function
AllowContentType
AllowContentType enforces a whitelist of request Content-Types otherwise responds with a 415 Unsupported Media Type status.
middleware/content_type.go:20
↓ 1 callers
Function
Compress
Compress is a middleware that compresses response body of a given content types to a data format based on Accept-Encoding request header. It uses a gi
middleware/compress.go:45
↓ 1 callers
Function
ContentCharset
ContentCharset generates a handler that writes a 415 Unsupported Media Type response if none of the charsets match. An empty charset will allow reques
middleware/content_charset.go:11
↓ 1 callers
Method
Discard
Discard causes all writes to the original ResponseWriter be discarded, instead writing only to the tee'd writer if it's set. The caller is responsible
middleware/wrap_writer.go:68
↓ 1 callers
Method
Discard
()
middleware/wrap_writer.go:138
↓ 1 callers
Function
FileServer
FileServer conveniently sets up a http.FileServer handler to serve static files from a http.FileSystem.
_examples/fileserver/main.go:48
↓ 1 callers
Method
Find
Find searches the routing tree for the pattern that matches the method/path. Note: the *Context state is updated during execution, so manage the stat
mux.go:374
↓ 1 callers
Method
Flush
()
middleware/wrap_writer.go:194
↓ 1 callers
Method
Flush
()
middleware/wrap_writer.go:239
↓ 1 callers
Method
Get
Get adds the route `pattern` that matches a GET http method to execute the `handlerFn` http.HandlerFunc.
mux.go:155
↓ 1 callers
Function
GetLogEntry
GetLogEntry returns the in-context LogEntry for a request.
middleware/logger.go:75
↓ 1 callers
Method
Group
Group creates a new inline-Mux with a copy of middleware stack. It's useful for a group of handlers along the same routing path that use an additional
mux.go:268
↓ 1 callers
Method
Handle
Handle adds the route `pattern` that matches any http method to execute the `handler` http.Handler.
mux.go:109
↓ 1 callers
Method
IsMatch
(value string)
middleware/route_headers.go:116
↓ 1 callers
Method
Match
(v string)
middleware/route_headers.go:141
↓ 1 callers
Method
MethodNotAllowedHandler
MethodNotAllowedHandler returns the default Mux 405 responder whenever a method cannot be resolved for a route.
mux.go:413
↓ 1 callers
Method
Middlewares
Middlewares returns the list of middlewares in use by the router.
chi.go:124
↓ 1 callers
Method
NewLogEntry
(r *http.Request)
middleware/logger.go:64
↓ 1 callers
Function
NewUserPayloadResponse
(user *User)
_examples/rest/main.go:295
↓ 1 callers
Method
Panic
(v interface{}, stack []byte)
middleware/logger.go:71
↓ 1 callers
Method
Post
Post adds the route `pattern` that matches a POST http method to execute the `handlerFn` http.HandlerFunc.
mux.go:179
↓ 1 callers
Function
PrintPrettyStack
(rvr interface{})
middleware/recoverer.go:54
↓ 1 callers
Function
RedirectSlashes
RedirectSlashes is a middleware that will match request paths with a trailing slash and redirect to the same path, less the trailing slash. NOTE: Red
middleware/strip.go:41
↓ 1 callers
Function
RegisterMethod
RegisterMethod adds support for custom HTTP method handlers, available via Router#Method and Router#MethodFunc
tree.go:70
↓ 1 callers
Method
Render
(w http.ResponseWriter, r *http.Request)
_examples/versions/presenter/v2/article.go:23
↓ 1 callers
Method
RouteAny
(header string, match []string, middlewareHandler func(next http.Handler) http.Handler)
middleware/route_headers.go:58
↓ 1 callers
Method
RouteDefault
(handler func(next http.Handler) http.Handler)
middleware/route_headers.go:72
↓ 1 callers
Function
RouteHeaders
RouteHeaders is a neat little header-based router that allows you to direct the flow of a request through a middleware stack based on a request header
middleware/route_headers.go:42
↓ 1 callers
Method
Sort
Sort the list of nodes by label
tree.go:834
↓ 1 callers
Function
StripPrefix
StripPrefix is a middleware that will strip the provided prefix from the request path before handing the request over to the next handler.
middleware/strip.go:73
↓ 1 callers
Function
StripSlashes
StripSlashes is a middleware that will match request paths with a trailing slash, strip it from the path and continue routing through the mux, if a ro
middleware/strip.go:14
↓ 1 callers
Function
Sunset
Sunset set Deprecation/Sunset header to response This can be used to enable Sunset in a route or a route group For more: https://www.rfc-editor.org/rf
middleware/sunset.go:11
↓ 1 callers
Method
Swap
(i, j int)
tree.go:836
↓ 1 callers
Method
Tee
Tee causes the response body to be written to the given io.Writer in addition to proxying the writes through. Only one io.Writer can be tee'd to at on
middleware/wrap_writer.go:61
↓ 1 callers
Function
Throttle
Throttle is a middleware that limits number of currently processed requests at a time across all users. Note: Throttle is not a rate-limiter per user,
middleware/throttle.go:32
↓ 1 callers
Function
Timeout
Timeout is a middleware that cancels ctx after a given timeout and return a 504 Gateway Timeout error to the client. It's required that you select th
middleware/timeout.go:32
↓ 1 callers
Function
URLParamFromCtx
URLParamFromCtx returns the url parameter from a http.Request Context.
context.go:18
↓ 1 callers
Function
WithLogEntry
WithLogEntry sets the in-context LogEntry for a request.
middleware/logger.go:81
↓ 1 callers
Method
WriteHeader
(code int)
middleware/compress.go:302
↓ 1 callers
Method
addChild
addChild appends the new `child` node to the tree using the `pattern` as the trie key. For a URL router like chi's, we split the static, param, regexp
tree.go:244
↓ 1 callers
Function
adminRouter
A completely separate router for administrator routes
_examples/rest/main.go:219
↓ 1 callers
Function
apiVersionCtx
(version string)
_examples/versions/main.go:51
↓ 1 callers
Function
articleRouter
()
_examples/versions/main.go:60
↓ 1 callers
Function
assertError
(t *testing.T, err error)
middleware/middleware_test.go:142
↓ 1 callers
Function
basicAuthFailed
(w http.ResponseWriter, realm string)
middleware/basic_auth.go:30
↓ 1 callers
Function
dbGetArticle
(id string)
_examples/rest/main.go:475
↓ 1 callers
Function
dbGetArticleBySlug
(slug string)
_examples/rest/main.go:484
↓ 1 callers
Function
dbGetUser
(id int64)
_examples/rest/main.go:513
↓ 1 callers
Function
dbNewArticle
(article *Article)
_examples/rest/main.go:469
↓ 1 callers
Function
dbRemoveArticle
(id string)
_examples/rest/main.go:503
↓ 1 callers
Function
dbUpdateArticle
(id string, article *Article)
_examples/rest/main.go:493
↓ 1 callers
Function
decodeResponseBody
(t *testing.T, resp *http.Response)
middleware/compress_test.go:229
↓ 1 callers
Method
decorateFuncCallLine
(line string, useColor bool, num int)
middleware/recoverer.go:132
↓ 1 callers
Method
decorateLine
(line string, useColor bool, num int)
middleware/recoverer.go:118
↓ 1 callers
Method
decorateSourceLine
(line string, useColor bool, num int)
middleware/recoverer.go:172
↓ 1 callers
Function
equalHandlers
equalHandlers reports whether a and b are the same handler value. Handlers are commonly funcs (e.g. http.HandlerFunc), and a direct == on those panics
tree.go:696
↓ 1 callers
Method
findRoute
Recursive edge traversal by checking all nodeTyp groups along the way. It's like searching through a multi-dimensional radix trie.
tree.go:410
↓ 1 callers
Method
getEdge
(ntyp nodeTyp, label, tail byte, prefix string)
tree.go:340
↓ 1 callers
Function
inAnyPrefix
inAnyPrefix reports whether ip falls within any of the given prefixes.
middleware/client_ip.go:250
↓ 1 callers
Method
isCompressible
()
middleware/compress.go:286
↓ 1 callers
Function
maintainDefaultRequestID
()
middleware/request_id_test.go:12
↓ 1 callers
Function
matchAcceptEncoding
(accepted []string, encoding string)
middleware/compress.go:252
↓ 1 callers
Function
methodNotAllowedHandler
methodNotAllowedHandler is a helper function to respond with a 405, method not allowed. It sets the Allow header with the list of allowed methods for
mux.go:524
↓ 1 callers
Method
parse
(debugStack []byte, rvr interface{}, useColor bool)
middleware/recoverer.go:76
↓ 1 callers
Function
patParamKeys
(pattern string)
tree.go:803
↓ 1 callers
Function
realIP
(r *http.Request)
middleware/realip.go:39
↓ 1 callers
Method
replaceChild
(label, tail byte, child *node)
tree.go:328
↓ 1 callers
Function
runChain
runChain is like run but applies multiple middlewares in order.
middleware/client_ip_test.go:722
↓ 1 callers
Method
selectEncoder
selectEncoder returns the encoder, the name of the encoder, and a closer function.
middleware/compress.go:223
↓ 1 callers
Function
service
()
_examples/graceful/main.go:45
↓ 1 callers
Method
setEndpoint
(method methodTyp, handler http.Handler, pattern string)
tree.go:353
↓ 1 callers
Method
setRetryAfterHeaderIfNeeded
setRetryAfterHeaderIfNeeded sets Retry-After HTTP header if corresponding retryAfterFn option of throttler is initialized.
middleware/throttle.go:146
↓ 1 callers
Method
tailSort
tailSort pushes nodes with '/' as the tail to the end of the list for param nodes. The list order determines the traversal order.
tree.go:841
↓ 1 callers
Function
testHandler
(t *testing.T, h http.Handler, method, path string, body io.Reader)
mux_test.go:2061
↓ 1 callers
Function
testRequestNoRedirect
(t *testing.T, ts *httptest.Server, method, path string, body io.Reader)
middleware/middleware_test.go:105
↓ 1 callers
Function
walk
(r Routes, walkFn WalkFunc, parentRoute string, parentMw ...func(http.Handler) http.Handler)
tree.go:886
↓ 1 callers
Method
walk
(fn func(eps endpoints, subroutes Routes) bool)
tree.go:716
Function
AdminOnly
AdminOnly middleware restricts access to just administrators.
_examples/rest/main.go:235
Function
ArticleCtx
ArticleCtx middleware is used to load an Article object from the URL parameters passed through as the request. In case the Article could not be found,
_examples/rest/main.go:124
Function
BasicAuth
BasicAuth implements a simple middleware handler for adding basic http auth to a route.
middleware/basic_auth.go:10
Function
BenchmarkMux
(b *testing.B)
mux_test.go:2076
Function
BenchmarkThrottle
(b *testing.B)
middleware/throttle_test.go:315
Function
BenchmarkTreeGet
(b *testing.B)
tree_test.go:489
Function
BenchmarkWalkXFF
BenchmarkWalkXFF measures the cost of walking a merged X-Forwarded-For chain end-to-end (visitor never stops). Exercises the worst case for ClientIPFr
middleware/client_ip_bench_test.go:18
Function
BenchmarkWalkXFF_RightmostStop
BenchmarkWalkXFF_RightmostStop measures the common case for both ClientIPFromXFF (no trusted prefixes => stop at the first / rightmost entry) and Clie
middleware/client_ip_bench_test.go:41
Method
Bind
(r *http.Request)
_examples/rest/main.go:327
Function
CleanPath
CleanPath middleware will clean out double slash mistakes from a user's request path. For example, if a user requests /users//1 or //users////1 will b
middleware/clean_path.go:12
Function
ClientIPFromRemoteAddr
ClientIPFromRemoteAddr stores the client IP read from the TCP RemoteAddr of the incoming request — the IP address of whoever opened the connection to
middleware/client_ip.go:187
Method
Connect
Connect adds the route `pattern` that matches a CONNECT http method to execute the `handlerFn` http.HandlerFunc.
mux.go:143
← previous
next →
101–200 of 435, ranked by callers