engine/configure/configure.go

24 lines
506 B
Go

package configure
import (
"os"
"strings"
"github.com/zeromicro/go-zero/core/conf"
)
// Load loads config into v from file, .json, .yaml and .yml are acceptable.
func LoadYamlFile(file string, repl map[string]string, v any) error {
contentBytes, err := os.ReadFile(file)
if err != nil {
return err
}
contentString := string(contentBytes)
for k, v := range repl {
contentString = strings.ReplaceAll(contentString, "{"+k+"}", v)
}
return conf.LoadFromYamlBytes([]byte(contentString), v)
}