Skip to content

Commit

Permalink
Merge pull request containerd#9878 from amghazanfari/main
Browse files Browse the repository at this point in the history
refactor: clean switch statements and convert if to switch
  • Loading branch information
dmcgowan authored Feb 27, 2024
2 parents b1624c3 + bd44df8 commit c9c8346
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions core/snapshots/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func ParseKind(s string) Kind {
return KindActive
case "committed":
return KindCommitted
default:
return KindUnknown
}

return KindUnknown
}

// String returns the string representation of the Kind
Expand All @@ -79,9 +79,9 @@ func (k Kind) String() string {
return "Active"
case KindCommitted:
return "Committed"
default:
return "Unknown"
}

return "Unknown"
}

// MarshalJSON the Kind to JSON
Expand All @@ -102,25 +102,27 @@ func (k *Kind) UnmarshalJSON(b []byte) error {

// KindToProto converts from [Kind] to the protobuf definition [snapshots.Kind].
func KindToProto(kind Kind) snapshotsapi.Kind {
if kind == KindActive {
switch kind {
case KindActive:
return snapshotsapi.Kind_ACTIVE
}
if kind == KindView {
case KindView:
return snapshotsapi.Kind_VIEW
default:
return snapshotsapi.Kind_COMMITTED
}
return snapshotsapi.Kind_COMMITTED
}

// KindFromProto converts from the protobuf definition [snapshots.Kind] to
// [Kind].
func KindFromProto(kind snapshotsapi.Kind) Kind {
if kind == snapshotsapi.Kind_ACTIVE {
switch kind {
case snapshotsapi.Kind_ACTIVE:
return KindActive
}
if kind == snapshotsapi.Kind_VIEW {
case snapshotsapi.Kind_VIEW:
return KindView
default:
return KindCommitted
}
return KindCommitted
}

// Info provides information about a particular snapshot.
Expand Down

0 comments on commit c9c8346

Please sign in to comment.