streamline env gets with defaults
parent
b43e94c2ed
commit
defacb9f58
19
main.go
19
main.go
|
@ -64,14 +64,15 @@ type tildeData struct {
|
||||||
News []newsEntry // Collection of town news entries
|
News []newsEntry // Collection of town news entries
|
||||||
}
|
}
|
||||||
|
|
||||||
func homesDir() string {
|
func getEnvDefault(key, def string) string {
|
||||||
hDir := os.Getenv("HOMES_DIR")
|
result := os.Getenv(key)
|
||||||
if hDir == "" {
|
if result == "" {
|
||||||
hDir = "/home"
|
result = def
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
return hDir
|
func homesDir() string { return getEnvDefault("HOMES_DIR", "/home") }
|
||||||
}
|
|
||||||
|
|
||||||
func getNews() (entries []newsEntry, err error) {
|
func getNews() (entries []newsEntry, err error) {
|
||||||
inMeta := true
|
inMeta := true
|
||||||
|
@ -79,10 +80,7 @@ func getNews() (entries []newsEntry, err error) {
|
||||||
current := newsEntry{}
|
current := newsEntry{}
|
||||||
blankLineRe := regexp.MustCompile(`^ *\n$`)
|
blankLineRe := regexp.MustCompile(`^ *\n$`)
|
||||||
|
|
||||||
newsPath := os.Getenv("NEWS_PATH")
|
newsPath := getEnvDefault("NEWS_PATH", "/town/news.posts")
|
||||||
if newsPath == "" {
|
|
||||||
newsPath = "/town/news.posts"
|
|
||||||
}
|
|
||||||
|
|
||||||
newsFile, err := os.Open(newsPath)
|
newsFile, err := os.Open(newsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -243,7 +241,6 @@ func (x byMtime) Less(i, j int) bool { return x[i].Mtime > x[j].Mtime } // becau
|
||||||
func (x byMtime) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
func (x byMtime) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
||||||
|
|
||||||
func getUsers() (users []*user, err error) {
|
func getUsers() (users []*user, err error) {
|
||||||
// TODO sort by mtime
|
|
||||||
// For the purposes of this program, we discover users via:
|
// For the purposes of this program, we discover users via:
|
||||||
// - presence in /home/
|
// - presence in /home/
|
||||||
// - absence in systemUsers list (sourced from source code and potentially augmented by an environment variable)
|
// - absence in systemUsers list (sourced from source code and potentially augmented by an environment variable)
|
||||||
|
|
Loading…
Reference in New Issue