{"id":34133219,"url":"https://github.com/winpooh32/spec","last_synced_at":"2026-03-09T23:02:39.979Z","repository":{"id":295364494,"uuid":"989876576","full_name":"WinPooh32/spec","owner":"WinPooh32","description":"Golang Composite Specification pattern implementation","archived":false,"fork":false,"pushed_at":"2025-05-25T06:16:17.000Z","size":1,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-25T06:29:53.736Z","etag":null,"topics":["ddd","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/WinPooh32.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,"zenodo":null}},"created_at":"2025-05-25T02:47:56.000Z","updated_at":"2025-05-25T06:16:20.000Z","dependencies_parsed_at":"2025-05-25T06:30:49.561Z","dependency_job_id":"4c742c9e-dc0d-4888-9cc0-e1de60f61631","html_url":"https://github.com/WinPooh32/spec","commit_stats":null,"previous_names":["winpooh32/spec"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/WinPooh32/spec","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WinPooh32%2Fspec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WinPooh32%2Fspec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WinPooh32%2Fspec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WinPooh32%2Fspec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WinPooh32","download_url":"https://codeload.github.com/WinPooh32/spec/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WinPooh32%2Fspec/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30315974,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T20:05:46.299Z","status":"ssl_error","status_checked_at":"2026-03-09T19:57:04.425Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ddd","specification-pattern"],"created_at":"2025-12-15T01:05:32.338Z","updated_at":"2026-03-09T23:02:39.972Z","avatar_url":"https://github.com/WinPooh32.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spec\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/WinPooh32/spec.svg)](https://pkg.go.dev/github.com/WinPooh32/spec)\n\nSimple implementation of the [Composite Specification pattern](https://martinfowler.com/apsupp/spec.pdf) ([archive](https://web.archive.org/web/20250428234628/https://martinfowler.com/apsupp/spec.pdf)). Only conjunction operation (and) is implemented for simplicity and better performance.\n\nAlso it can provide textual description what specification rule is not satisfied by using an error interface instead of a bool predicate.\n\n## Example\n\n\u003chttps://go.dev/play/p/Katvuji0xHo\u003e\n\nDefine class:\n\n```go\ntype Man struct {\n    Age    int\n    Mortal bool\n    Diet   []string\n}\n```\n\nDefine specifications:\n\n```go\ntype ImmortalSpec struct{}\n\nfunc (ImmortalSpec) SatisfiedBy(man Man) error {\n    if !man.Mortal {\n        return nil\n    }\n\n    return fmt.Errorf(\"expected to be immortal\")\n}\n\ntype AncientSpec struct{}\n\nfunc (AncientSpec) SatisfiedBy(man Man) error {\n    const n = 500\n\n    if man.Age \u003e= n {\n        return nil\n    }\n\n    return fmt.Errorf(\"expected to be older than %d years\", n)\n}\n\ntype DietSpec struct {\n    Meals map[string]struct{}\n}\n\nfunc (diet DietSpec) SatisfiedBy(man Man) error {\n    for _, meal := range man.Diet {\n        if _, ok := diet.Meals[meal]; !ok {\n            return fmt.Errorf(\"expected diet: %v\", diet.Meals)\n        }\n    }\n\n    return nil\n}\n```\n\nTest specification is satisfied:\n\n```go\n// Define composite specification.\nvampireSpec := spec.And(\n    ImmortalSpec{},\n    AncientSpec{},\n    DietSpec{map[string]struct{}{\"blood\": {}}},\n)\n\n// Define man instance.\nman := Man{\n    Age:    200,\n    Mortal: true,\n    Diet:   []string{\"meat\", \"apple\"},\n}\n\n// Test the man is a vampire.\nfmt.Println(vampireSpec.SatisfiedBy(man))\n\n// Output:\n// expected to be immortal\n// expected to be older than 500 years\n// expected diet: map[blood:{}]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinpooh32%2Fspec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinpooh32%2Fspec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinpooh32%2Fspec/lists"}