Created
November 19, 2021 06:09
-
-
Save shrmpy/68d1d82b21016843267e7acfdb748f5e to your computer and use it in GitHub Desktop.
package configuration to abstract environment variables and support the CORS tests
This file contains 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
package ebs | |
import ( | |
"fmt" | |
"os" | |
) | |
// configuration | |
// to make environment variables available to testing | |
const EXTENSION_ID = "EXTENSION_ID" | |
type Config struct { | |
extensionId string | |
} | |
func NewConfig() *Config { | |
return &Config{} | |
} | |
func (c *Config) ExtensionId(id string) { | |
c.extensionId = id | |
} | |
func (c *Config) Hostname() string { | |
// format the hostname for the CORS allow-origin | |
// 1. For Netlify, EXTENSION_ID environment variable should be defined | |
// 2. Locally for testing, rely on configuration field | |
if c.extensionId != "" { | |
return fmt.Sprintf("https://%s.ext-twitch.tv", c.extensionId) | |
} | |
cid := os.Getenv(EXTENSION_ID) | |
if cid != "" { | |
c.extensionId = cid | |
return fmt.Sprintf("https://%s.ext-twitch.tv", c.extensionId) | |
} | |
return "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment