sk-matrix-project/backend/golang/matrix-dnslog-service/pkg/config/generate.go
2023-03-24 15:46:54 +08:00

33 lines
504 B
Go

package config
import (
"github.com/pelletier/go-toml/v2"
"os"
"path/filepath"
)
func GenerateConfig() error {
p, _ := filepath.Abs("./config.toml")
flag := os.O_RDWR
_, err := os.Stat(p)
exist := !os.IsNotExist(err)
if !exist {
f, err := os.OpenFile(p, flag|os.O_CREATE, 0644)
if err != nil {
return err
}
defer func() {
_ = f.Close()
}()
encoder := toml.NewEncoder(f)
encoder.SetIndentTables(true)
_ = encoder.Encode(DefaultConfig())
_ = f.Sync()
}
return nil
}