{"id":24714127,"url":"https://github.com/jimouchen/hertz-backend-base","last_synced_at":"2025-09-22T08:33:33.213Z","repository":{"id":263097388,"uuid":"854136596","full_name":"JimouChen/hertz-backend-base","owner":"JimouChen","description":"A backend basic web framework implemented by herzt","archived":false,"fork":false,"pushed_at":"2024-09-25T14:15:04.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T08:15:01.103Z","etag":null,"topics":["backend","go-web-framework","herzt"],"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/JimouChen.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":"2024-09-08T13:30:35.000Z","updated_at":"2024-09-25T14:16:38.000Z","dependencies_parsed_at":"2024-11-16T08:15:07.049Z","dependency_job_id":null,"html_url":"https://github.com/JimouChen/hertz-backend-base","commit_stats":null,"previous_names":["jimouchen/hertz-backend-base"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JimouChen/hertz-backend-base","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimouChen%2Fhertz-backend-base","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimouChen%2Fhertz-backend-base/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimouChen%2Fhertz-backend-base/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimouChen%2Fhertz-backend-base/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JimouChen","download_url":"https://codeload.github.com/JimouChen/hertz-backend-base/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimouChen%2Fhertz-backend-base/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263140501,"owners_count":23419895,"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":["backend","go-web-framework","herzt"],"created_at":"2025-01-27T08:15:36.605Z","updated_at":"2025-09-22T08:33:28.148Z","avatar_url":"https://github.com/JimouChen.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hertz-backend-base\nA backend basic web framework implemented by herzt\n\n## some call demo for common utils\n- file\n\n```go\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"herrz-backend-base/utils\"\n\t\"log\"\n)\n\nfunc main() {\n\tfu := \u0026utils.FileUtils{}\n\n\t// 写入JSON文件\n\tdata := map[string]interface{}{\n\t\t\"name\": \"Go\",\n\t\t\"type\": \"Programming Language\",\n\t\t\"lst\":  []int{21, 3, 4, 5, 1},\n\t\t\"map\": map[string]interface{}{\n\t\t\t\"a\": \"A\",\n\t\t\t\"b\": \"B\",\n\t\t},\n\t}\n\terr := fu.WriteToJSON(\"./data/example.json\", data, \"w\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Error writing to JSON: %v\", err)\n\t}\n\n\t// 读取JSON文件\n\tloadedData, err := fu.LoadJSON(\"./data/example.json\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Error loading JSON: %v\", err)\n\t}\n\tfmt.Printf(\"Loaded data: %v\\n\", loadedData)\n}\n\n```\n\n## usage demo of ctx\n\n- mock demo\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"time\"\n\t\"log\"\n\t\"github.com/cloudwego/hertz/pkg/app\"\n)\n\nfunc SearchAll(ctx context.Context, c *app.RequestContext) {\n\t// 创建带有 3 秒超时的 context\n\tctx, cancel := context.WithTimeout(ctx, 3*time.Second)\n\tdefer cancel() // 在函数结束时取消超时 context\n\n\t// 模拟长时间的操作\n\tdone := make(chan bool)\n\tgo func() {\n\t\t// 假设这里是一些需要时间的操作，比如数据库查询\n\t\ttime.Sleep(5 * time.Second) // 模拟 5 秒的操作\n\t\tdone \u003c- true\n\t}()\n\n\t// 处理超时或正常完成\n\tselect {\n\tcase \u003c-ctx.Done(): // ctx 超时或取消时会进入这里\n\t\tlog.Println(\"Request timed out\")\n\t\tc.JSON(504, map[string]string{\"error\": \"Request timed out\"})\n\t\treturn\n\tcase \u003c-done: // 操作完成\n\t\tlog.Println(\"Operation completed\")\n\t\tc.JSON(200, map[string]string{\"message\": \"Operation completed successfully\"})\n\t}\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimouchen%2Fhertz-backend-base","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimouchen%2Fhertz-backend-base","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimouchen%2Fhertz-backend-base/lists"}