{"id":24153405,"url":"https://github.com/qm012/okk","last_synced_at":"2026-05-15T20:32:40.178Z","repository":{"id":163297193,"uuid":"637612703","full_name":"qm012/okk","owner":"qm012","description":"go gin web develop tool library，paging，pageinfo object，sort，response","archived":false,"fork":false,"pushed_at":"2024-10-25T03:25:03.000Z","size":72,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-05T02:22:37.625Z","etag":null,"topics":["gin","go","paging","web"],"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/qm012.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":"2023-05-08T03:22:33.000Z","updated_at":"2024-10-25T03:25:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"b48e1139-6c11-4087-9a70-681c0a96fcd7","html_url":"https://github.com/qm012/okk","commit_stats":null,"previous_names":["qm012/ok","qm012/dun"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/qm012/okk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qm012%2Fokk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qm012%2Fokk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qm012%2Fokk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qm012%2Fokk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qm012","download_url":"https://codeload.github.com/qm012/okk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qm012%2Fokk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33078899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T20:25:35.270Z","status":"ssl_error","status_checked_at":"2026-05-15T20:25:34.732Z","response_time":103,"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":["gin","go","paging","web"],"created_at":"2025-01-12T11:21:39.593Z","updated_at":"2026-05-15T20:32:40.162Z","avatar_url":"https://github.com/qm012.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ok web develop tool library\n\n[//]: # ([![Build Status]\u0026#40;https://github.com//qm012/okk/workflows/Run%20Tests/badge.svg?branch=main\u0026#41;]\u0026#40;https://github.com/qm012/okk/actions?query=branch%3Amian\u0026#41;)\n\n[//]: # ([![codecov]\u0026#40;https://codecov.io/gh//qm012/okk/branch/main/graph/badge.svg\u0026#41;]\u0026#40;https://codecov.io/gh/qm012/okk\u0026#41;)\n[![GoDoc](https://pkg.go.dev/badge/github.com/qm012/okk?status.svg)](https://pkg.go.dev/github.com/qm012/okk?tab=doc)\n[![Sourcegraph](https://sourcegraph.com/github.com/qm012/okk/-/badge.svg)](https://sourcegraph.com/github.com/qm012/okk?badge)\n[![Release](https://img.shields.io/github/release/qm012/okk.svg?style=flat-square)](https://github.com/qm012/okk/releases)\n\ngo gin web develop tool library,includes pagination, middleware, pageSearch, response and other functions\n\n## Getting started\n\n### Getting okk\n\n```sh\n$ go get -u github.com/qm012/okk\n```\n\nWith [Go module](https://github.com/golang/go/wiki/Modules) support, simply add the following import\n\n```go\nimport \"github.com/qm012/okk\"\n```\n\n### Examples reference\n\n#### Base info\n\n```go\ntype SearchUserinfoReq struct {\n\tQuery string `json:\"query\" binding:\"required,max=1000\"`\n\tokk.PageSearch\n}\n```\n\n#### PageInfo\n\n```go\n// for gorm paging\n// Part of the code is omitted\nfunc gormPaging(req *SerchUserinfoReq) (*okk.PageInfo, err){\n    var (\n        count int64\n        userinfo Userinfo\n    )\n    err := *gorm.DB.Model(\u0026userinfo).Select(\"id\").Where(cmd, values...).Count(\u0026count).Error\n    if err != nil {\n        return nil, err\n    }\n\t\n    userinfoList := make([]*Userinfo, 0, req.PageSize)\n    err = *gorm.DB.Where(cmd, values...).Order(req.SortByMysql(nil, \"id\")).Limit(req.PageSize).Offset(req.Offset(count)).Find(\u0026userinfos).Error\n    if err !=nil {\n        return nil, err\n    }\n    \n    info := okk.NewPageInfo(count, userinfoList).SetPageSize(req.PageNum, req.PageSize)\n    // info object can be used by the frontend\n    return info, nil\n}\n\n// for mongo paging \n// Part of the code is omitted\nfunc mongoPaging(req *SerchUserinfoReq) (*okk.PageInfo, err){\n    count, err := *mongo.Collection.CountDocuments(context.Background(), bson.D{})\n\tif err != nil {\n\t\treturn nil, err\n    }\n\t\n    opt := options.Find().\n        SetLimit(int64(req.PageSize)).\n        SetSkip(int64(req.Offset(count)))\n    cursor,err:=*mongo.Collection.Find(ctx, filter, opt)\n    if err != nil {\n        return nil, err\n    }\n    userinfoList := make([]*Userinfo, 0, req.PageSize) // cursor.All(ctx, \u0026userinfos) \n    info := okk.NewPageInfo(count, userinfoList).SetPageSize(req.PageNum, req.PageSize)\n    // info object can be used by the frontend\n    return info, nil\n} \n\n```\n#### PageSearch\n\n##### P.S.：The value of `offset` depends on whether the current page exceeds the maximum number of pages. By default, the maximum number of pages is the main number. You can also call `okk.DisableCalcPageNum()` to cancel the calculation，`okk.DisableCalcPageNum()` global valid\n```go\nfunc GetUserinfoService(req *SearchUserinfoReq)  {\n    // get request object data\n\tsortFieldMap := map[string]struct{}{\n\t    \"id\":  {},\n\t    \"name\":{},\n\t\t\"sort\":{},\n    }\n    // Prevents sql injection. Properties are valid when they exist in sortFieldMap \n\t`example1：`*gorm.DB.Where(cmd, values...).Order(req.SortByMysql(sortFieldMap))\n    // req.SortField level gt customField\n\t`example2：`*gorm.DB.Where(cmd, values...).Order(req.SortByMysql(sortFieldMap, \"id\"))\n\n    totalCount := 290 // total records，data source: Select/Find mysql/mongo data\n    offset:=req.Offset(totalCount)\n    `example mysql：`*gorm.DB.Where(cmd, values...).Limit(req.PageSize).Offset(offset)\n    `example mongo：`opt := options.Find().\n                            SetLimit(int64(req.PageSize)).\n                            SetSkip(int64(offset))\n}\n\n```\n\n## License\n\nThe okk web tool is open-sourced software licensed under the [Apache license](./LICENSE).\n\n## Acknowledgments\n\nThe following project had particular influence on okk's design.\n\n- [pagehelper/Mybatis-PageHelper](https://github.com/pagehelper/Mybatis-PageHelper) Mybatis通用分页插件\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqm012%2Fokk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqm012%2Fokk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqm012%2Fokk/lists"}