Initial quick and dirty code, TODO: pushover actions, crontab, and cleanliness

This commit is contained in:
Tony Blyler 2021-05-18 01:25:18 -04:00
parent 445be657f2
commit ed13a5994f
Signed by: tblyler
GPG key ID: 7F13D9A60C0D678E
8 changed files with 667 additions and 0 deletions

7
config/config.go Normal file
View file

@ -0,0 +1,7 @@
package config
// Config for application setup
type Config interface {
BadgerPath() (string, error)
PushoverAPIToken() (string, error)
}

51
config/env.go Normal file
View file

@ -0,0 +1,51 @@
package config
import (
"errors"
"fmt"
"os"
)
const (
// BadgerPathEnv name
BadgerPathEnv = "BADGER_PATH"
// PushoverAPITokenEnv name
PushoverAPITokenEnv = "PUSHOVER_API_TOKEN"
)
var (
// ErrEnvVariableNotSet occurs when an environment variable is not set
ErrEnvVariableNotSet = errors.New("environment variable is not set")
)
// Env variable Config implementation
type Env struct {
}
// BadgerPath for the database directory
func (e *Env) BadgerPath() (string, error) {
val, ok := os.LookupEnv(BadgerPathEnv)
if !ok {
return "", fmt.Errorf(
"unable to get badger path from env variable %s: %w",
BadgerPathEnv,
ErrEnvVariableNotSet,
)
}
return val, nil
}
// PushoverAPIToken getter
func (e *Env) PushoverAPIToken() (string, error) {
val, ok := os.LookupEnv(PushoverAPITokenEnv)
if !ok {
return "", fmt.Errorf(
"unable to get pushover API token from env variable %s: %w",
PushoverAPITokenEnv,
ErrEnvVariableNotSet,
)
}
return val, nil
}