Skip to content

Instantly share code, notes, and snippets.

@shrmpy
Created November 19, 2021 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrmpy/68d1d82b21016843267e7acfdb748f5e to your computer and use it in GitHub Desktop.
Save shrmpy/68d1d82b21016843267e7acfdb748f5e to your computer and use it in GitHub Desktop.
package configuration to abstract environment variables and support the CORS tests
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