mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			28 lines
		
	
	
		
			533 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			533 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package utils
 | 
						|
 | 
						|
import (
 | 
						|
	"errors"
 | 
						|
	"io/ioutil"
 | 
						|
 | 
						|
	"gopkg.in/yaml.v3"
 | 
						|
)
 | 
						|
 | 
						|
// 从指定路径加载yaml文件
 | 
						|
func LoadYml(path string, out interface{}) error {
 | 
						|
	yamlFileBytes, readErr := ioutil.ReadFile(path)
 | 
						|
	if readErr != nil {
 | 
						|
		return readErr
 | 
						|
	}
 | 
						|
	// yaml解析
 | 
						|
	err := yaml.Unmarshal(yamlFileBytes, out)
 | 
						|
	if err != nil {
 | 
						|
		return errors.New("无法解析 [" + path + "] -- " + err.Error())
 | 
						|
	}
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
func LoadYmlByString(yamlStr string, out interface{}) error {
 | 
						|
	// yaml解析
 | 
						|
	return yaml.Unmarshal([]byte(yamlStr), out)
 | 
						|
}
 |