{"id":3517488,"name":"github.com/InVisionApp/rye","ecosystem":"go","description":"Package Rye is a simple library to support http services.\nRye provides a middleware handler which can be used to chain http handlers together while providing\nsimple statsd metrics for use with a monitoring solution such as DataDog or other logging aggregators.\nRye also provides some additional middleware handlers that are entirely optional but easily consumed using Rye.\n\nIn order to use rye, you should vendor it and the statsd client within your project.\n\nBegin by importing the required libraries:\n\nCreate a statsd client (if desired) and create a rye Config in order to pass in optional dependencies:\n\nCreate a middleware handler. The purpose of the Handler is to keep Config and to provide an interface for chaining http handlers.\n\nBuild your http handlers using the Handler type from the **rye** package.\n\nHere are some example (custom) handlers:\n\nFinally, to setup your handlers in your API\n\nRye comes with built-in configurable `statsd` statistics that you could record to your favorite monitoring system. To configure that, you'll need to set up a `Statter` based on the `github.com/cactus/go-statsd-client` and set it in your instantiation of `MWHandler` through the `rye.Config`.\n\nWhen a middleware is called, it's timing is recorded and a counter is recorded associated directly with the http status code returned during the call. Additionally, an `errors` counter is also sent to the statter which allows you to count any errors that occur with a code equaling or above 500.\n\nExample: If you have a middleware handler you've created with a method named `loginHandler`, successful calls to that will be recorded to `handlers.loginHandler.2xx`. Additionally you'll receive stats such as `handlers.loginHandler.400` or `handlers.loginHandler.500`. You also will receive an increase in the `errors` count.\n\nIf you're sending your logs into a system such as DataDog, be aware that your stats from Rye can have prefixes such as `statsd.my-service.my-k8s-cluster.handlers.loginHandler.2xx` or even `statsd.my-service.my-k8s-cluster.errors`. Just keep in mind your stats could end up in the destination sink system with prefixes.\n\nWith Golang 1.7, a new feature has been added that supports a request specific context.\nThis is a great feature that Rye supports out-of-the-box. The tricky part of this is how the context\nis modified on the request. In Golang, the Context is always available on a\nRequest through `http.Request.Context()`. Great! However, if you want to add key/value pairs to the\ncontext, you will have to add the context to the request before it gets passed to the next Middleware.\nTo support this, the `rye.Response` has a property called `Context`. This property takes a properly\ncreated context (pulled from the `request.Context()` function. When you return a `rye.Response`\nwhich has `Context`, the **rye** library will craft a new Request and make sure that the next middleware\nreceives that request.\n\nHere's the details of creating a middleware with a proper `Context`. You must first pull from the\ncurrent request `Context`. In the example below, you see `ctx := r.Context()`. That pulls the current\ncontext. Then, you create a NEW context with your additional context key/value. Finally, you\nreturn `\u0026rye.Response{Context:ctx}`\n\nNow in a later middleware, you can easily retrieve the value you set!\n\nFor another simple example, look in the JWT middleware - it adds the JWT into the\ncontext for use by other middlewares. It uses the `CONTEXT_JWT` key to push the\nJWT token into the `Context`.\n\nRye comes with various pre-built middleware handlers. Pre-built middlewares  source (and docs) can be found in the package dir following the pattern `middleware_*.go`.\n\nTo use them, specify the constructor of the middleware as one of the middleware handlers when you define your routes:\n\nOR\n\nThe JWT Middleware pushes the JWT token onto the Context for use by other middlewares in the chain.\nThis is a convenience that allows any part of your middleware chain quick access to the JWT.\nExample usage might include a middleware that needs access to your user id or email address stored in the JWT.\nTo access this `Context` variable, the code is very simple:","homepage":"https://github.com/InVisionApp/rye","licenses":"MIT","normalized_licenses":["MIT"],"repository_url":"https://github.com/InVisionApp/rye","keywords_array":[],"namespace":"github.com/InVisionApp","versions_count":8,"first_release_published_at":"2016-12-08T14:51:35.000Z","latest_release_published_at":"2018-10-04T14:55:28.000Z","latest_release_number":"v1.0.8","last_synced_at":"2026-05-09T06:31:27.823Z","created_at":"2022-04-10T21:47:02.966Z","updated_at":"2026-05-09T06:31:27.824Z","registry_url":"https://pkg.go.dev/github.com/InVisionApp/rye","install_command":"go get github.com/InVisionApp/rye","documentation_url":"https://pkg.go.dev/github.com/InVisionApp/rye#section-documentation","metadata":{},"repo_metadata":{"uuid":"70187842","full_name":"InVisionApp/rye","owner":"InVisionApp","description":"A tiny http middleware for Golang with added handlers for common needs.","archived":false,"fork":false,"pushed_at":"2018-10-04T15:00:04.000Z","size":2893,"stargazers_count":99,"open_issues_count":0,"forks_count":15,"subscribers_count":204,"default_branch":"master","last_synced_at":"2023-02-27T02:42:27.219Z","etag":null,"topics":["basic-auth","chain","golang","http-handler","jwt-middleware","middleware","middleware-handlers","rye","statsd"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"logo_url":null,"metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-06T19:51:59.000Z","updated_at":"2023-01-04T02:43:30.000Z","dependencies_parsed_at":"2022-08-29T13:31:00.765Z","dependency_job_id":null,"html_url":"https://github.com/InVisionApp/rye","commit_stats":null,"repository_url":"http://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InVisionApp%2Frye","tags_url":"http://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InVisionApp%2Frye/tags","manifests_url":"http://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InVisionApp%2Frye/manifests","owner_url":"http://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InVisionApp","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":108921946,"host_url":"http://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"http://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"http://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names"}},"repo_metadata_updated_at":"2023-03-21T18:41:42.819Z","dependent_packages_count":0,"downloads":null,"downloads_period":null,"dependent_repos_count":1,"rankings":{"downloads":null,"dependent_repos_count":4.712729684882282,"dependent_packages_count":9.552533439361593,"stargazers_count":4.643398392193336,"forks_count":5.591147059029266,"docker_downloads_count":null,"average":6.1249521438666195},"purl":"pkg:golang/github.com/%21in%21vision%21app/rye","advisories":[],"docker_usage_url":"https://docker.ecosyste.ms/usage/go/github.com/InVisionApp/rye","docker_dependents_count":null,"docker_downloads_count":null,"usage_url":"https://repos.ecosyste.ms/usage/go/github.com/InVisionApp/rye","dependent_repositories_url":"https://repos.ecosyste.ms/api/v1/usage/go/github.com/InVisionApp/rye/dependencies","status":null,"funding_links":[],"critical":null,"issue_metadata":{"last_synced_at":"2023-06-04T14:26:23.905Z","issues_count":3,"pull_requests_count":33,"avg_time_to_close_issue":15456777.333333334,"avg_time_to_close_pull_request":83119.69696969698,"issues_closed_count":3,"pull_requests_closed_count":33,"pull_request_authors_count":10,"issue_authors_count":3,"avg_comments_per_issue":2.6666666666666665,"avg_comments_per_pull_request":1.2424242424242424,"merged_pull_requests_count":31,"bot_issues_count":0,"bot_pull_requests_count":0,"past_year_issues_count":0,"past_year_pull_requests_count":0,"past_year_avg_time_to_close_issue":null,"past_year_avg_time_to_close_pull_request":null,"past_year_issues_closed_count":0,"past_year_pull_requests_closed_count":0,"past_year_pull_request_authors_count":0,"past_year_issue_authors_count":0,"past_year_avg_comments_per_issue":null,"past_year_avg_comments_per_pull_request":null,"past_year_bot_issues_count":0,"past_year_bot_pull_requests_count":0,"past_year_merged_pull_requests_count":0},"versions_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2FInVisionApp%2Frye/versions","version_numbers_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2FInVisionApp%2Frye/version_numbers","latest_version_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2FInVisionApp%2Frye/latest_version","dependent_packages_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2FInVisionApp%2Frye/dependent_packages","related_packages_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2FInVisionApp%2Frye/related_packages","codemeta_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2FInVisionApp%2Frye/codemeta","maintainers":[]}