mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
a7e867a699
This commit replaces github.com/spf13/viper with github.com/knadh/koanf. Koanf is very similar library to viper, with less dependencies and several quality of life differences. This also allows most config options to be defined by ENV. Lastly it also enables the use of split configuration files which can be configured by setting the --config flag multiple times. Co-authored-by: Amir Zarrinkafsh <nightah@me.com>
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package utils
|
|
|
|
import "runtime"
|
|
|
|
// ErrSliceSortAlphabetical is a helper type that can be used with sort.Sort to sort a slice of errors in alphabetical
|
|
// order. Usage is simple just do sort.Sort(ErrSliceSortAlphabetical([]error{})).
|
|
type ErrSliceSortAlphabetical []error
|
|
|
|
func (s ErrSliceSortAlphabetical) Len() int { return len(s) }
|
|
|
|
func (s ErrSliceSortAlphabetical) Less(i, j int) bool { return s[i].Error() < s[j].Error() }
|
|
|
|
func (s ErrSliceSortAlphabetical) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
|
|
|
// GetExpectedErrTxt returns error text for expected errs.
|
|
func GetExpectedErrTxt(err string) string {
|
|
switch err {
|
|
case "pathnotfound":
|
|
switch runtime.GOOS {
|
|
case windows:
|
|
return "open %s: The system cannot find the path specified."
|
|
default:
|
|
return errFmtLinuxNotFound
|
|
}
|
|
case "filenotfound":
|
|
switch runtime.GOOS {
|
|
case windows:
|
|
return "open %s: The system cannot find the file specified."
|
|
default:
|
|
return errFmtLinuxNotFound
|
|
}
|
|
case "yamlisdir":
|
|
switch runtime.GOOS {
|
|
case windows:
|
|
return "read %s: The handle is invalid."
|
|
default:
|
|
return "read %s: is a directory"
|
|
}
|
|
}
|
|
|
|
return ""
|
|
}
|