Initial WIP logic to handle loading configuration from the disk using viper

This commit is contained in:
Dane Everitt
2021-01-12 21:14:57 -08:00
parent d45a159456
commit 9480ccdbba
9 changed files with 213 additions and 287 deletions

View File

@@ -7,14 +7,35 @@ import (
"encoding/json"
"fmt"
"io"
"strconv"
"strings"
"sync"
"time"
"emperror.dev/errors"
)
var cr = []byte(" \r")
var crr = []byte("\r\n")
// FirstNotEmpty returns the first string passed in that is not an empty value.
func FirstNotEmpty(v ...string) string {
for _, val := range v {
if val != "" {
return val
}
}
return ""
}
func MustInt(v string) int {
i, err := strconv.Atoi(v)
if err != nil {
panic(errors.Wrap(err, "system/utils: could not parse int"))
}
return i
}
func ScanReader(r io.Reader, callback func(line string)) error {
br := bufio.NewReader(r)
// Avoid constantly re-allocating memory when we're flooding lines through this