mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
a7e867a699
This commit replaces github.com/spf13/viper with github.com/knadh/koanf. Koanf is very similar library to viper, with less dependencies and several quality of life differences. This also allows most config options to be defined by ENV. Lastly it also enables the use of split configuration files which can be configured by setting the --config flag multiple times. Co-authored-by: Amir Zarrinkafsh <nightah@me.com>
32 lines
680 B
Go
32 lines
680 B
Go
package configuration
|
|
|
|
import (
|
|
_ "embed"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
//go:embed config.template.yml
|
|
var template []byte
|
|
|
|
// EnsureConfigurationExists is an auxiliary function to the main Configuration tools that ensures the Configuration
|
|
// template is created if it doesn't already exist.
|
|
func EnsureConfigurationExists(path string) (created bool, err error) {
|
|
_, err = os.Stat(path)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
err := ioutil.WriteFile(path, template, 0600)
|
|
if err != nil {
|
|
return false, fmt.Errorf(errFmtGenerateConfiguration, err)
|
|
}
|
|
|
|
return true, nil
|
|
}
|
|
|
|
return false, fmt.Errorf(errFmtGenerateConfiguration, err)
|
|
}
|
|
|
|
return false, nil
|
|
}
|