From bd44df8a1c132e118a94b67ca159a2c30b715805 Mon Sep 17 00:00:00 2001 From: amghazanfari Date: Mon, 26 Feb 2024 22:07:14 +0330 Subject: [PATCH] refactor code - clean switch and if statements Signed-off-by: amghazanfari --- core/snapshots/snapshotter.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/core/snapshots/snapshotter.go b/core/snapshots/snapshotter.go index bf628fb87..f96c949d6 100644 --- a/core/snapshots/snapshotter.go +++ b/core/snapshots/snapshotter.go @@ -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 @@ -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 @@ -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.