jlelse
/
hugo-micropub
Archived
1
Fork 0
This repository has been archived on 2020-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
hugo-micropub/config.go

117 lines
2.8 KiB
Go
Raw Normal View History

2019-11-07 10:00:24 +00:00
package main
import (
"errors"
2019-12-06 09:32:30 +00:00
"log"
2019-11-07 10:00:24 +00:00
"os"
2019-12-06 09:32:30 +00:00
"strings"
2019-11-07 10:00:24 +00:00
)
2019-12-06 09:32:30 +00:00
var (
BlogUrl string
GiteaEndpoint string
GiteaToken string
BunnyCdnKey string
2019-12-12 21:36:05 +00:00
MicroblogUrl string
MicroblogToken string
2019-12-06 09:32:30 +00:00
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
2019-12-12 21:36:05 +00:00
// Microblog (optional)
microblogUrl, err := microblogUrl()
if err != nil {
log.Println(err)
}
MicroblogUrl = microblogUrl
microblogToken, err := microblogToken()
if err != nil {
log.Println(err)
}
MicroblogToken = microblogToken
2019-12-06 09:32:30 +00:00
// Ignored Webmention URLs (optional)
ignoredWebmentionUrls, err := ignoredWebmentionUrls()
if err != nil {
log.Println(err)
}
IgnoredWebmentionUrls = ignoredWebmentionUrls
}
func giteaEndpoint() (string, error) {
2019-11-07 10:00:24 +00:00
giteaEndpoint := os.Getenv("GITEA_ENDPOINT")
if len(giteaEndpoint) == 0 || giteaEndpoint == "" {
return "", errors.New("GITEA_ENDPOINT not specified")
}
return giteaEndpoint, nil
}
2019-12-06 09:32:30 +00:00
func giteaToken() (string, error) {
2019-11-07 10:00:24 +00:00
giteaToken := os.Getenv("GITEA_TOKEN")
if len(giteaToken) == 0 || giteaToken == "" {
return "", errors.New("GITEA_TOKEN not specified")
}
return giteaToken, nil
}
2019-12-06 09:32:30 +00:00
func blogUrl() (string, error) {
2019-11-07 10:00:24 +00:00
blogURL := os.Getenv("BLOG_URL")
if len(blogURL) == 0 || blogURL == "" {
return "", errors.New("BLOG_URL not specified")
}
return blogURL, nil
}
2019-12-06 09:32:30 +00:00
func bunnyCdnKey() (string, error) {
bunnyCDNKey := os.Getenv("BUNNY_CDN_KEY")
if len(bunnyCDNKey) == 0 || bunnyCDNKey == "" {
2019-12-06 09:32:30 +00:00
return "", errors.New("BUNNY_CDN_KEY not specified, BunnyCDN features are deactivated")
}
return bunnyCDNKey, nil
}
2019-12-06 09:32:30 +00:00
2019-12-12 21:36:05 +00:00
func microblogUrl() (string, error) {
microblogUrl := os.Getenv("MICROBLOG_URL")
if len(microblogUrl) == 0 || microblogUrl == "" {
return "", errors.New("MICROBLOG_URL not specified, microblog.pub features are deactivated")
}
return microblogUrl, nil
}
func microblogToken() (string, error) {
microblogToken := os.Getenv("MICROBLOG_TOKEN")
if len(microblogToken) == 0 || microblogToken == "" {
return "", errors.New("MICROBLOG_TOKEN not specified, microblog.pub features are deactivated")
}
return microblogToken, nil
}
2019-12-06 09:32:30 +00:00
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
}