{"id":15860265,"url":"https://github.com/arabian9ts/builder","last_synced_at":"2025-04-15T23:09:44.093Z","repository":{"id":117469667,"uuid":"265555983","full_name":"arabian9ts/builder","owner":"arabian9ts","description":"struct builder written in golang","archived":false,"fork":false,"pushed_at":"2020-05-31T11:33:49.000Z","size":31,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-04-15T23:09:38.519Z","etag":null,"topics":["builder","builder-generator","builder-pattern","cli","golang"],"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/arabian9ts.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":"2020-05-20T12:18:47.000Z","updated_at":"2024-10-27T23:44:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"b73a0ae1-3023-4eb8-9a69-ec1b6ce361da","html_url":"https://github.com/arabian9ts/builder","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/arabian9ts%2Fbuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arabian9ts%2Fbuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arabian9ts%2Fbuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arabian9ts%2Fbuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arabian9ts","download_url":"https://codeload.github.com/arabian9ts/builder/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249167445,"owners_count":21223506,"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":["builder","builder-generator","builder-pattern","cli","golang"],"created_at":"2024-10-05T21:43:17.142Z","updated_at":"2025-04-15T23:09:44.064Z","avatar_url":"https://github.com/arabian9ts.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# builder\n\n## What is builder?\nCode generating tool for initialize entity keep while keeping encapsulation.\nIn order to lock our business logic into models, we need to use private fields, which makes it difficult for other packages to initialize models.\nSo, builder generates model builder structs and funcs.\n\n## Installation\n```sh\n$ go get -u github.com/arabian9ts/builder\n```\n\n## Example\nThis struct express user entity and is in `./entity` package.\n```go\ntype User struct {\n\tid        string `build:\"ID\" get:\"GetID\" set:\"SetID\"`\n\tname      string `build:\"\" get:\"\" set:\"\"`\n\tdigest    string\n\ttimestamp int64  `get:\"\" set:\"\"`\n}\n```\n\nTo generate user builders, specify the target package(s).\n```sh\n$ builder entity\n```\n\nThen, user builder is generated as following.\n\n**user_builder.go**\n```user_builder.go\ntype UserBuilder struct {\n\tid        string\n\tname      string\n\tdigest    string\n\ttimestamp int64\n}\n\nfunc NewUserBuilder() *UserBuilder {\n\treturn \u0026UserBuilder{}\n}\n\nfunc (userBuilder *UserBuilder) ID(id string) *UserBuilder {\n\tuserBuilder.id = id\n\treturn userBuilder\n}\n\nfunc (userBuilder *UserBuilder) Name(name string) *UserBuilder {\n\tuserBuilder.name = name\n\treturn userBuilder\n}\n\nfunc (userBuilder *UserBuilder) Digest(digest string) *UserBuilder {\n\tuserBuilder.digest = digest\n\treturn userBuilder\n}\n\nfunc (userBuilder *UserBuilder) Timestamp(timestamp int64) *UserBuilder {\n\tuserBuilder.timestamp = timestamp\n\treturn userBuilder\n}\n\nfunc (userBuilder UserBuilder) Build() *User {\n\treturn \u0026User{\n\t\tdigest:    userBuilder.digest,\n\t\tid:        userBuilder.id,\n\t\tname:      userBuilder.name,\n\t\ttimestamp: userBuilder.timestamp,\n\t}\n}\n```\n\n**user_accessor.go**\n```user_accessor.go\nfunc (user *User) GetID() string {\n\treturn user.id\n}\n\nfunc (user *User) GetName() string {\n\treturn user.name\n}\n\nfunc (user *User) GetTimestamp() int64 {\n\treturn user.timestamp\n}\n\nfunc (user *User) SetID(id string) {\n\tuser.id = id\n}\n\nfunc (user *User) SetName(name string) {\n\tuser.name = name\n}\n\nfunc (user *User) SetTimestamp(timestamp int64) {\n\tuser.timestamp = timestamp\n}\n\n``` \n\nThe Usage of these builder code is ...\n```go\nuser := NewUserBuilder().\n    ID(\"id\").\n    Name(\"name\").\n    Timestamp(time.Now().Unix()).\n    Build()\n```\n\n## ToDo\n- [x] skip struct tag for ignore generating builder func.\n- [x] getter or setter func with struct tag\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farabian9ts%2Fbuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farabian9ts%2Fbuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farabian9ts%2Fbuilder/lists"}