Skip to content

Instantly share code, notes, and snippets.

@qweliant
Created January 21, 2021 17:39
Show Gist options
  • Select an option

  • Save qweliant/74b9e1dc3388a44f82ea77a4b00d949d to your computer and use it in GitHub Desktop.

Select an option

Save qweliant/74b9e1dc3388a44f82ea77a4b00d949d to your computer and use it in GitHub Desktop.
var (
PLAID_CLIENT_ID = ""
PLAID_SECRET = ""
PLAID_ENV = ""
PLAID_PRODUCTS = ""
PLAID_COUNTRY_CODES = ""
PLAID_REDIRECT_URI = ""
APP_PORT = ""
client *plaid.Client = nil
)
var environments = map[string]plaid.Environment{
"sandbox": plaid.Sandbox,
"development": plaid.Development,
"production": plaid.Production,
}
func init() {
// load env vars from .env file
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file. Did you copy .env.example to .env and fill it out?")
}
// set constants from env
PLAID_CLIENT_ID = os.Getenv("PLAID_CLIENT_ID")
PLAID_SECRET = os.Getenv("PLAID_SECRET")
PLAID_ENV = os.Getenv("PLAID_ENV")
PLAID_PRODUCTS = os.Getenv("PLAID_PRODUCTS")
PLAID_COUNTRY_CODES = os.Getenv("PLAID_COUNTRY_CODES")
PLAID_REDIRECT_URI = os.Getenv("PLAID_REDIRECT_URI")
APP_PORT = os.Getenv("APP_PORT")
// set defaults
if PLAID_PRODUCTS == "" {
PLAID_PRODUCTS = "transactions"
}
if PLAID_COUNTRY_CODES == "" {
PLAID_COUNTRY_CODES = "US"
}
if PLAID_ENV == "" {
PLAID_ENV = "sandbox"
}
if APP_PORT == "" {
APP_PORT = "8000"
}
if PLAID_CLIENT_ID == "" {
log.Fatal("PLAID_CLIENT_ID is not set. Make sure to fill out the .env file")
}
if PLAID_SECRET == "" {
log.Fatal("PLAID_SECRET is not set. Make sure to fill out the .env file")
}
// create Plaid client
client, err = plaid.NewClient(plaid.ClientOptions{
PLAID_CLIENT_ID,
PLAID_SECRET,
environments[PLAID_ENV],
&http.Client{},
})
if err != nil {
panic(fmt.Errorf("unexpected error while initializing plaid client %w", err))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment