mirror of
https://github.com/rclone/rclone
synced 2024-12-28 21:03:45 +01:00
e43b5ce5e5
This is possible now that we no longer support go1.12 and brings rclone into line with standard practices in the Go world. This also removes errors.New and errors.Errorf from lib/errors and prefers the stdlib errors package over lib/errors.
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package fs
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// CutoffMode describes the possible delete modes in the config
|
|
type CutoffMode byte
|
|
|
|
// MaxTransferMode constants
|
|
const (
|
|
CutoffModeHard CutoffMode = iota
|
|
CutoffModeSoft
|
|
CutoffModeCautious
|
|
CutoffModeDefault = CutoffModeHard
|
|
)
|
|
|
|
var cutoffModeToString = []string{
|
|
CutoffModeHard: "HARD",
|
|
CutoffModeSoft: "SOFT",
|
|
CutoffModeCautious: "CAUTIOUS",
|
|
}
|
|
|
|
// String turns a LogLevel into a string
|
|
func (m CutoffMode) String() string {
|
|
if m >= CutoffMode(len(cutoffModeToString)) {
|
|
return fmt.Sprintf("CutoffMode(%d)", m)
|
|
}
|
|
return cutoffModeToString[m]
|
|
}
|
|
|
|
// Set a LogLevel
|
|
func (m *CutoffMode) Set(s string) error {
|
|
for n, name := range cutoffModeToString {
|
|
if s != "" && name == strings.ToUpper(s) {
|
|
*m = CutoffMode(n)
|
|
return nil
|
|
}
|
|
}
|
|
return fmt.Errorf("Unknown cutoff mode %q", s)
|
|
}
|
|
|
|
// Type of the value
|
|
func (m *CutoffMode) Type() string {
|
|
return "string"
|
|
}
|
|
|
|
// UnmarshalJSON makes sure the value can be parsed as a string or integer in JSON
|
|
func (m *CutoffMode) UnmarshalJSON(in []byte) error {
|
|
return UnmarshalJSONFlag(in, m, func(i int64) error {
|
|
if i < 0 || i >= int64(len(cutoffModeToString)) {
|
|
return fmt.Errorf("Out of range cutoff mode %d", i)
|
|
}
|
|
*m = (CutoffMode)(i)
|
|
return nil
|
|
})
|
|
}
|