{"id":26284189,"url":"https://github.com/gabrielmellooliveira/go-spec","last_synced_at":"2025-03-14T18:30:16.494Z","repository":{"id":197669917,"uuid":"699078564","full_name":"gabrielmellooliveira/go-spec","owner":"gabrielmellooliveira","description":"Lib to golang Specification Pattern","archived":false,"fork":false,"pushed_at":"2023-10-01T23:25:14.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-10-03T07:02:32.924Z","etag":null,"topics":["go","golang","specification-pattern"],"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/gabrielmellooliveira.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}},"created_at":"2023-10-01T21:08:18.000Z","updated_at":"2023-10-01T23:23:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"b2336bc3-babf-468f-a56e-529abd666117","html_url":"https://github.com/gabrielmellooliveira/go-spec","commit_stats":null,"previous_names":["gabrielmellooliveira/go-spec"],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielmellooliveira%2Fgo-spec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielmellooliveira%2Fgo-spec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielmellooliveira%2Fgo-spec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielmellooliveira%2Fgo-spec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gabrielmellooliveira","download_url":"https://codeload.github.com/gabrielmellooliveira/go-spec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243624978,"owners_count":20321205,"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":["go","golang","specification-pattern"],"created_at":"2025-03-14T18:30:15.987Z","updated_at":"2025-03-14T18:30:16.480Z","avatar_url":"https://github.com/gabrielmellooliveira.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-spec\n\n[![GoDoc Widget]][GoDoc]\n\n`go-spec` is a lib to implement Specification Pattern.\n\nSpecification is to separate the statement of how to match a candidate, from the candidate object that it is matched against. As well as its usefulness in selection, it is also valuable for validation and for building to order.\n\n## Install\n\n`go get -u github.com/gabrielmellooliveira/go-spec`\n\n## Examples\n\n### Create a specification\n\n```go\npackage main\n\nimport \"github.com/gabrielmellooliveira/go-spec\"\n\ntype User struct {\n\tminAge int\n\tmaxAge int\n}\n\ntype UserAgeSpecification struct {\n\tSpecification spec.Specification[User]\n}\n\nfunc NewUserAgeSpecification() spec.Specification[User] {\n\tspecification := \u0026UserAgeSpecification{}\n\tspecification.Specification = spec.NewSpecification[User](specification.IsSatisfiedBy)\n\n\treturn specification.Specification\n}\n\nfunc (spec *UserAgeSpecification) IsSatisfiedBy(entity User) bool {\n\treturn entity.minAge == entity.maxAge\n}\n```\n\n### Use a specification\n\n```go\npackage main\n\nimport \"github.com/gabrielmellooliveira/go-spec\"\n\nfunc main() {\n    userAgeSpecification := NewUserAgeSpecification()\n\n    user := User{minAge: 18, maxAge: 18}\n\n    if userAgeSpecification.IsSatisfiedBy(user) {\n        ...\n    } else {\n        ...\n    }\n}\n```\n\n### Combine specifications\n\n```go\npackage main\n\nimport \"github.com/gabrielmellooliveira/go-spec\"\n\nfunc main() {\n    userAgeSpecification := NewUserAgeSpecification()\n    userRoleSpecification := NewUserRoleSpecification()\n\n    user := User{minAge: 18, maxAge: 18}\n\n    if userAgeSpecification.And(userRoleSpecification).IsSatisfiedBy(user) {\n        ...\n    } else {\n        ...\n    }\n}\n```\n\n## License\n\nCopyright (c) 2015-present [Gabriel Mello de Oliveira](https://github.com/gabrielmellooliveira)\n\nLicensed under [MIT License](./LICENSE)\n\n[GoDoc]: https://pkg.go.dev/github.com/gabrielmellooliveira/go-spec\n[GoDoc Widget]: https://godoc.org/github.com/gabrielmellooliveira/go-spec?status.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielmellooliveira%2Fgo-spec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabrielmellooliveira%2Fgo-spec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielmellooliveira%2Fgo-spec/lists"}