{"id":13786710,"url":"https://github.com/bobg/mid","last_synced_at":"2026-03-03T04:55:21.902Z","repository":{"id":57532772,"uuid":"279332427","full_name":"bobg/mid","owner":"bobg","description":"Middleware for HTTP services in Go","archived":false,"fork":false,"pushed_at":"2025-03-22T21:38:38.000Z","size":53,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-11T22:39:10.915Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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,"icon_url":"https://github.com/bobg.png","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-13T14:53:59.000Z","updated_at":"2025-03-22T21:38:20.000Z","dependencies_parsed_at":"2025-03-22T18:28:05.883Z","dependency_job_id":"c7458e3b-1b71-4d5b-9b37-73552d3171ce","html_url":"https://github.com/bobg/mid","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/bobg/mid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobg%2Fmid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobg%2Fmid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobg%2Fmid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobg%2Fmid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bobg","download_url":"https://codeload.github.com/bobg/mid/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobg%2Fmid/sbom","scorecard":{"id":246369,"data":{"date":"2025-08-11","repo":{"name":"github.com/bobg/mid","commit":"4cf8bc4896c234a1433da34c81044316ba00552e"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.7,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/25 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/go.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/bobg/mid/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/bobg/mid/go.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/go.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/bobg/mid/go.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/go.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/bobg/mid/go.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":3,"reason":"branch protection is not maximal on development and all release branches","details":["Info: 'allow deletion' disabled on branch 'master'","Info: 'force pushes' disabled on branch 'master'","Info: 'branch protection settings apply to administrators' is required to merge on branch 'master'","Info: 'stale review dismissal' is required to merge on branch 'master'","Warn: branch 'master' does not require approvers","Warn: codeowners review is not required on branch 'master'","Warn: 'last push approval' is disabled on branch 'master'","Warn: no status checks found to merge onto branch 'master'","Info: PRs are required in order to make changes on branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 3 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T07:41:42.111Z","repository_id":57532772,"created_at":"2025-08-17T07:41:42.112Z","updated_at":"2025-08-17T07:41:42.112Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30032235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T03:27:35.548Z","status":"ssl_error","status_checked_at":"2026-03-03T03:27:09.213Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T19:01:29.900Z","updated_at":"2026-03-03T04:55:21.872Z","avatar_url":"https://github.com/bobg.png","language":"Go","readme":"# Mid - Assorted middleware for HTTP services.\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/bobg/mid.svg)](https://pkg.go.dev/github.com/bobg/mid)\n[![Go Report Card](https://goreportcard.com/badge/github.com/bobg/mid)](https://goreportcard.com/report/github.com/bobg/mid)\n[![Tests](https://github.com/bobg/mid/actions/workflows/go.yml/badge.svg)](https://github.com/bobg/mid/actions/workflows/go.yml)\n[![Coverage Status](https://coveralls.io/repos/github/bobg/mid/badge.svg?branch=master)](https://coveralls.io/github/bobg/mid?branch=master)\n\nThis is mid,\na collection of useful middleware for HTTP services.\n\n## Err\n\nThe `Err` function turns a `func(http.ResponseWriter, *http.Request) error`\ninto an `http.Handler`,\nallowing handler functions to return errors in a more natural fashion.\nThese errors result in the handler producing an HTTP 500 status code,\nbut `CodeErr` and `Responder` allow you to control this behavior\n(see below).\nA `nil` return produces a `200`,\nor a `204` (“no content”) if no bytes were written to the response object.\n\nUsage:\n\n```go\nfunc main() {\n  http.Handle(\"/foo\", Err(fooHandler))\n  http.ListenAndServe(\":8080\", nil)\n}\n\nfunc fooHandler(w http.ResponseWriter, req *http.Request) error {\n  if x := req.FormValue(\"x\"); x != \"secret password\" {\n    return CodeErr{C: http.StatusUnauthorized}\n  }\n  fmt.Fprintf(w, \"You know the secret password\")\n  return nil\n}\n```\n\n## JSON\n\nThe `JSON` function turns a `func(context.Context, X) (Y, error)`\ninto an `http.Handler`,\nwhere `X` is the type of a parameter into which the HTTP request body is automatically JSON-unmarshaled,\nand `Y` is the type of a result that is automatically JSON-marshaled into the HTTP response.\nAny error is handled as with `Err`\n(see above).\nAll parts of the `func` signature are optional:\nthe `context.Context` parameter,\nthe `X` parameter,\nthe `Y` result,\nand the `error` result.\n\nUsage:\n\n```go\nfunc main() {\n  // Parses the request body as a JSON-encoded array of strings,\n  // then sorts, re-encodes, and returns that array.\n  http.Handle(\"/bar\", JSON(barHandler))\n\n  http.ListenAndServe(\":8080\", nil)\n}\n\nfunc barHandler(inp []string) []string {\n  sort.Strings(inp)\n  return inp\n}\n```\n\n## CodeErr and Responder\n\n`CodeErr` is an `error` type suitable for returning from `Err`- and `JSON`-wrapped handlers that can control the HTTP status code that gets returned.\nIt contains an HTTP status code field and a nested `error`.\n\n`Responder` is an interface\n(implemented by `CodeErr`)\nthat allows an error type to control how `Err`- and `JSON`-wrapped handlers respond to the pending request.\n\n## ResponseWrapper\n\n`ResponseWrapper` is an `http.ResponseWriter` that wraps a nested `http.ResponseWriter` and also records the status code and number of bytes sent in the response.\n\n## Trace\n\nThe `Trace` function wraps an `http.Handler` and decorates the `context.Context` in its `*http.Request` with any “trace ID” string found in the request header.\n\n## Log\n\nThe `Log` function wraps an `http.Handler` with a function that writes a simple log line on the way into and out of the handler.\nThe log line includes any “trace ID” found in the request’s `context.Context`.\n","funding_links":[],"categories":["Web Frameworks","Actual middlewares","Web框架"],"sub_categories":["Middlewares","中间件","Fail injection"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobg%2Fmid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbobg%2Fmid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobg%2Fmid/lists"}