fix goenv

This commit is contained in:
Andre Medeiros 2021-07-05 20:20:00 -04:00
parent 60a9e7deae
commit 7f30f279bc
2 changed files with 8 additions and 10 deletions

View file

@ -28,17 +28,16 @@ type application struct {
} }
func main() { func main() {
err := godotenv.Load() logger := log.New(os.Stdout, "", log.Ldate|log.Ltime)
if err != nil {
log.Fatal("Error loading .env file") if err := godotenv.Load(); err != nil {
logger.Printf("Couldn't find .env so I will read from existing ENV.")
} }
var cfg config var cfg config
flag.IntVar(&cfg.port, "port", 4000, "API server port") flag.IntVar(&cfg.port, "port", 4000, "API server port")
flag.Parse() flag.Parse()
logger := log.New(os.Stdout, "", log.Ldate|log.Ltime)
db, err := sql.Open("postgres", os.Getenv("DATABASE_URL")) db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View file

@ -116,13 +116,12 @@ func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, qu
} }
func main() { func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
logger := log.New(os.Stdout, "", log.Ldate|log.Ltime) logger := log.New(os.Stdout, "", log.Ldate|log.Ltime)
if err := godotenv.Load(); err != nil {
logger.Printf("Couldn't find .env so I will read from existing ENV.")
}
rc := reddit.NewClient(os.Getenv("REDDIT_CLIENT_ID"), os.Getenv("REDDIT_CLIENT_SECRET")) rc := reddit.NewClient(os.Getenv("REDDIT_CLIENT_ID"), os.Getenv("REDDIT_CLIENT_SECRET"))
db, err := sql.Open("postgres", os.Getenv("DATABASE_URL")) db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))