From 2ee380c0e2c0cb3d833129a6c9ac5d7fed466041 Mon Sep 17 00:00:00 2001 From: Xavier Michelon Date: Sun, 17 Mar 2024 12:11:19 +0100 Subject: [PATCH] added some drive enum stringer methods. --- share_types.go | 41 ++++++++++++++++++++++++++++++++++++++++- volume_types.go | 26 ++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/share_types.go b/share_types.go index 6966c13..99d9aea 100644 --- a/share_types.go +++ b/share_types.go @@ -1,6 +1,10 @@ package proton -import "github.com/ProtonMail/gopenpgp/v2/crypto" +import ( + "fmt" + + "github.com/ProtonMail/gopenpgp/v2/crypto" +) type ShareMetadata struct { ShareID string // Encrypted share ID @@ -76,6 +80,19 @@ const ( ShareTypeDevice ShareType = 3 ) +func (t ShareType) String() string { + switch t { + case ShareTypeMain: + return "main" + case ShareTypeStandard: + return "standard" + case ShareTypeDevice: + return "device" + default: + return fmt.Sprintf("unknown (%v)", int(t)) + } +} + type ShareState int const ( @@ -83,9 +100,31 @@ const ( ShareStateDeleted ShareState = 2 ) +func (s ShareState) String() string { + switch s { + case ShareStateActive: + return "active" + case ShareStateDeleted: + return "deleted" + default: + return fmt.Sprintf("unknown (%v)", int(s)) + } +} + type ShareFlags int const ( NoFlags ShareFlags = iota PrimaryShare ) + +func (f ShareFlags) String() string { + switch f { + case NoFlags: + return "none" + case PrimaryShare: + return "primary" + default: + return fmt.Sprintf("unknown (%v)", int(f)) + } +} diff --git a/volume_types.go b/volume_types.go index f728932..0590d8d 100644 --- a/volume_types.go +++ b/volume_types.go @@ -1,5 +1,7 @@ package proton +import "fmt" + // Volume is a Proton Drive volume. type Volume struct { VolumeID string // Encrypted volume ID @@ -30,6 +32,17 @@ const ( VolumeStateLocked VolumeState = 3 ) +func (v VolumeState) String() string { + switch v { + case VolumeStateActive: + return "active" + case VolumeStateLocked: + return "locked" + default: + return fmt.Sprintf("unknown (%v)", int(v)) + } +} + // VolumeRestoreStatus is the status of the restore task. type VolumeRestoreStatus int @@ -38,3 +51,16 @@ const ( RestoreStatusInProgress VolumeRestoreStatus = 1 RestoreStatusFailed VolumeRestoreStatus = -1 ) + +func (rs VolumeRestoreStatus) String() string { + switch rs { + case RestoreStatusDone: + return "done" + case RestoreStatusInProgress: + return "in progress" + case RestoreStatusFailed: + return "failed" + default: + return fmt.Sprintf("unknown (%v)", int(rs)) + } +}