James Tombleson
75b66dd625
* Using sqlc to generate queries and goose for migrations. The intial tests look good. * moving the old calls away for now. Might use this in a package later on. * Added postgres driver * Updated the dockerfile to support sql migrations * added sqlc config file * updated schema and starting a seed script * updated models to use the database ones * updated reddit cron to talk to the db * added env for sql connection string * got the reddit source working with the db and posting articles * added sql packages * added rule to ignore dev sql file * added migration down statement for rolling back * updated cron for reddit and youtube * Updated reddit to follow a new standard pattern * updated youtube to follow new patterns * updated tests and brought them to the standard * updated the seed migration * all cron tasks should feed the db now * updated app init * bumped docker to 1.18.3 * disabled remote tests given secrets and lack of interfaces currently to run tests
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"log"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
const (
|
|
DB_URI string = "DB_URI"
|
|
|
|
Sql_Connection_String string = "SQL_CONNECTION_STRING"
|
|
|
|
REDDIT_PULL_TOP = "REDDIT_PULL_TOP"
|
|
REDDIT_PULL_HOT = "REDDIT_PULL_HOT"
|
|
REDDIT_PULL_NSFW = "REDDIT_PULL_NSFW"
|
|
|
|
YOUTUBE_DEBUG = "YOUTUBE_DEBUG"
|
|
|
|
TWITCH_CLIENT_ID = "TWITCH_CLIENT_ID"
|
|
TWITCH_CLIENT_SECRET = "TWITCH_CLIENT_SECRET"
|
|
TWITCH_MONITOR_CLIPS = "TWITCH_MONITOR_CLIPS"
|
|
TWITCH_MONITOR_VOD = "TWITCH_MONITOR_VOD"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|