mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-05-09 05:48:11 +00:00
* feat: add support for oauth whitelist file (#817) * Merge branch 'main' into feat/oauth-whitelist-file * fix: fix conflicts * tests: use testify for testing --------- Co-authored-by: Stavros <steveiliop56@gmail.com>
This commit is contained in:
@@ -28,3 +28,41 @@ func CoalesceToString(value any) string {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func ParseNonEmptyLines(contents string) []string {
|
||||
lines := make([]string, 0)
|
||||
|
||||
for line := range strings.SplitSeq(contents, "\n") {
|
||||
lineTrimmed := strings.TrimSpace(line)
|
||||
if lineTrimmed == "" {
|
||||
continue
|
||||
}
|
||||
lines = append(lines, lineTrimmed)
|
||||
}
|
||||
|
||||
return lines
|
||||
}
|
||||
|
||||
func GetStringList(valuesCfg []string, valuesPath string) ([]string, error) {
|
||||
values := make([]string, 0, len(valuesCfg))
|
||||
|
||||
for _, value := range valuesCfg {
|
||||
valueTrimmed := strings.TrimSpace(value)
|
||||
if valueTrimmed == "" {
|
||||
continue
|
||||
}
|
||||
values = append(values, valueTrimmed)
|
||||
}
|
||||
|
||||
if valuesPath == "" {
|
||||
return values, nil
|
||||
}
|
||||
|
||||
contents, err := ReadFile(valuesPath)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
|
||||
values = append(values, ParseNonEmptyLines(contents)...)
|
||||
return values, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user