hugo-micropub/config.go

88 lines
2.0 KiB
Go

package main
import (
"errors"
"log"
"os"
"strings"
)
var (
BlogUrl string
GiteaEndpoint string
GiteaToken string
BunnyCdnKey string
IgnoredWebmentionUrls []string
)
func init() {
// Blog URL (required)
blogUrl, err := blogUrl()
if err != nil {
log.Fatal(err)
}
BlogUrl = blogUrl
// Gitea (required)
giteaEndpoint, err := giteaEndpoint()
if err != nil {
log.Fatal(err)
}
GiteaEndpoint = giteaEndpoint
giteaToken, err := giteaToken()
if err != nil {
log.Fatal(err)
}
GiteaToken = giteaToken
// BunnyCDN (optional)
bunnyCdnKey, err := bunnyCdnKey()
if err != nil {
log.Println(err)
}
BunnyCdnKey = bunnyCdnKey
// Ignored Webmention URLs (optional)
ignoredWebmentionUrls, err := ignoredWebmentionUrls()
if err != nil {
log.Println(err)
}
IgnoredWebmentionUrls = ignoredWebmentionUrls
}
func giteaEndpoint() (string, error) {
giteaEndpoint := os.Getenv("GITEA_ENDPOINT")
if len(giteaEndpoint) == 0 || giteaEndpoint == "" {
return "", errors.New("GITEA_ENDPOINT not specified")
}
return giteaEndpoint, nil
}
func giteaToken() (string, error) {
giteaToken := os.Getenv("GITEA_TOKEN")
if len(giteaToken) == 0 || giteaToken == "" {
return "", errors.New("GITEA_TOKEN not specified")
}
return giteaToken, nil
}
func blogUrl() (string, error) {
blogURL := os.Getenv("BLOG_URL")
if len(blogURL) == 0 || blogURL == "" {
return "", errors.New("BLOG_URL not specified")
}
return blogURL, nil
}
func bunnyCdnKey() (string, error) {
bunnyCDNKey := os.Getenv("BUNNY_CDN_KEY")
if len(bunnyCDNKey) == 0 || bunnyCDNKey == "" {
return "", errors.New("BUNNY_CDN_KEY not specified, BunnyCDN features are deactivated")
}
return bunnyCDNKey, nil
}
func ignoredWebmentionUrls() ([]string, error) {
webmentionIgnored := os.Getenv("WEBMENTION_IGNORED")
if len(webmentionIgnored) == 0 {
return nil, errors.New("WEBMENTION_IGNORED not set, no URLs are ignored on Webmention sending")
}
return strings.Split(webmentionIgnored, ","), nil
}