Skip to content

Commit

Permalink
Reusing constant values to parse enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
blkt committed Nov 20, 2024
1 parent 3643fb4 commit 8f2034e
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions pkg/v2/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type PackageSummaryAnnotation struct {
// changes to `"complete"` once processed.
type Status string

var (
const (
// StatusInProgress represents a package being processed.
StatusInProgress Status = "in_progress"
// StatusComplete represents an already processed package.
Expand All @@ -67,9 +67,9 @@ func (t *Status) UnmarshalJSON(data []byte) error {
}

switch tmp {
case "in_progress":
case string(StatusInProgress):
*t = StatusInProgress
case "complete":
case string(StatusComplete):
*t = StatusComplete
default:
return fmt.Errorf("invalid status type: %s", tmp)
Expand All @@ -96,7 +96,7 @@ type SummaryDescription struct {
// was able to gather.
type ProvenanceType string

var (
const (
// ProvenanceTypeVerified represents a fully verified
// provenance information.
ProvenanceTypeVerified ProvenanceType = "verified_provenance_match"
Expand All @@ -118,13 +118,13 @@ func (t *ProvenanceType) UnmarshalJSON(data []byte) error {
}

switch tmp {
case "verified_provenance_match":
case string(ProvenanceTypeVerified):
*t = ProvenanceTypeVerified
case "historical_provenance_match":
case string(ProvenanceTypeHistorical):
*t = ProvenanceTypeHistorical
case "unknown":
case string(ProvenanceTypeUnknown):
*t = ProvenanceTypeUnknown
case "historical_provenance_mismatched":
case string(ProvenanceTypeMismatched):
*t = ProvenanceTypeMismatched
default:
return fmt.Errorf("invalid provenance type: %s", tmp)
Expand All @@ -141,7 +141,7 @@ type PackageType string
// as they're added to Trusty. The downside of this is that sdk users
// must match new types manually until we add the case to the list.

var (
const (
// PackageTypePypi is the ecosystem of Python packages.
PackageTypePypi PackageType = "pypi"
// PackageTypeNpm is the ecosystem of JavaScript packages.
Expand All @@ -158,7 +158,7 @@ var (
// repository.
type PackageStatus string

var (
const (
// PackageStatusPending represents status pending
PackageStatusPending PackageStatus = "pending"
// PackageStatusInitial represents status initial
Expand All @@ -185,21 +185,21 @@ func (t *PackageStatus) UnmarshalJSON(data []byte) error {
}

switch tmp {
case "pending":
case string(PackageStatusPending):
*t = PackageStatusPending
case "initial":
case string(PackageStatusInitial):
*t = PackageStatusInitial
case "neighbours":
case string(PackageStatusNeighbours):
*t = PackageStatusNeighbours
case "complete":
case string(PackageStatusComplete):
*t = PackageStatusComplete
case "failed":
case string(PackageStatusFailed):
*t = PackageStatusFailed
case "scoring":
case string(PackageStatusScoring):
*t = PackageStatusScoring
case "propagate":
case string(PackageStatusPropagate):
*t = PackageStatusPropagate
case "deleted":
case string(PackageStatusDeleted):
*t = PackageStatusDeleted
default:
return fmt.Errorf("invalid package status type: %s", tmp)
Expand Down

0 comments on commit 8f2034e

Please sign in to comment.