Initial quick and dirty code, TODO: pushover actions, crontab, and cleanliness
This commit is contained in:
parent
445be657f2
commit
ed13a5994f
8 changed files with 667 additions and 0 deletions
7
config/config.go
Normal file
7
config/config.go
Normal 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
51
config/env.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue