mirror of
https://github.com/lightninglabs/aperture.git
synced 2025-12-18 09:34:20 +01:00
42 lines
746 B
Go
42 lines
746 B
Go
package auth
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/lightninglabs/kirin/freebie"
|
|
)
|
|
|
|
type Level string
|
|
|
|
func (l Level) lower() string {
|
|
return strings.ToLower(string(l))
|
|
}
|
|
|
|
func (l Level) IsOn() bool {
|
|
lower := l.lower()
|
|
return lower == "" || lower == "on" || lower == "true"
|
|
}
|
|
|
|
func (l Level) IsFreebie() bool {
|
|
return strings.HasPrefix(l.lower(), "freebie")
|
|
}
|
|
|
|
func (l Level) FreebieCount() freebie.Count {
|
|
parts := strings.Split(l.lower(), " ")
|
|
if len(parts) != 2 {
|
|
panic(fmt.Errorf("invalid auth value: %s", l.lower()))
|
|
}
|
|
count, err := strconv.Atoi(parts[1])
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return freebie.Count(count)
|
|
}
|
|
|
|
func (l Level) IsOff() bool {
|
|
lower := l.lower()
|
|
return lower == "off" || lower == "false"
|
|
}
|