implement auth middleware

This commit is contained in:
Jakob Schrettenbrunner
2017-07-06 20:49:36 +02:00
parent 260c9d70ab
commit 0bceb409e5
4 changed files with 233 additions and 7 deletions

View File

@@ -76,13 +76,16 @@ type Config struct {
// If set to <= 0 logs are kept forever
DeleteAfterDays int `mapstructure:"deleteAfterDays"`
} `mapstructure:"log"`
AuthKeys []string `mapstructure:"authKeys"`
}
var config *Config
func LoadConfiguration(path *string) error {
if path != nil {
viper.SetConfigFile(*path)
// LoadConfiguration loads the configuration from a specified file
func LoadConfiguration(path string) error {
if path != "" {
viper.SetConfigFile(path)
} else {
viper.AddConfigPath("./")
viper.SetConfigName("config")
@@ -109,3 +112,13 @@ func Get() *Config {
func setDefaults() {
}
// ContainsAuthKey checks wether the config contains a specified authentication key
func (c *Config) ContainsAuthKey(key string) bool {
for _, k := range c.AuthKeys {
if k == key {
return true
}
}
return false
}