Created
January 21, 2021 17:41
-
-
Save qweliant/f0f22f22bbc436fa392aa8f7b9550149 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ( | |
// 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") | |
) | |
var environments = map[string]plaid.Environment{ | |
"sandbox": plaid.Sandbox, | |
"development": plaid.Development, | |
"production": plaid.Production, | |
} | |
func init() { | |
// 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") | |
} | |
} | |
var client = func() *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)) | |
} | |
return client | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment