{"id":27969178,"url":"https://github.com/future-architect/reguerr","last_synced_at":"2025-11-04T12:02:35.676Z","repository":{"id":42027683,"uuid":"397097992","full_name":"future-architect/reguerr","owner":"future-architect","description":"reguerr - Code generator for systematic error handling","archived":false,"fork":false,"pushed_at":"2022-04-17T12:41:14.000Z","size":168,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-05-07T21:08:50.085Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/future-architect.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":"2021-08-17T04:31:02.000Z","updated_at":"2022-07-07T14:27:18.000Z","dependencies_parsed_at":"2022-08-12T02:50:15.757Z","dependency_job_id":null,"html_url":"https://github.com/future-architect/reguerr","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/future-architect%2Freguerr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/future-architect%2Freguerr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/future-architect%2Freguerr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/future-architect%2Freguerr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/future-architect","download_url":"https://codeload.github.com/future-architect/reguerr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252954409,"owners_count":21830905,"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":"2025-05-07T21:08:54.476Z","updated_at":"2025-11-04T12:02:35.663Z","avatar_url":"https://github.com/future-architect.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo](logo/reguerr_logo.png)\n\n### reguerr\n\nreguerr - Code generator for systematic error handling\n\n## Abstract\n\nreguerr helps with systematic error handling.\n\nIn order to facilitate the handling of system failure, you can set the error code to identify the error in reguerr\nand the log level and response code associated with it.\n\n\n## Installation\n\n```sh\ngo install gitlab.com/future-architect/reguerr/cmd/reguerr@latest\n```\n\n## Options\n\n```sh\n\u003ereguerr -h\n\nUsage:\n  reguerr [command]\n\nAvailable Commands:\n  generate    generate reguerr code\n  help        Help about any command\n  validate    validate input file\n\nFlags:\n  -h, --help   help for reguerr\n```\n\ngenerate command is main function in reguerr.\n\n```sh\n\u003ereguerr generate -h\ngenerate reguerr code\n\nUsage:\n  reguerr generate [flags]\n\nFlags:\n      --defaultErrorLevel string   change default log level(Trace,Debug,Info,Warn,Error,Fatal)\n      --defaultStatusCode int      change default status code (default -1)\n  -f, --file string                input go file\n  -h, --help                       help for generate\n```\n\n## Usage\n\n```sh\n# target file\ncat \u003c\u003cEOF \u003e example.go\npackage example\n\nimport (\n\t\"gitlab.com/future-architect/reguerr\"\n)\n\nvar (\n\t// No message arguments\n\tPermissionDeniedErr = reguerr.New(\"1001\", \"permission denied\").Build()\n\n\t// One message arguments\n\tUpdateConflictErr = reguerr.New(\"1002\", \"other user updated: key=%s\").Build()\n\n\t// Message arguments with label\n\tInvalidInputParameterErr = reguerr.New(\"1003\", \"invalid input parameter: %v\").\n\t\tLabel(0,\"payload\", map[string]interface{}{}).\n\t\tBuild()\n)\nEOF\n\n# START reguerr\n./reguerr generate -f example.go\n```\n\nOutput is bellow format.\n\n```go example_gen.go\n// Code generated by reguerr; DO NOT EDIT.\npackage example\n\nimport (\n\t\"gitlab.com/future-architect/reguerr\"\n)\n\nfunc NewPermissionDeniedErr(err error) *reguerr.Error {\n\treturn PermissionDeniedErr.WithError(err)\n}\n\nfunc IsPermissionDeniedErr(err error) bool {\n\tvar cerr *reguerr.Error\n\tif as := errors.As(err, \u0026cerr); as {\n\t\tif cerr.Code() == PermissionDeniedErr.Code() {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc NewUpdateConflictErr(err error, arg1 interface{}) *reguerr.Error {\n\treturn UpdateConflictErr.WithError(err).WithArgs(arg1)\n}\n\nfunc IsUpdateConflictErr(err error) bool {\n\tvar cerr *reguerr.Error\n\tif as := errors.As(err, \u0026cerr); as {\n\t\tif cerr.Code() == UpdateConflictErr.Code() {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc NewInvalidInputParameterErr(err error, payload map[string]interface{}) *reguerr.Error {\n\treturn InvalidInputParameterErr.WithError(err).WithArgs(payload)\n}\n\nfunc IsInvalidInputParameterErr(err error) bool {\n\tvar cerr *reguerr.Error\n\tif as := errors.As(err, \u0026cerr); as {\n\t\tif cerr.Code() == InvalidInputParameterErr.Code() {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n```\n\nThen reguerr also generated markdown table.\n\n| CODE |           NAME           | LOGLEVEL | STATUSCODE |           FORMAT            |\n|------|--------------------------|----------|------------|-----------------------------|\n| 1001 | PermissionDeniedErr      | Error    |        500 | permission denied           |\n| 1002 | UpdateConflictErr        | Error    |        500 | other user updated: key=%s  |\n| 1003 | InvalidInputParameterErr | Error    |        500 | invalid input parameter: %v |\n\n\nIf you want to see more examples, you can get [example](./example).\n\n\n## Use Case reguerr \n\nThe output location of the error log and the switching process of the response status code are aggregated.\n\n```go\npackage example\n\nimport (\n\t\"fmt\"\n\t\"github.com/rs/zerolog\"\n\t\"github.com/rs/zerolog/log\"\n\t\"gitlab.com/future-architect/reguerr\"\n\t\"net/http\"\n)\n\nfunc UserHandleFunc(w http.ResponseWriter, r *http.Request) {\n\tif err := somethingUserOperation(\"id1\"); err != nil {\n\t\terrorLog(err)\n\t\tw.WriteHeader(httpStatus(err))\n\t\treturn\n\t}\n\tw.WriteHeader(http.StatusOK)\n}\n\nfunc errorLog(err error) {\n\trerr, ok := reguerr.ErrorOf(err)\n\tif ok {\n\t\tlevel, err := zerolog.ParseLevel(rerr.Level().String())\n\t\tif err != nil {\n\t\t\tlog.Error().Str(\"code\", rerr.Code()).Msgf(rerr.Error())\n\t\t} else {\n\t\t\tlog.WithLevel(level).Str(\"code\", rerr.Code()).Msgf(rerr.Error())\n\t\t}\n\t\treturn\n\t}\n\tlog.Printf(\"unexpected error: %v\\n\", err)\n}\n\nfunc httpStatus(err error) int {\n\tcode, ok := reguerr.StatusOf(err)\n\tif ok {\n\t\treturn code\n\t} else {\n\t\treturn http.StatusInternalServerError\n\t}\n}\n\nfunc somethingUserOperation(key string) error {\n\t// some operation for user\n\treturn NewNotFoundOperationIDErr(fmt.Errorf(\"key=%v\", key))\n}\n```\n\n## License\n\nApache License Version 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuture-architect%2Freguerr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuture-architect%2Freguerr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuture-architect%2Freguerr/lists"}