From 670a706a245efdd455f0528dbea10a338b133675 Mon Sep 17 00:00:00 2001 From: Marcus Perlick Date: Thu, 27 Jun 2024 15:21:59 +0200 Subject: [PATCH] Make known type strings const instead of var --- packageurl.go | 180 +++++++++++++++++++++++++------------------------- 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/packageurl.go b/packageurl.go index 0dd89a7..b8ce937 100644 --- a/packageurl.go +++ b/packageurl.go @@ -51,7 +51,7 @@ var ( // These are the known purl types as defined in the spec. Some of these require // special treatment during parsing. // https://github.com/package-url/purl-spec#known-purl-types -var ( +const ( // TypeAlpm is a pkg:alpm purl. TypeAlpm = "alpm" // TypeApk is a pkg:apk purl. @@ -112,42 +112,44 @@ var ( TypeSWID = "swid" // TypeSwift is pkg:swift purl TypeSwift = "swift" +) - // KnownTypes is a map of types that are officially supported by the spec. - // See https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#known-purl-types - KnownTypes = map[string]struct{}{ - TypeAlpm: {}, - TypeApk: {}, - TypeBitbucket: {}, - TypeBitnami: {}, - TypeCargo: {}, - TypeCocoapods: {}, - TypeComposer: {}, - TypeConan: {}, - TypeConda: {}, - TypeCran: {}, - TypeDebian: {}, - TypeDocker: {}, - TypeGem: {}, - TypeGeneric: {}, - TypeGithub: {}, - TypeGolang: {}, - TypeHackage: {}, - TypeHex: {}, - TypeHuggingface: {}, - TypeMaven: {}, - TypeMLFlow: {}, - TypeNPM: {}, - TypeNuget: {}, - TypeOCI: {}, - TypePub: {}, - TypePyPi: {}, - TypeQpkg: {}, - TypeRPM: {}, - TypeSWID: {}, - TypeSwift: {}, - } +// KnownTypes is a map of types that are officially supported by the spec. +// See https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#known-purl-types +var KnownTypes = map[string]struct{}{ + TypeAlpm: {}, + TypeApk: {}, + TypeBitbucket: {}, + TypeBitnami: {}, + TypeCargo: {}, + TypeCocoapods: {}, + TypeComposer: {}, + TypeConan: {}, + TypeConda: {}, + TypeCran: {}, + TypeDebian: {}, + TypeDocker: {}, + TypeGem: {}, + TypeGeneric: {}, + TypeGithub: {}, + TypeGolang: {}, + TypeHackage: {}, + TypeHex: {}, + TypeHuggingface: {}, + TypeMaven: {}, + TypeMLFlow: {}, + TypeNPM: {}, + TypeNuget: {}, + TypeOCI: {}, + TypePub: {}, + TypePyPi: {}, + TypeQpkg: {}, + TypeRPM: {}, + TypeSWID: {}, + TypeSwift: {}, +} +const ( TypeApache = "apache" TypeAndroid = "android" TypeAtom = "atom" @@ -196,62 +198,62 @@ var ( TypeVim = "vim" TypeWORDPRESS = "wordpress" TypeYocto = "yocto" - - // CandidateTypes is a map of types that are not yet officially supported by the spec, - // but are being considered for inclusion. - // See https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#other-candidate-types-to-define - CandidateTypes = map[string]struct{}{ - TypeApache: {}, - TypeAndroid: {}, - TypeAtom: {}, - TypeBower: {}, - TypeBrew: {}, - TypeBuildroot: {}, - TypeCarthage: {}, - TypeChef: {}, - TypeChocolatey: {}, - TypeClojars: {}, - TypeCoreos: {}, - TypeCpan: {}, - TypeCtan: {}, - TypeCrystal: {}, - TypeDrupal: {}, - TypeDtype: {}, - TypeDub: {}, - TypeElm: {}, - TypeEclipse: {}, - TypeGitea: {}, - TypeGitlab: {}, - TypeGradle: {}, - TypeGuix: {}, - TypeHaxe: {}, - TypeHelm: {}, - TypeJulia: {}, - TypeLua: {}, - TypeMelpa: {}, - TypeMeteor: {}, - TypeNim: {}, - TypeNix: {}, - TypeOpam: {}, - TypeOpenwrt: {}, - TypeOsgi: {}, - TypeP2: {}, - TypePear: {}, - TypePecl: {}, - TypePERL6: {}, - TypePlatformio: {}, - TypeEbuild: {}, - TypePuppet: {}, - TypeSourceforge: {}, - TypeSublime: {}, - TypeTerraform: {}, - TypeVagrant: {}, - TypeVim: {}, - TypeWORDPRESS: {}, - TypeYocto: {}, - } ) +// CandidateTypes is a map of types that are not yet officially supported by the spec, +// but are being considered for inclusion. +// See https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#other-candidate-types-to-define +var CandidateTypes = map[string]struct{}{ + TypeApache: {}, + TypeAndroid: {}, + TypeAtom: {}, + TypeBower: {}, + TypeBrew: {}, + TypeBuildroot: {}, + TypeCarthage: {}, + TypeChef: {}, + TypeChocolatey: {}, + TypeClojars: {}, + TypeCoreos: {}, + TypeCpan: {}, + TypeCtan: {}, + TypeCrystal: {}, + TypeDrupal: {}, + TypeDtype: {}, + TypeDub: {}, + TypeElm: {}, + TypeEclipse: {}, + TypeGitea: {}, + TypeGitlab: {}, + TypeGradle: {}, + TypeGuix: {}, + TypeHaxe: {}, + TypeHelm: {}, + TypeJulia: {}, + TypeLua: {}, + TypeMelpa: {}, + TypeMeteor: {}, + TypeNim: {}, + TypeNix: {}, + TypeOpam: {}, + TypeOpenwrt: {}, + TypeOsgi: {}, + TypeP2: {}, + TypePear: {}, + TypePecl: {}, + TypePERL6: {}, + TypePlatformio: {}, + TypeEbuild: {}, + TypePuppet: {}, + TypeSourceforge: {}, + TypeSublime: {}, + TypeTerraform: {}, + TypeVagrant: {}, + TypeVim: {}, + TypeWORDPRESS: {}, + TypeYocto: {}, +} + // Qualifier represents a single key=value qualifier in the package url type Qualifier struct { Key string