newsbot-api/services/config.go
James Tombleson eba63c27ef
Youtube source is now working (#5)
* added extra packages to help with parsing

* getting the core built for Youtube collection.  The feed can be pulled and starting to build the article object

* added some tests, reddit will need more love but youtube is starting off with more tests.  Starting to add Rod to pull missing values from the site

* Added rod to work with browser automation

* Moved the config inside the client as they can change within runtime and need to be refreshed on each client creation

* added more features to collect data per video and tests to support them.

* adding the cache and tests

* moved errors to var values at the top

* youtube is now getting collected and tests have been setup

* resolved an issue with the config

* setting up the first interface, its not used yet

* more updates to the cache service. Not finished yet and could see rework

* added logic to monitor Youtube.  Still basic logic that needs to be wired up to the database
2022-04-17 07:25:49 -07:00

50 lines
876 B
Go

package services
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 NewConfigClient() 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)
}
}