You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.0 KiB
64 lines
2.0 KiB
3 years ago
|
package config
|
||
|
|
||
3 years ago
|
import (
|
||
|
"strings"
|
||
|
|
||
|
"github.com/sirupsen/logrus"
|
||
|
"github.com/spf13/pflag"
|
||
|
"github.com/spf13/viper"
|
||
|
)
|
||
|
|
||
3 years ago
|
// Backend contains backend connection-specific configuration
|
||
|
type Backend struct {
|
||
3 years ago
|
Addr string `mapstructure:"addr"`
|
||
|
Secured bool `mapstructure:"secured"`
|
||
|
Headers map[string]string `mapstructure:"headers"`
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
// Content contains content-specific configuration
|
||
|
type Content struct {
|
||
3 years ago
|
Backend Backend `mapstructure:"backend"`
|
||
|
Key string `mapstructure:"key"`
|
||
|
Pinned string `mapstructure:"pinned"`
|
||
|
PostsPerPage int `mapstructure:"postsPerPage"`
|
||
3 years ago
|
}
|
||
|
|
||
|
// Config contains application configuration
|
||
|
type Config struct {
|
||
|
Verbose string `mapstructure:"verbose"`
|
||
|
Base string `mapstructure:"base"`
|
||
|
Addr string `mapstructure:"addr"`
|
||
|
Unix string `mapstructure:"unix"`
|
||
|
Content Content `mapstructure:"content"`
|
||
|
}
|
||
3 years ago
|
|
||
|
// initialize default values on app-start
|
||
|
func init() {
|
||
|
|
||
|
pflag.BoolP("version", "V", false, "get application version")
|
||
|
pflag.BoolP("verbose", "v", false, "enable verbose logging")
|
||
|
pflag.StringP("config", "c", string("frontend.yaml"), "config file path")
|
||
|
|
||
|
pflag.String("addr", "127.0.0.1:8000", "tcp addr to listen")
|
||
|
pflag.String("unix", "", "unix socket path to listen")
|
||
|
pflag.String("base", "", "http URI prefix")
|
||
|
|
||
3 years ago
|
pflag.StringToString("content.backend.headers", nil, "map of additional headers to send")
|
||
3 years ago
|
pflag.String("content.backend.addr", "demo.ghost.io:443", "ghost backend addr")
|
||
|
pflag.Bool("content.backend.secured", true, "is ghost backend secured")
|
||
3 years ago
|
pflag.String("content.key", "22444f78447824223cefc48062", "ghost content api key")
|
||
|
pflag.String("content.pinned", "contact", "pinned page slug")
|
||
|
pflag.Int("content.postsPerPage", 5, "amount of posts per page")
|
||
|
|
||
|
pflag.Parse()
|
||
|
|
||
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||
|
viper.AutomaticEnv()
|
||
|
viper.BindPFlags(pflag.CommandLine)
|
||
|
|
||
|
if viper.GetBool("verbose") {
|
||
|
logrus.SetLevel(logrus.DebugLevel)
|
||
|
logrus.Debug("Verbose mode")
|
||
|
}
|
||
|
}
|