James Tombleson
11892b9a7b
* starting the ffxiv reader * working on getting the standard interface for sources based on the work for ffxiv * got more of ffxiv working and updated tests * Author and Description can be extracted and validated with tests * added uuid package * ffxiv core logic is working and testes updated to reflect it. * Updated the scheduler with the current sources and moved them from main * updated reddit to allow modern go to talk to the endpoint with a debug flag * gave the func a better name * cleaned up main * Moved cache to its own package and updated tests" * moved config to its own package and added basic tests * updated imports * minor update" * interface update and cache model update * updated the scheduler for basic services. No DB calls yet * updated db calls * bypassed the reddit test as its flaky in github
50 lines
862 B
Go
50 lines
862 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"log"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
const (
|
|
DB_URI string = "DB_URI"
|
|
|
|
REDDIT_PULL_TOP = "REDDIT_PULL_TOP"
|
|
REDDIT_PULL_HOT = "REDDIT_PULL_HOT"
|
|
REDDIT_PULL_NSFW = "REDDIT_PULL_NSFW"
|
|
|
|
YOUTUBE_DEBUG = "YOUTUBE_DEBUG"
|
|
)
|
|
|
|
type ConfigClient struct {}
|
|
|
|
func New() ConfigClient {
|
|
_, err := os.Open(".env")
|
|
if err == nil {
|
|
loadEnvFile()
|
|
}
|
|
|
|
return ConfigClient{}
|
|
}
|
|
|
|
func (cc *ConfigClient) GetConfig(key string) string {
|
|
res, filled := os.LookupEnv(key)
|
|
if !filled {
|
|
log.Printf("Missing the a value for '%v'. Could generate errors.", key)
|
|
}
|
|
return res
|
|
}
|
|
|
|
// Use this when your ConfigClient has been opened for awhile and you want to ensure you have the most recent env changes.
|
|
func (cc *ConfigClient) RefreshEnv() {
|
|
loadEnvFile()
|
|
}
|
|
|
|
func loadEnvFile() {
|
|
err := godotenv.Load()
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
}
|