{"id":13670154,"url":"https://github.com/fumeboy/nni","last_synced_at":"2026-01-16T15:48:31.647Z","repository":{"id":118583206,"uuid":"352103319","full_name":"fumeboy/nni","owner":"fumeboy","description":"通过声明嵌套结构体的方式生成URL ","archived":false,"fork":false,"pushed_at":"2021-03-28T03:06:57.000Z","size":4,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-03T09:07:06.890Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fumeboy.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-03-27T15:10:00.000Z","updated_at":"2021-03-28T03:06:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"6c1f1893-fd44-44bf-aae0-b7e7d1c7f563","html_url":"https://github.com/fumeboy/nni","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumeboy%2Fnni","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumeboy%2Fnni/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumeboy%2Fnni/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumeboy%2Fnni/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fumeboy","download_url":"https://codeload.github.com/fumeboy/nni/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224067018,"owners_count":17250098,"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":[],"created_at":"2024-08-02T09:00:34.100Z","updated_at":"2026-01-16T15:48:30.604Z","avatar_url":"https://github.com/fumeboy.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# 通过嵌套结构体的方式生成URL \n\n如下方式定义结构体\n```go\n/*\ntype Route struct { // the path is \"/\"\n\t// 空结构体\n}\n*/\n\ntype RouteApple struct { // the path is \"/apple/:kind\"\n\tnni.Route `url:\"apple\"`\n\tkind string // 这里的 kind 关联 path param，可以用依赖注入的方式设置值\n}\n\ntype RouteAppleGet struct { // the path is \"/apple/:kind/get/:number\"\n\tRouteApple `url:\"get\"`\n\tnumber string\n\tnni.GET // 这个 GET 指 http request method。是空结构体\n}\n\nfunc TestExample1(t *testing.T){\n\tfmt.Println(nni.Parse(\u0026RouteAppleGet{}))\n}\n```\n\n`nni.Parse()` output:\n\n```txt\n{/apple/:kind/get/:number/ get}\n```\n\n## 使用场景？\n\n可以是这样\n\n```go\ntype RouteAppleGet struct { // the path is \"/apple/:kind/get/:number\"\n\tRouteApple `url:\"get\"`\n\tnumber string\n\tnni.GET\n}\n\nfunc (handler *RouteAppleGet) handle(c *gin.Context){\n\n}\n\nrouter.Registe(\u0026RouteAppleGet{})\n```\n\n## 目的\n\n你不用像下面这样通过注释的方式弱捆绑 URL 到 handler 上\n```go\n// @router /***/**/handle1 [POST]\nfunc Handle1(c *gin.Context) {\n```\n\n而且这样从下向上的书写 URL，也很容易写错 parent path `/***/**/`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffumeboy%2Fnni","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffumeboy%2Fnni","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffumeboy%2Fnni/lists"}