{"id":18994047,"url":"https://github.com/swaggest/usecase","last_synced_at":"2025-09-01T09:38:01.130Z","repository":{"id":39719074,"uuid":"231456183","full_name":"swaggest/usecase","owner":"swaggest","description":"Clean Architecture Use Case for Go","archived":false,"fork":false,"pushed_at":"2023-12-19T01:13:44.000Z","size":49,"stargazers_count":34,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T12:55:53.245Z","etag":null,"topics":["clean-architecture","hacktoberfest","usecase"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/swaggest/usecase","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/swaggest.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":"2020-01-02T20:41:07.000Z","updated_at":"2025-02-24T19:46:35.000Z","dependencies_parsed_at":"2023-12-19T04:56:27.491Z","dependency_job_id":null,"html_url":"https://github.com/swaggest/usecase","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/swaggest/usecase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fusecase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fusecase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fusecase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fusecase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swaggest","download_url":"https://codeload.github.com/swaggest/usecase/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fusecase/sbom","scorecard":{"id":861519,"data":{"date":"2025-08-11","repo":{"name":"github.com/swaggest/usecase","commit":"90e267b09e101189bf5dba73049c7055a0babd28"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/24 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/cloc.yml:1","Warn: no topLevel permission defined: .github/workflows/golangci-lint.yml:1","Warn: no topLevel permission defined: .github/workflows/gorelease.yml:1","Warn: no topLevel permission defined: .github/workflows/test-unit.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/cloc.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/cloc.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/cloc.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/cloc.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/cloc.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/cloc.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/golangci-lint.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/golangci-lint.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/golangci-lint.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/golangci-lint.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/golangci-lint.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/golangci-lint.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gorelease.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/gorelease.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gorelease.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/gorelease.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gorelease.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/gorelease.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/gorelease.yml:48: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/gorelease.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-unit.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/test-unit.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-unit.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/test-unit.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-unit.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/test-unit.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-unit.yml:62: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/test-unit.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test-unit.yml:107: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/test-unit.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test-unit.yml:133: update your workflow using https://app.stepsecurity.io/secureworkflow/swaggest/usecase/test-unit.yml/master?enable=pin","Warn: goCommand not pinned by hash: .github/workflows/gorelease.yml:42","Info:   0 out of  11 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   5 third-party GitHubAction dependencies pinned","Info:   0 out of   1 goCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 16 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-24T01:26:33.742Z","repository_id":39719074,"created_at":"2025-08-24T01:26:33.742Z","updated_at":"2025-08-24T01:26:33.742Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273100674,"owners_count":25045700,"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","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["clean-architecture","hacktoberfest","usecase"],"created_at":"2024-11-08T17:23:57.173Z","updated_at":"2025-09-01T09:38:01.108Z","avatar_url":"https://github.com/swaggest.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Use Case Interactor\n\n[![Build Status](https://github.com/swaggest/usecase/workflows/test-unit/badge.svg)](https://github.com/swaggest/usecase/actions?query=branch%3Amaster+workflow%3Atest-unit)\n[![Coverage Status](https://codecov.io/gh/swaggest/usecase/branch/master/graph/badge.svg)](https://codecov.io/gh/swaggest/usecase)\n[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/github.com/swaggest/usecase)\n![Code lines](https://sloc.xyz/github/swaggest/usecase/?category=code)\n![Comments](https://sloc.xyz/github/swaggest/usecase/?category=comments)\n\nThis module defines generalized contract of *Use Case Interactor* to enable \n[The Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) \nin Go application.\n\n![Clean Architecture](https://blog.cleancoder.com/uncle-bob/images/2012-08-13-the-clean-architecture/CleanArchitecture.jpg)\n\n## Why?\n\nIsolating transport layer from business logic reduces coupling and allows better control on both transport and business \nsides. For example the application needs to consume AMQP events and act on them, with isolated use case interactor it is \neasy to trigger same action with HTTP message (as a part of developer tools).\n\nUse case interactors declare their ports and may serve as a source of information for documentation automation.\n\nThis abstraction is intended for use with automated transport layer, for example see [`REST`](https://github.com/swaggest/rest).\n\n## Usage\n\n### Input/Output Definitions\n\n```go\n// Configure use case interactor in application layer.\ntype myInput struct {\n    Param1 int    `path:\"param1\" description:\"Parameter in resource path.\" multipleOf:\"2\"`\n    Param2 string `json:\"param2\" description:\"Parameter in resource body.\"`\n}\n\ntype myOutput struct {\n    Value1 int    `json:\"value1\"`\n    Value2 string `json:\"value2\"`\n}\n\n```\n### Classic API\n\n```go\nu := usecase.NewIOI(new(myInput), new(myOutput), func(ctx context.Context, input, output interface{}) error {\n    var (\n        in  = input.(*myInput)\n        out = output.(*myOutput)\n    )\n\n    if in.Param1%2 != 0 {\n        return status.InvalidArgument\n    }\n\n    // Do something to set output based on input.\n    out.Value1 = in.Param1 + in.Param1\n    out.Value2 = in.Param2 + in.Param2\n\n    return nil\n})\n\n```\n\n### Generic API with type parameters\n\nWith `go1.18` and later (or [`gotip`](https://pkg.go.dev/golang.org/dl/gotip)) you can use simplified generic API instead \nof classic API based on `interface{}`.\n\n```go\nu := usecase.NewInteractor(func(ctx context.Context, input myInput, output *myOutput) error {\n    if in.Param1%2 != 0 {\n        return status.InvalidArgument\n    }\n\n    // Do something to set output based on input.\n    out.Value1 = in.Param1 + in.Param1\n    out.Value2 = in.Param2 + in.Param2\n\n    return nil\n})\n```\n\n### Further Configuration And Usage\n\n```go\n// Additional properties can be configured for purposes of automated documentation.\nu.SetTitle(\"Doubler\")\nu.SetDescription(\"Doubler doubles parameter values.\")\nu.SetTags(\"transformation\")\nu.SetExpectedErrors(status.InvalidArgument)\nu.SetIsDeprecated(true)\n```\n\nThen use configured use case interactor with transport/documentation/etc adapter.\n\nFor example with [REST](https://github.com/swaggest/rest/blob/v0.1.18/_examples/basic/main.go#L95-L96) router:\n```go\n// Add use case handler to router.\nr.Method(http.MethodPost, \"/double/{param1}\", nethttp.NewHandler(u))\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswaggest%2Fusecase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswaggest%2Fusecase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswaggest%2Fusecase/lists"}