1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-05-29 01:45:35 +02:00

WIP: CLI, relates to

This commit is contained in:
Philipp Heckel 2021-12-16 20:33:01 -05:00
parent 4346f55b29
commit 1e8421e8ce
10 changed files with 571 additions and 102 deletions

View file

@ -1,9 +1,11 @@
package util
import (
"errors"
"fmt"
"math/rand"
"os"
"strings"
"sync"
"time"
)
@ -15,6 +17,8 @@ const (
var (
random = rand.New(rand.NewSource(time.Now().UnixNano()))
randomMutex = sync.Mutex{}
errInvalidPriority = errors.New("unknown priority")
)
// FileExists checks if a file exists, and returns true if it does
@ -75,3 +79,22 @@ func DurationToHuman(d time.Duration) (str string) {
}
return
}
func ParsePriority(priority string) (int, error) {
switch strings.ToLower(priority) {
case "":
return 0, nil
case "1", "min":
return 1, nil
case "2", "low":
return 2, nil
case "3", "default":
return 3, nil
case "4", "high":
return 4, nil
case "5", "max", "urgent":
return 5, nil
default:
return 0, errInvalidPriority
}
}