{"id":21619089,"url":"https://github.com/bannzai/constructor","last_synced_at":"2025-04-11T08:42:44.492Z","repository":{"id":94327796,"uuid":"185443417","full_name":"bannzai/constructor","owner":"bannzai","description":"constructor is generated Constructor for struct.","archived":false,"fork":false,"pushed_at":"2022-12-21T12:01:43.000Z","size":174,"stargazers_count":18,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T05:00:01.104Z","etag":null,"topics":[],"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/bannzai.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":"2019-05-07T16:52:40.000Z","updated_at":"2023-02-27T06:45:29.000Z","dependencies_parsed_at":"2023-03-18T06:30:45.318Z","dependency_job_id":null,"html_url":"https://github.com/bannzai/constructor","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2Fconstructor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2Fconstructor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2Fconstructor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2Fconstructor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bannzai","download_url":"https://codeload.github.com/bannzai/constructor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248362493,"owners_count":21091141,"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-11-24T23:07:51.979Z","updated_at":"2025-04-11T08:42:44.469Z","avatar_url":"https://github.com/bannzai.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# constructor\n`constructor` is generated [Constructor](https://golang.org/doc/effective_go.html#composite_literals) for struct.\n\nExample result.\n```go\ntype Foo struct {\n  Bar string\n}\n\nfunc NewFoo(bar string) Foo {\n  return Foo{\n    Bar: bar,\n  }\n}\n```\n\n## Install\nGetting `constructor` via `go get`.\n\n```shell\n$ go get -u github.com/bannzai/constructor\n```\n\n## Usage\nFirst, You can prepare configuration files when exec `constructor setup`. After created `constructor.tpl`.\n`constructor` necessary these configuration files.\n\n```shell\n$ constructor setup\n```\n\nNext, Execute `constructor generate`, after you edited configuration files.   \nAnd you confirm diff between before and after executing it. You found  about constructor functions `.go` file.\n\n```shell\n$ constructor generate --source=structure/code.go --destination=structure/code.constructor.go --package=structure\n```\n\n\u003cdetails\u003e\n\n\u003csummary\u003e $ cat structure/code.constructor.go \u003c/summary\u003e\n\n```go\n// DO NOT EDIT THIS FILE.\n// File generated by constructor.\n// https://github.com/bannzai/constructor\npackage structure\n\n// NewCodeStructure insitanciate Code\nfunc NewCodeStructure(\n\tfilePath Path,\n\tstructs []Struct,\n) Code {\n\treturn Code{\n\t\tFilePath: filePath,\n\t\tStructs:  structs,\n\t}\n}\n\n// NewFieldStructure insitanciate Field\nfunc NewFieldStructure(\n\tname string,\n\t_type string,\n) Field {\n\treturn Field{\n\t\tName: name,\n\t\tType: _type,\n\t}\n}\n\n// NewStructStructure insitanciate Struct\nfunc NewStructStructure(\n\tfields []Field,\n\tname string,\n) Struct {\n\treturn Struct{\n\t\tFields: fields,\n\t\tName:   name,\n\t}\n}\n```\n\n\u003c/details\u003e\n\n## Help\n\n#### constructor --help\n```shell\n$ constructor --help                     \n\nThis application is a tool to generate constructor functions for each struct quickly.\nWhen you execute \"constructor generate [flags]\",\nIt is generating constructor functions under the package.\nYou get \"./constructor.tpl\" via to execute \"constructor setup\".\nThis is default template for [constructor].\nYou can edit this template, If you customize generated files and pass it.\n\nUsage:\n  construtor [flags]\n  construtor [command]\n\nAvailable Commands:\n  generate    generate constructor functions\n  help        Help about any command\n  setup       setup will create ./constructor.yaml\n\nFlags:\n  -h, --help   help for construtor\n\nUse \"construtor [command] --help\" for more information about a command.\n```\n\n#### constructor generate --help\n```shell\n$ constructor generate --help            \nconstructor can be add constructor functions for each go struct.\n\nUsage:\n  construtor generate [flags]\n\nFlags:\n      --destination string    Destination go file path\n  -h, --help                  help for generate\n      --ignoreFields string   Not contains generated fields. It is list with commas. (e.g id,name,age\n      --package string        Package name for generated constructor.\n      --source string         Source go file path\n      --template string       Constructor functions format template file path. Default is ./constructor.tpl (default \"constructor.tpl\")\n      --type string           Specify struct about generated constructor function.\n\n```\n\n## go:generate\n**constructor** recommended to use `go:generate`. \nFor example.\n\n```\n//go:generate constructor generate --source=$GOFILE --destination=$GOPATH/src/github.com/bannzai/constructor/generator/constructor.constructor.go --package=$GOPACKAGE --template=$GOPATH/src/github.com/bannzai/constructor/constructor.tpl --type=Constructor --ignoreFields=TemplateReader,SourceCodeReader\n```\n\n## Customize template\nIt is possible to use customize template.  \nTwo ways for preparing template files.  \n\n1. Edit `constructor.tpl`\n2. Create new `[YOUR_CUSTOMIZE_TEMPLATE].tpl`\n\nAnd, It can be passed to `constructor generate [REQUIRED_FLAGS] --template=[YOUR_CUSTOMIZE_TEMPLATE].tpl`.\n\n## LICENSE\n**constructor** is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbannzai%2Fconstructor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbannzai%2Fconstructor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbannzai%2Fconstructor/lists"}