2020-07-28 19:17:07 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type config struct {
|
2020-08-04 17:42:09 +00:00
|
|
|
Server *configServer `mapstructure:"server"`
|
|
|
|
Db *configDb `mapstructure:"database"`
|
|
|
|
Cache *configCache `mapstructure:"cache"`
|
|
|
|
Blog *configBlog `mapstructure:"blog"`
|
|
|
|
User *configUser `mapstructure:"user"`
|
2020-09-20 16:46:25 +00:00
|
|
|
Hooks *configHooks `mapstructure:"hooks"`
|
2020-09-18 10:34:52 +00:00
|
|
|
Hugo *configHugo `mapstructure:"hugo"`
|
2020-07-28 19:17:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type configServer struct {
|
2020-08-04 17:42:09 +00:00
|
|
|
Logging bool `mapstructure:"logging"`
|
|
|
|
Port int `mapstructure:"port"`
|
|
|
|
Domain string `mapstructure:"domain"`
|
2020-09-15 15:01:53 +00:00
|
|
|
PublicAddress string `mapstructure:"publicAddress"`
|
2020-08-04 17:42:09 +00:00
|
|
|
PublicHttps bool `mapstructure:"publicHttps"`
|
|
|
|
LetsEncryptMail string `mapstructure:"letsEncryptMail"`
|
|
|
|
LocalHttps bool `mapstructure:"localHttps"`
|
2020-07-28 19:17:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type configDb struct {
|
2020-08-04 17:42:09 +00:00
|
|
|
File string `mapstructure:"file"`
|
2020-07-28 19:17:07 +00:00
|
|
|
}
|
|
|
|
|
2020-07-29 20:45:26 +00:00
|
|
|
type configCache struct {
|
2020-08-04 17:42:09 +00:00
|
|
|
Enable bool `mapstructure:"enable"`
|
|
|
|
Expiration int64 `mapstructure:"expiration"`
|
2020-07-29 20:45:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-31 13:48:01 +00:00
|
|
|
// exposed to templates via function "blog"
|
|
|
|
type configBlog struct {
|
|
|
|
// Language of the blog, e.g. "en" or "de"
|
2020-08-04 17:42:09 +00:00
|
|
|
Lang string `mapstructure:"lang"`
|
2020-07-31 13:48:01 +00:00
|
|
|
// Title of the blog, e.g. "My blog"
|
2020-08-04 17:42:09 +00:00
|
|
|
Title string `mapstructure:"title"`
|
2020-09-01 16:14:49 +00:00
|
|
|
// Description of the blog
|
|
|
|
Description string `mapstructure:"description"`
|
2020-08-05 17:54:04 +00:00
|
|
|
// Number of posts per page
|
|
|
|
Pagination int `mapstructure:"pagination"`
|
2020-08-25 18:55:32 +00:00
|
|
|
// Sections
|
2020-09-01 16:14:49 +00:00
|
|
|
Sections []*section `mapstructure:"sections"`
|
2020-08-31 19:12:43 +00:00
|
|
|
// Taxonomies
|
2020-09-01 16:14:49 +00:00
|
|
|
Taxonomies []*taxonomy `mapstructure:"taxonomies"`
|
2020-09-19 11:37:58 +00:00
|
|
|
// Menus
|
2020-09-20 15:28:24 +00:00
|
|
|
Menus map[string]*menu `mapstructure:"menus"`
|
2020-09-21 16:03:05 +00:00
|
|
|
// Photos
|
|
|
|
Photos *photos `mapstructure:"photos"`
|
2020-09-24 15:13:03 +00:00
|
|
|
// ActivityStreams
|
|
|
|
ActivityStreams *activityStreams `mapstructure:"activitystreams"`
|
2020-09-01 16:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type section struct {
|
|
|
|
Name string `mapstructure:"name"`
|
|
|
|
Title string `mapstructure:"title"`
|
|
|
|
Description string `mapstructure:"description"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type taxonomy struct {
|
|
|
|
Name string `mapstructure:"name"`
|
|
|
|
Title string `mapstructure:"title"`
|
|
|
|
Description string `mapstructure:"description"`
|
2020-07-31 13:48:01 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 11:37:58 +00:00
|
|
|
type menu struct {
|
|
|
|
Items []*menuItem `mapstructure:"items"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type menuItem struct {
|
|
|
|
Title string `mapstructure:"title"`
|
|
|
|
Link string `mapstructure:"link"`
|
|
|
|
}
|
|
|
|
|
2020-09-21 16:03:05 +00:00
|
|
|
type photos struct {
|
|
|
|
Enabled bool `mapstructure:"enabled"`
|
|
|
|
Parameter string `mapstructure:"parameter"`
|
|
|
|
Path string `mapstructure:"path"`
|
|
|
|
Title string `mapstructure:"title"`
|
|
|
|
Description string `mapstructure:"description"`
|
|
|
|
}
|
|
|
|
|
2020-09-24 15:13:03 +00:00
|
|
|
type activityStreams struct {
|
|
|
|
Enabled bool `mapstructure:"enabled"`
|
|
|
|
ReplyParameter string `mapstructure:"replyParameter"`
|
|
|
|
ImagesParameter string `mapstructure:"imagesParameter"`
|
|
|
|
}
|
|
|
|
|
2020-08-01 13:16:21 +00:00
|
|
|
type configUser struct {
|
2020-08-04 17:42:09 +00:00
|
|
|
Nick string `mapstructure:"nick"`
|
|
|
|
Name string `mapstructure:"name"`
|
|
|
|
Password string `mapstructure:"password"`
|
2020-08-01 13:16:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-20 16:46:25 +00:00
|
|
|
type configHooks struct {
|
|
|
|
Shell string `mapstructure:"shell"`
|
|
|
|
PreStart []string `mapstructure:"prestart"`
|
|
|
|
}
|
|
|
|
|
2020-09-18 10:34:52 +00:00
|
|
|
type configHugo struct {
|
|
|
|
Frontmatter []*frontmatter `mapstructure:"frontmatter"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type frontmatter struct {
|
|
|
|
Meta string `mapstructure:"meta"`
|
|
|
|
Parameter string `mapstructure:"parameter"`
|
|
|
|
}
|
|
|
|
|
2020-08-04 17:42:09 +00:00
|
|
|
var appConfig = &config{}
|
2020-07-28 19:17:07 +00:00
|
|
|
|
|
|
|
func initConfig() error {
|
|
|
|
viper.SetConfigName("config")
|
|
|
|
viper.AddConfigPath("./config/")
|
|
|
|
err := viper.ReadInConfig()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-04 17:42:09 +00:00
|
|
|
// Defaults
|
|
|
|
viper.SetDefault("server.logging", false)
|
|
|
|
viper.SetDefault("server.port", 8080)
|
|
|
|
viper.SetDefault("server.domain", "example.com")
|
2020-09-15 15:01:53 +00:00
|
|
|
viper.SetDefault("server.publicAddress", "http://localhost:8080")
|
2020-08-04 17:42:09 +00:00
|
|
|
viper.SetDefault("server.publicHttps", false)
|
|
|
|
viper.SetDefault("server.letsEncryptMail", "mail@example.com")
|
|
|
|
viper.SetDefault("server.localHttps", false)
|
|
|
|
viper.SetDefault("database.file", "data/db.sqlite")
|
|
|
|
viper.SetDefault("cache.enable", true)
|
|
|
|
viper.SetDefault("cache.expiration", 600)
|
|
|
|
viper.SetDefault("blog.lang", "en")
|
|
|
|
viper.SetDefault("blog.title", "My blog")
|
2020-09-01 16:14:49 +00:00
|
|
|
viper.SetDefault("blog.description", "This is my blog")
|
2020-08-05 17:54:04 +00:00
|
|
|
viper.SetDefault("blog.pagination", 10)
|
2020-09-01 16:14:49 +00:00
|
|
|
viper.SetDefault("blog.sections", []*section{{Name: "posts", Title: "Posts", Description: "**Posts** on this blog"}})
|
|
|
|
viper.SetDefault("blog.taxonomies", []*taxonomy{{Name: "tags", Title: "Tags", Description: "**Tags** on this blog"}})
|
2020-09-20 15:28:24 +00:00
|
|
|
viper.SetDefault("blog.menus", map[string]*menu{"main": {Items: []*menuItem{{Title: "Home", Link: "/"}, {Title: "Post", Link: "Posts"}}}})
|
2020-09-21 16:03:05 +00:00
|
|
|
viper.SetDefault("blog.photos.enabled", true)
|
|
|
|
viper.SetDefault("blog.photos.parameter", "images")
|
|
|
|
viper.SetDefault("blog.photos.path", "/photos")
|
|
|
|
viper.SetDefault("blog.photos.title", "Photos")
|
|
|
|
viper.SetDefault("blog.photos.description", "Photos on this blog")
|
2020-09-24 15:13:03 +00:00
|
|
|
viper.SetDefault("blog.activitystreams.enabled", false)
|
|
|
|
viper.SetDefault("blog.activitystreams.replyParameter", "replylink")
|
|
|
|
viper.SetDefault("blog.activitystreams.imagesParameter", "images")
|
2020-08-04 17:42:09 +00:00
|
|
|
viper.SetDefault("user.nick", "admin")
|
|
|
|
viper.SetDefault("user.name", "Admin")
|
|
|
|
viper.SetDefault("user.password", "secret")
|
2020-09-20 16:46:25 +00:00
|
|
|
viper.SetDefault("hooks.shell", "/bin/bash")
|
2020-09-18 10:34:52 +00:00
|
|
|
viper.SetDefault("hugo.frontmatter", []*frontmatter{{Meta: "title", Parameter: "title"}, {Meta: "tags", Parameter: "tags"}})
|
2020-08-04 17:42:09 +00:00
|
|
|
// Unmarshal config
|
|
|
|
err = viper.Unmarshal(appConfig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-07-28 19:17:07 +00:00
|
|
|
return nil
|
|
|
|
}
|