{"id":48939971,"url":"https://github.com/scanoss/go-component-helper","last_synced_at":"2026-04-17T13:11:54.249Z","repository":{"id":340678216,"uuid":"1164820103","full_name":"scanoss/go-component-helper","owner":"scanoss","description":null,"archived":false,"fork":false,"pushed_at":"2026-03-31T18:09:40.000Z","size":57,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-31T19:34:40.905Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scanoss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-23T14:19:49.000Z","updated_at":"2026-03-19T20:25:50.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/scanoss/go-component-helper","commit_stats":null,"previous_names":["scanoss/go-component-helper"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/scanoss/go-component-helper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scanoss%2Fgo-component-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scanoss%2Fgo-component-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scanoss%2Fgo-component-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scanoss%2Fgo-component-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scanoss","download_url":"https://codeload.github.com/scanoss/go-component-helper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scanoss%2Fgo-component-helper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31930255,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T12:37:54.787Z","status":"ssl_error","status_checked_at":"2026-04-17T12:37:25.095Z","response_time":62,"last_error":"SSL_read: 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":[],"created_at":"2026-04-17T13:11:53.384Z","updated_at":"2026-04-17T13:11:54.244Z","avatar_url":"https://github.com/scanoss.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SCANOSS Platform 2.0 Component Helper Package\nWelcome to the SCANOSS Platform 2.0 component helper package.\n\nThis package contains helper functions to make development of Go services easier to configure for component version resolution.\n\n## Usage\nThe main function in this package is `GetComponentsVersion`. It takes a list of components (with PURLs and optional requirements), resolves their concrete versions using the SCANOSS API, and returns the results.\n\n```go\nimport (\n    componenthelper \"github.com/scanoss/go-component-helper/componenthelper\"\n)\n\nresults := componenthelper.GetComponentsVersion(componenthelper.ComponentVersionCfg{\n    MaxWorkers: 5,\n    Ctx:        ctx,\n    S:          logger,\n    DB:         db,\n    Input: []componenthelper.ComponentDTO{\n        {Purl: \"pkg:npm/lodash\", Requirement: \"\u003e=4.17.0\"},\n        {Purl: \"pkg:github/scanoss/scanner.c@1.2.3\"},\n    },\n})\n```\n\n### PURL Version Handling\nWhen a PURL contains a version (e.g., `pkg:github/scanoss/scanner.c@1.2.3`), the version is automatically extracted and moved to the `Requirement` field. **This overwrites any existing requirement.** The PURL is then stored without the version (e.g., `pkg:github/scanoss/scanner.c`).\n\nThis means the following inputs are equivalent:\n- `{Purl: \"pkg:npm/lodash@4.17.0\"}`\n- `{Purl: \"pkg:npm/lodash\", Requirement: \"4.17.0\"}`\n\nQualifiers and subpaths in the PURL are preserved (e.g., `pkg:npm/%40scope/name@1.0.0?repository_url=https://example.com` becomes `pkg:npm/%40scope/name?repository_url=https://example.com` with Requirement `1.0.0`).\n\n### FindNearestVersion\nThe `FindNearestVersion` utility resolves the closest semver version from a list of candidates. It strips any range operators from the requirement, then picks the candidate with the smallest weighted distance (major \u003e minor \u003e patch). On a tie, it prefers the higher version.\n\n```go\nimport (\n    \"github.com/scanoss/go-component-helper/componenthelper/utils\"\n)\n\ncandidates := []string{\"1.0.0\", \"1.2.0\", \"1.4.0\", \"2.0.0\"}\n\n// Exact match\nutils.FindNearestVersion(\"1.2.0\", candidates) // \"1.2.0\"\n\n// Nearest version (1.3.0 is equidistant from 1.2.0 and 1.4.0, prefers higher)\nutils.FindNearestVersion(\"1.3.0\", candidates) // \"1.4.0\"\n\n// Operators are stripped before comparing\nutils.FindNearestVersion(\"\u003e=1.3.0\", candidates) // \"1.4.0\"\n\n// Invalid requirement returns empty string\nutils.FindNearestVersion(\"not-a-version\", candidates) // \"\"\n```\n\nMore details about each function can be found in the packaged documentation.\n\n## Bugs/Features\nTo request features or alert about bugs, please do so [here](https://github.com/scanoss/go-component-helper/issues).\n\n## Changelog\nDetails of major changes to the library can be found in [CHANGELOG.md](CHANGELOG.md).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscanoss%2Fgo-component-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscanoss%2Fgo-component-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscanoss%2Fgo-component-helper/lists"}