Skip to content

Commit

Permalink
feat: add env variables support
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Dec 17, 2023
1 parent a19ea03 commit e234108
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
12 changes: 5 additions & 7 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ tokensSecret: SecureSecret
webhookSecret: GitHub
# The website language.
language: en
# The website title.
title: "The Website Title"
# Turn on TOR Onion service (with Onion-Location header).
tor: true

Expand All @@ -31,18 +29,18 @@ login:
# Encrypted password. Use 'eagle pwd' to generate the password.
password: invalidSecret

# Webmentions configuration.
webmentions:
# Webmention.io (https://webmention.io) secret for incoming webmentions.
secret: MySecret

# Enable support for comments. They are moderated through the same view as
# Webmentions, and stored in the same file. You need to add a form to your posts
# to submit a comment to the '/comments' endpoint.
comments:
# Must be set to enable. Page to which to redirect users after commenting.
redirect: /my-thank-you-page/

# Webmentions configuration.
webmentions:
# Webmention.io (https://webmention.io) secret for incoming webmentions.
secret: MySecret

# Optional Micropub configuration. Disabled otherwise.
micropub:
# Which of your Hugo taxonomy is Micropub channels. Disabled if not set.
Expand Down
17 changes: 11 additions & 6 deletions core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/url"
"path/filepath"
"strings"

"github.com/spf13/viper"
"go.hacdias.com/indielib/micropub"
Expand Down Expand Up @@ -48,18 +49,22 @@ type ServerConfig struct {
Comments Comments
Webmentions Webmentions
Micropub *Micropub
Plugins map[string]map[string]interface{}
MeiliSearch *MeiliSearch
Notifications Notifications
BunnyCDN *BunnyCDN
MeiliSearch *MeiliSearch
ImgProxy *ImgProxy
Plugins map[string]map[string]interface{}
}

func parseServerConfig() (*ServerConfig, error) {
v := viper.New()
v.SetConfigName("config")
v.AddConfigPath(".")

v.SetEnvPrefix("eagle")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()

err := v.ReadInConfig()
if err != nil {
return nil, err
Expand Down Expand Up @@ -154,14 +159,14 @@ func (u *Login) validate() error {
return nil
}

type Webmentions struct {
Secret string
}

type Comments struct {
Redirect string
}

type Webmentions struct {
Secret string
}

type Micropub struct {
ChannelsTaxonomy string
CategoriesTaxonomy string
Expand Down

0 comments on commit e234108

Please sign in to comment.