{"id":19451572,"url":"https://github.com/pxyup/verifiers","last_synced_at":"2025-04-25T04:30:26.857Z","repository":{"id":78602354,"uuid":"471541715","full_name":"PxyUp/verifiers","owner":"PxyUp","description":"Small library for verify async function response","archived":false,"fork":false,"pushed_at":"2022-03-26T22:21:17.000Z","size":19,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T15:52:28.714Z","etag":null,"topics":["generic","golang","testing"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/PxyUp/verifiers","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/PxyUp.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":"2022-03-18T23:13:04.000Z","updated_at":"2022-05-02T20:43:21.000Z","dependencies_parsed_at":"2023-04-26T21:48:35.690Z","dependency_job_id":null,"html_url":"https://github.com/PxyUp/verifiers","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PxyUp%2Fverifiers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PxyUp%2Fverifiers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PxyUp%2Fverifiers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PxyUp%2Fverifiers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PxyUp","download_url":"https://codeload.github.com/PxyUp/verifiers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250754516,"owners_count":21481827,"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":["generic","golang","testing"],"created_at":"2024-11-10T16:42:17.337Z","updated_at":"2025-04-25T04:30:26.608Z","avatar_url":"https://github.com/PxyUp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Verifiers\n\n[![codecov](https://codecov.io/gh/PxyUp/verifiers/branch/master/graph/badge.svg)](https://codecov.io/gh/PxyUp/verifiers)\n\nSmall GO library for verify async function response.\n\nProvide some basic functionality for conditional check\n\n# Usage\n\n```bash\ngo get github.com/PxyUp/verifiers\n```\n\n**Important**: all function will be finished if condition are matched (it is mean all child routine will be stopped)\n\n# Methods\n\n- [verifier.All(...Verifier)](#verifierall) - is equal verifier.Exact(len(fns), fns ...Verifier)\n- [verifier.OneOf(...Verifier)](#verifieroneof) - is equal verifier.AtLeast(1, ...Verifier)\n- [verifier.AtLeast(int, ...Verifier)](#verifieratleast) \n- [verifier.Exact(int, ...Verifier)](#verifierexact) \n- [verifier.OnlyOne(...Verifier)](#verifieronlyone) - is equal verifier.Exact(1, ...Verifier)\n- [verifier.NoOne(...Verifier)](#verifiernoone) - is equal verifier.Exact(0, ...Verifier)\n\n**For Go v1.18+(with generics)**\n\n- [verifiers.FromArray[T any](arr []T, cmp func(context.Context, T) error)](#verifiersfromarray) - generate Verifier from static array\n\n# List of errors\n```go\n// ErrCountMoreThanLength is configuration error.\n// Will return if we expect more function than we provide for verifier.AtLeast or verifier.Exact\nverifiers.ErrCountMoreThanLength = errors.New(\"cant wait more than exists\")\n// ErrMaxAmountOfError wii be returned some function which we not expect return error\nverifiers.ErrMaxAmountOfError = errors.New(\"verifier reach max amount of error\")\n// ErrMaxAmountOfFinished will be returned if some other function(which we not expect) return success\nverifiers.ErrMaxAmountOfFinished = errors.New(\"verifier reach max amount success jobs\")\n```\n\n### verifier.All\n\n```go\ntype Verifier func(ctx context.Context) error\n\nAll(fns ...Verifier) error\n```\n\nMethod verifies is all function finished without error in given context timeout/deadline\n\nExample success:\n\n```go\nverifier := verifiers.New(ctx)\nstartTime := time.Now()\nerr := verifier.All(\n    func(ctx context.Context) error {\n        time.Sleep(time.Second)\n        return nil\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 2)\n        return nil\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 3)\n        return nil\n    },\n)\n// Because we should wait latest function\nassert.True(t, time.Now().Sub(startTime) \u003e= time.Second*3)\n```\n\nExample error:\n\n```go\nverifier := verifiers.New(ctx)\nstartTime := time.Now()\nerr := verifier.All(\n    func(ctx context.Context) error {\n        time.Sleep(time.Second)\n        return errors.New(\"\")\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 2)\n        return nil\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 3)\n        return nil\n    },\n)\n// Because we will throw error after first return it\nassert.True(t, time.Now().Sub(startTime) \u003c time.Second*2)\nassert.Err(t, verifiers.ErrMaxAmountOfError)\n```\n\n### verifier.OneOf\n\n```go\ntype Verifier func(ctx context.Context) error\n\nOneOf(fns ...Verifier) error\n```\n\nMethod verifies is at least one function finished without error in given context timeout/deadline\n\n```go\nverifier := verifiers.New(ctx)\nstartTime := time.Now()\nerr := verifier.OneOf(\n    func(ctx context.Context) error {\n        time.Sleep(time.Second)\n        return nil\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 2)\n        return errors.New(\"\")\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 3)\n        return nil\n    },\n)\n// Because we should wait second function\nassert.True(t, time.Now().Sub(startTime) \u003e= time.Second*1)\nassert.True(t, time.Now().Sub(startTime) \u003c time.Second*2)\nassert.Nil(t, err)\n```\n\n### verifier.AtLeast\n\n```go\ntype Verifier func(ctx context.Context) error\n\nAtLeast(count int, fns ...Verifier) error\n```\n\nMethod verifies is at least provided amount of functions will be finished without error in given context timeout/deadline\n\n```go\nverifier := verifiers.New(ctx)\nstartTime := time.Now()\nerr := verifier.AtLeast(\n    2,\n    func(ctx context.Context) error {\n        time.Sleep(time.Second)\n        return nil\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 2)\n        return nil\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 3)\n        return errors.New(\"\")\n    },\n)\n// Because we should wait second function\nassert.True(t, time.Now().Sub(startTime) \u003e time.Second*1)\nassert.True(t, time.Now().Sub(startTime) \u003c= time.Second*3)\nassert.Nil(t, err)\n```\n\n### verifier.Exact\n\n```go\ntype Verifier func(ctx context.Context) error\n\nExact(count int, fns ...Verifier) error\n```\n\nMethod verify exactly provided amount of functions finished without error in given context timeout/deadline\n\n```go\nverifier := verifiers.New(ctx)\nstartTime := time.Now()\nerr := verifier.Exact(\n    2,\n    func(ctx context.Context) error {\n        time.Sleep(time.Second)\n        return nil\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 2)\n        return nil\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 3)\n        return errors.New(\"\")\n    },\n)\n// Because we should wait three function(all functions should be finished)\nassert.True(t, time.Now().Sub(startTime) \u003e= time.Second*3)\nassert.Nil(t, err)\n```\n\n### verifier.OnlyOne\n\n```go\ntype Verifier func(ctx context.Context) error\n\nOnyOne(fns ...Verifier) error\n```\n\nMethod verify exactly one function finished without error in given context timeout/deadline\n\n```go\nverifier := verifiers.New(ctx)\nstartTime := time.Now()\nerr := verifier.OnlyOne(\n    func(ctx context.Context) error {\n        time.Sleep(time.Second)\n        return nil\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 2)\n        return errors.New(\"\")\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 3)\n        return errors.New(\"\")\n    },\n)\n// Because we should wait three function(all functions should be finished)\nassert.True(t, time.Now().Sub(startTime) \u003e= time.Second*3)\nassert.Nil(t, err)\n```\n\n### verifier.NoOne\n\n```go\ntype Verifier func(ctx context.Context) error\n\nNoOne(fns ...Verifier) error\n```\n\nMethod verifies no one from functions finished without error in given context timeout/deadline\n\n```go\nverifier := verifiers.New(ctx)\nstartTime := time.Now()\nerr := verifier.NoOne(\n    func(ctx context.Context) error {\n        time.Sleep(time.Second)\n        return errors.New(\"\")\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 2)\n        return errors.New(\"\")\n    },\n    func(ctx context.Context) error {\n        time.Sleep(time.Second * 3)\n        return errors.New(\"\")\n    },\n)\n// Because we should wait three function(all functions should be finished)\nassert.True(t, time.Now().Sub(startTime) \u003e= time.Second*3)\nassert.Nil(t, err)\n```\n\n### verifiers.FromArray\n\n**JUST FOR Go v1.18+(GENERIC)**\n\n```go\ntype Verifier func(ctx context.Context) error\n\nfunc FromArray[T any](arr []T, cmp func(context.Context, T) error) []Verifier\n```\n\nMethod FromArray generate Verifier from static generic array. With that method you can also verify static array\n\n```go\npackage verifiers_test\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"github.com/PxyUp/verifiers\"\n\t\"github.com/stretchr/testify/assert\"\n\t\"testing\"\n)\n\nfunc Test(t *testing.T) {\n\ttype People struct {\n\t\tName string\n\t\tAge  int\n\t}\n\n\tpeople := []*People{\n\t\t{\n\t\t\tAge:  20,\n\t\t\tName: \"First\",\n\t\t},\n\t\t{\n\t\t\tAge:  25,\n\t\t\tName: \"Second\",\n\t\t},\n\t\t{\n\t\t\tAge:  30,\n\t\t\tName: \"Third\",\n\t\t},\n\t}\n\n\tfns := verifiers.FromArray(people, func(ctx context.Context, p *People) error {\n\t\tif p.Age \u003e= 25 {\n\t\t\treturn nil\n\t\t}\n\t\treturn errors.New(\"to old\")\n\t})\n\n\tv := verifiers.New(context.Background())\n\n\tassert.Equal(t, verifiers.ErrMaxAmountOfError, v.All(fns...))\n\tassert.Equal(t, verifiers.ErrMaxAmountOfFinished, v.NoOne(fns...))\n\tassert.Equal(t, nil, v.OneOf(fns...))\n\tassert.Equal(t, nil, v.Exact(2, fns...))\n\tassert.Equal(t, verifiers.ErrMaxAmountOfFinished, v.OnlyOne(fns...))\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpxyup%2Fverifiers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpxyup%2Fverifiers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpxyup%2Fverifiers/lists"}