newsbox/internal/config.go

87 lines
2 KiB
Go
Raw Normal View History

2023-02-15 16:56:06 +00:00
package internal
import (
2023-02-15 19:51:54 +00:00
"fmt"
"os"
2023-02-15 16:56:06 +00:00
"strconv"
"github.com/gobuffalo/envy"
)
2023-02-15 19:51:54 +00:00
// DatabaseURL returns the site's database URL
func DatabaseUrl() string {
dbURL, err := envy.MustGet("DATABASE_URL")
if err != nil {
fmt.Fprintf(os.Stderr, "unable to get DATABASE_URL")
}
return dbURL
}
2023-02-15 16:56:06 +00:00
// SiteName returns the name of the current site
func SiteName() string {
return envy.Get("SITE_NAME", "Newsbox")
}
// SiteProtocol returns the scheme (http/https) that the site should use when generating URLs
func SiteProtocol() string {
return envy.Get("SITE_PROTOCOL", "https")
}
// AnalyticsEnabled returns true if analytics are enabled for this site
func AnalyticsEnabled() bool {
val, err := strconv.ParseBool(envy.Get("ENABLE_ANALYTICS", "false"))
if err != nil {
return false
}
return val
}
// AnalyticsSelfHostingEnabled returns true if analytics are enabled for this site and the following enviornment
// variable is set: ENABLE_ANALYTICS_SELF_HOSTING
func AnalyticsSelfHostingEnabled() bool {
if !AnalyticsEnabled() {
return false
}
val, err := strconv.ParseBool(envy.Get("ENABLE_ANALYTICS_SELF_HOSTING", "false"))
if err != nil {
return false
}
return val
}
// PaymentsEnabled returns true if payments are enabled.
// Payments are enabled by setting the following environment variables: STRIPE_KEY, STRIPE_PRICE_ID
func PaymentsEnabled() bool {
val, err := envy.MustGet("STRIPE_KEY")
if err != nil || val == "" {
return false
}
val, err = envy.MustGet("STRIPE_PRICE_ID")
if err != nil || val == "" {
return false
}
return true
}
// GithubLoginEnabled() returns true if Github oauth logins are enabled
// Github oauth logins are enabled by setting the following environment variables: GH_OAUTH_CLIENT_ID, GH_OAUTH_CLIENT_SECRET
func GithubLoginEnabled() bool {
val, err := envy.MustGet("GH_OAUTH_CLIENT_ID")
if err != nil || val == "" {
return false
}
val, err = envy.MustGet("GH_OAUTH_CLIENT_SECRET")
if err != nil || val == "" {
return false
}
return true
}