engine/configure/configure.go

24 lines
506 B
Go
Raw Normal View History

2024-02-11 01:31:01 +08:00
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)
}