{"id":18310113,"url":"https://github.com/kazhuravlev/structspec","last_synced_at":"2025-04-05T17:33:18.955Z","repository":{"id":64497499,"uuid":"575480234","full_name":"kazhuravlev/structspec","owner":"kazhuravlev","description":"Generate results of struct reflection","archived":false,"fork":false,"pushed_at":"2024-08-14T16:46:10.000Z","size":32,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T16:16:19.146Z","etag":null,"topics":["codegen","go","golang","struct","tool"],"latest_commit_sha":null,"homepage":"","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/kazhuravlev.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":"2022-12-07T15:55:10.000Z","updated_at":"2024-08-19T06:00:22.000Z","dependencies_parsed_at":"2024-06-20T16:21:21.733Z","dependency_job_id":"294b8885-e739-490c-94d9-8e1c16dbfd0d","html_url":"https://github.com/kazhuravlev/structspec","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazhuravlev%2Fstructspec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazhuravlev%2Fstructspec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazhuravlev%2Fstructspec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazhuravlev%2Fstructspec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kazhuravlev","download_url":"https://codeload.github.com/kazhuravlev/structspec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247375842,"owners_count":20929118,"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":["codegen","go","golang","struct","tool"],"created_at":"2024-11-05T16:13:16.427Z","updated_at":"2025-04-05T17:33:13.935Z","avatar_url":"https://github.com/kazhuravlev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# structspec\n\nGenerate static results of struct reflection.\n\nThis tool generates special structs that contain all fields from the source\nstruct.\n\nIt allows mentioning some fields of source structs without the need to remember\nthe field names. This especially helps when you write queries to the database,\nvalidating JSON/XML/etc fields.\n\n## Installation\n\n```shell\ngo install github.com/kazhuravlev/structspec/cmd/structspec@latest\n```\n\n## Usage\n\n```shell\n$ structspec gen --help\nNAME:\n   structspec gen - Generate and write result\n\nUSAGE:\n   structspec gen [command options] [arguments...]\n\nOPTIONS:\n   --src value                          Source directory\n   --structs value [ --structs value ]  Which structs should be included. Default: all founded\n   --ignore value [ --ignore value ]    Which structs should be ignored. Default: no one\n   --tag value [ --tag value ]          Which tags should be used for generation. Default: all founded\n   --out-file value                     Output filename\n   --out-pkg value                      Output package name\n   --help, -h                           show help (default: false)\n\n$ structspec gen \\\n  --src ./path/to/package/with/target/structs \\\n  --out-pkg mypackage\n```\n\n## Example\n\nSource struct:\n\n```go\npackage structs\n\ntype User struct {\n\tID       string `json:\"id\" sql:\"user_id\"`\n\tUsername string `json:\"username\" sql:\"username\"`\n}\n```\n\nGenerated code:\n\n```go\npackage structs\n\nfunc (User) Spec() UserSpec {\n\treturn UserSpecData\n}\n\ntype UserSpec struct {\n\tJson UserSpecFields\n\tSql  UserSpecFields\n}\n\ntype UserSpecFields struct {\n\tID       FieldName\n\tUsername FieldName\n}\n\nvar UserSpecData = UserSpec{\n\tJson: UserSpecFields{\n\t\tID:       \"id\",\n\t\tUsername: \"username\",\n\t},\n\tSql: UserSpecFields{\n\t\tID:       \"user_id\",\n\t\tUsername: \"username\",\n\t},\n}\n\n// and helper functions ....\n\n```\n\nUsage in sql query builder:\n\n```go\npackage storage\n\nimport \"fmt\"\n\nfunc ExampleGetUserByID(id string) {\n\tqueryTpl := `select %s, %s from users where %s = ?`\n\tquery := fmt.Sprintf(\n\t\tqueryTpl,\n\t\tstructs.UserSpecData.Sql.ID,\n\t\tstructs.UserSpecData.Sql.Username,\n\t\tstructs.UserSpecData.Sql.ID,\n\t)\n\tfmt.Println(query)\n\t// select id, username from users where id = ?\n}\n\n```\n\nThis tool guarantees you never forget to update your queries after updating\nsource structs. All you need is to run `go generate` and the go compiler will\nhighlight what you forgot to update.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazhuravlev%2Fstructspec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkazhuravlev%2Fstructspec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazhuravlev%2Fstructspec/lists"}