{"id":20554899,"url":"https://github.com/codelineage/brotli","last_synced_at":"2025-10-06T22:27:48.236Z","repository":{"id":57561540,"uuid":"328721461","full_name":"CodeLineage/brotli","owner":"CodeLineage","description":"gin middleware","archived":false,"fork":false,"pushed_at":"2021-01-27T03:09:58.000Z","size":22,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T01:53:30.729Z","etag":null,"topics":["brotli","compress","gin","middleware"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodeLineage.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}},"created_at":"2021-01-11T16:16:46.000Z","updated_at":"2024-05-31T07:46:48.000Z","dependencies_parsed_at":"2022-09-10T06:14:04.281Z","dependency_job_id":null,"html_url":"https://github.com/CodeLineage/brotli","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeLineage%2Fbrotli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeLineage%2Fbrotli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeLineage%2Fbrotli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeLineage%2Fbrotli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeLineage","download_url":"https://codeload.github.com/CodeLineage/brotli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248883235,"owners_count":21177184,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["brotli","compress","gin","middleware"],"created_at":"2024-11-16T03:14:18.790Z","updated_at":"2025-10-06T22:27:43.187Z","avatar_url":"https://github.com/CodeLineage.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Brotli Middleware for Gin\n\n## 文档\n\n[GoDoc](https://pkg.go.dev/github.com/CodeLineage/brotli)\n\n## 功能\n\n针对http输出数据进行压缩\n\n## 使用案例\n\n### 默认\n\n```golang\nhandler.Use(brotli.DefaultHandler().Gin)\n```\n\n### 自定义\n\n```golang\n handler.Use(brotli.NewHandler(brotli.Config{\n  CompressionLevel: brotli.DefaultCompression,\n  MinContentLength: brotli.DefalutContentLen,\n  RequestFilter: []brotli.RequestFilter{\n   brotli.NewCommonRequestFilter(),\n   brotli.NewRequestApiFilter([]string{\n    \"/blog/cache/http\",\n    \"/blog/detail/index\",\n   }),\n  },\n  ResponseHeaderFilter: []brotli.ResponseHeaderFilter{\n   brotli.DefaultContentTypeFilter(),\n  },\n }).Gin)\n```\n\n## 测试\n\n### 压测速率\n\n```brotli\nbash-4.3# go test -v  -run=\"GinWithLevelsHandler\"\n=== RUN   TestGinWithLevelsHandler\n=== RUN   TestGinWithLevelsHandler/level_0\n=== RUN   TestGinWithLevelsHandler/level_1\n=== RUN   TestGinWithLevelsHandler/level_2\n=== RUN   TestGinWithLevelsHandler/level_3\n=== RUN   TestGinWithLevelsHandler/level_4\n=== RUN   TestGinWithLevelsHandler/level_5\n=== RUN   TestGinWithLevelsHandler/level_6\n=== RUN   TestGinWithLevelsHandler/level_7\n=== RUN   TestGinWithLevelsHandler/level_8\n=== RUN   TestGinWithLevelsHandler/level_9\n=== RUN   TestGinWithLevelsHandler/level_10\n=== RUN   TestGinWithLevelsHandler/level_11\n--- PASS: TestGinWithLevelsHandler (0.06s)\n    --- PASS: TestGinWithLevelsHandler/level_0 (0.00s)\n        handler_test.go:215: level_0: compressed 4267 =\u003e 1456 ratio=\u003e0.66\n    --- PASS: TestGinWithLevelsHandler/level_1 (0.00s)\n        handler_test.go:215: level_1: compressed 4267 =\u003e 1419 ratio=\u003e0.67\n    --- PASS: TestGinWithLevelsHandler/level_2 (0.00s)\n        handler_test.go:215: level_2: compressed 4267 =\u003e 1410 ratio=\u003e0.67\n    --- PASS: TestGinWithLevelsHandler/level_3 (0.00s)\n        handler_test.go:215: level_3: compressed 4267 =\u003e 1340 ratio=\u003e0.69\n    --- PASS: TestGinWithLevelsHandler/level_4 (0.00s)\n        handler_test.go:215: level_4: compressed 4267 =\u003e 1257 ratio=\u003e0.71\n    --- PASS: TestGinWithLevelsHandler/level_5 (0.00s)\n        handler_test.go:215: level_5: compressed 4267 =\u003e 1187 ratio=\u003e0.72\n    --- PASS: TestGinWithLevelsHandler/level_6 (0.01s)\n        handler_test.go:215: level_6: compressed 4267 =\u003e 1187 ratio=\u003e0.72\n    --- PASS: TestGinWithLevelsHandler/level_7 (0.00s)\n        handler_test.go:215: level_7: compressed 4267 =\u003e 1186 ratio=\u003e0.72\n    --- PASS: TestGinWithLevelsHandler/level_8 (0.01s)\n        handler_test.go:215: level_8: compressed 4267 =\u003e 1186 ratio=\u003e0.72\n    --- PASS: TestGinWithLevelsHandler/level_9 (0.01s)\n        handler_test.go:215: level_9: compressed 4267 =\u003e 1185 ratio=\u003e0.72\n    --- PASS: TestGinWithLevelsHandler/level_10 (0.01s)\n        handler_test.go:215: level_10: compressed 4268 =\u003e 1049 ratio=\u003e0.75\n    --- PASS: TestGinWithLevelsHandler/level_11 (0.02s)\n        handler_test.go:215: level_11: compressed 4268 =\u003e 1042 ratio=\u003e0.76\nPASS\nok      github.com/CodeLineage/brotli   0.076s\nbash-4.3#\n```\n\n### 性能测试\n\n```brotli\nbash-4.3# go test -benchmem -bench .\ngoos: linux\ngoarch: amd64\npkg: github.com/CodeLineage/brotli\nBenchmarkGin_SmallPayload-2                              2917842               435 ns/op              96 B/op          3 allocs/op\nBenchmarkGinWithDefaultHandler_SmallPayload-2            1271218               997 ns/op             128 B/op          4 allocs/op\nBenchmarkGin_BigPayload-2                                2912677               424 ns/op              96 B/op          3 allocs/op\nBenchmarkGinWithDefaultHandler_BigPayload-2                 3063            405511 ns/op             882 B/op          6 allocs/op\nPASS\nok      github.com/CodeLineage/brotli   7.122s\n```\n\n## 依赖\n\ngithub.com/andybalholm/brotli v1.0.1\n\n## 参考\n\n[https://github.com/nanmu42/gzip](https://github.com/nanmu42/gzip)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodelineage%2Fbrotli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodelineage%2Fbrotli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodelineage%2Fbrotli/lists"}