2021-08-03 16:55:21 +07:00
|
|
|
package configuration
|
|
|
|
|
|
|
|
import (
|
2021-08-20 08:42:35 +07:00
|
|
|
_ "embed" // Embed config.template.yml.
|
2021-08-03 16:55:21 +07:00
|
|
|
"fmt"
|
|
|
|
"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) {
|
2022-06-28 10:15:50 +07:00
|
|
|
if err = os.WriteFile(path, template, 0600); err != nil {
|
2021-08-03 16:55:21 +07:00
|
|
|
return false, fmt.Errorf(errFmtGenerateConfiguration, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, fmt.Errorf(errFmtGenerateConfiguration, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, nil
|
|
|
|
}
|