{"id":19755235,"url":"https://github.com/lawrsp/pigo","last_synced_at":"2025-10-16T21:17:51.446Z","repository":{"id":52954037,"uuid":"260243496","full_name":"lawrsp/pigo","owner":"lawrsp","description":"some go generate tools","archived":false,"fork":false,"pushed_at":"2022-08-21T07:58:02.000Z","size":160,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-10T22:24:38.551Z","etag":null,"topics":["builder","generate","go","parser"],"latest_commit_sha":null,"homepage":null,"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/lawrsp.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}},"created_at":"2020-04-30T15:05:54.000Z","updated_at":"2022-07-26T14:34:41.000Z","dependencies_parsed_at":"2022-08-28T09:03:09.913Z","dependency_job_id":null,"html_url":"https://github.com/lawrsp/pigo","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lawrsp%2Fpigo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lawrsp%2Fpigo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lawrsp%2Fpigo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lawrsp%2Fpigo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lawrsp","download_url":"https://codeload.github.com/lawrsp/pigo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241086291,"owners_count":19907276,"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","generate","go","parser"],"created_at":"2024-11-12T03:09:41.886Z","updated_at":"2025-10-16T21:17:46.425Z","avatar_url":"https://github.com/lawrsp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pigo\nsome go generate tools\n[![Go Reference](https://pkg.go.dev/badge/github.com/lawrsp/pigo.svg)](https://pkg.go.dev/github.com/lawrsp/pigo)\n\n# what is\n\nThere's always some repetitive, simple code you have to write, that is very annoy.\n\ne.g. when you must assign structs, and you donn't want use reflect.\n\nWhen the go generator tool comes up, I write pigo, let the generator write some simple code even a pig can write.\n\nThat is why it is called `pigo`: **pig-go**\n\n# for now\nThere are 8 generators:\n\n1. checker: use struct tags to generate struct validate function, e.g noempty, compare, valid function, set default..\n2. convert: convert one struct to another by field name or specified tags\n3. evalid: enum validate, check if a value is one of the consts\n4. setter: set one struct to another, support value diff, old/new collects\n5. setdb: set the DB object which implement chainable Where clause (e.g. gorm)\n6. jsonfield: conver a map[FieldName] map[jsonname] according the struct's json tag\n7. genrpc: write some gRpc glue code to connect service layer and api layer\n8. pfilter: a version of gRpc donnot support optional value, it must use a fieldmask to work with nil \n\n# instal\n\ngo get github.com/lawrsp/pigo\n\n# run\n\npigo help \n\npigo help xxxx\n\n# example \n\n```golang\n\n//go:generate pigo setter --type A --target B --tagname setter --name Set --withmap --checkdiff --withold --output gen_setters.go $GOFILE\n\ntype A struct {\n   Foo int `setter:\"Bar\"`\n   SameName string\n}\n\ntype B struct {\n   Bar int \n   SameName string\n}\n\n```\n\nrun `go generate` , it will create a file gen_setters.go (--output) and generate codes:\n\n```golang\nfunc (t *A) Update(target *B) (map[string]interface{}, map[string]interface{}) {\n  if target == nil {\n    return nil, nil\n  }\n  old := map[string]interface{}{}\n  updated := map[string]interface{}{}\n  if t.Foo != target.Bar {\n    old[\"Bar\"] = target.Bar\n    target.Bar = t.Foo\n    updated[\"Bar\"] = target.Bar\n  }\n  if t.SameName != target.SameName {\n    old[\"SameName\"] = target.SameName\n    target.SameName = t.SameName\n    updated[\"SameName\"] = target.SameName\n  }\n\n  return updated, old\n}\n\t\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flawrsp%2Fpigo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flawrsp%2Fpigo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flawrsp%2Fpigo/lists"}