Merge pull request #9878 from amghazanfari/main

refactor: clean switch statements and convert if to switch
This commit is contained in:
Derek McGowan 2024-02-27 05:14:01 +00:00 committed by GitHub
commit c9c8346bfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -65,10 +65,10 @@ func ParseKind(s string) Kind {
return KindActive
case "committed":
return KindCommitted
}
default:
return KindUnknown
}
}
// String returns the string representation of the Kind
func (k Kind) String() string {
@ -79,10 +79,10 @@ func (k Kind) String() string {
return "Active"
case KindCommitted:
return "Committed"
}
default:
return "Unknown"
}
}
// MarshalJSON the Kind to JSON
func (k Kind) MarshalJSON() ([]byte, error) {
@ -102,26 +102,28 @@ 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
}
}
// 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
}
}
// Info provides information about a particular snapshot.
// JSON marshalling is supported for interacting with tools like ctr,