2020-01-29 20:08:03 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Init initializes a config file
|
|
|
|
func Init(confpath string, configs string) error {
|
|
|
|
|
|
|
|
// assert that the config directory exists
|
|
|
|
if err := os.MkdirAll(filepath.Dir(confpath), 0755); err != nil {
|
|
|
|
return fmt.Errorf("failed to create directory: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// write the config file
|
2022-08-05 02:38:49 +02:00
|
|
|
if err := os.WriteFile(confpath, []byte(configs), 0644); err != nil {
|
2020-01-29 20:08:03 +01:00
|
|
|
return fmt.Errorf("failed to create file: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|