mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-29 01:45:35 +02:00
WIP: CLI, relates to #46
This commit is contained in:
parent
4346f55b29
commit
1e8421e8ce
10 changed files with 571 additions and 102 deletions
util
23
util/util.go
23
util/util.go
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue