ing
This commit is contained in:
parent
71ce7f35b5
commit
4fa607e239
12
config.go
12
config.go
|
@ -41,7 +41,7 @@ func init() {
|
||||||
func SetConfigPath(in string) error { return _c.SetConfigPath(in) }
|
func SetConfigPath(in string) error { return _c.SetConfigPath(in) }
|
||||||
func (c *config) SetConfigPath(in string) error {
|
func (c *config) SetConfigPath(in string) error {
|
||||||
if in != "" {
|
if in != "" {
|
||||||
absin, err := absPathify(in)
|
absin, err := ABSPathify(in)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ func Save(target interface{}, file string, overWrite bool) error {
|
||||||
func (c *config) Save(target interface{}, file string, overWrite bool) error {
|
func (c *config) Save(target interface{}, file string, overWrite bool) error {
|
||||||
var absPath string
|
var absPath string
|
||||||
var err error
|
var err error
|
||||||
if absPath, err = absPathify(file); nil != err {
|
if absPath, err = ABSPathify(file); nil != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,8 +107,8 @@ func (c *config) getConfigFiles(files ...string) []string {
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
// check configuration
|
// check configuration
|
||||||
if absin, err := absPathify(file); nil == err {
|
if absin, err := ABSPathify(file); nil == err {
|
||||||
if exists(absin) {
|
if Exists(absin) {
|
||||||
results = append(results, absin)
|
results = append(results, absin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,8 +116,8 @@ func (c *config) getConfigFiles(files ...string) []string {
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
// check configuration
|
// check configuration
|
||||||
if absin, err := absPathify(filepath.Join(c.configPath, file)); nil == err {
|
if absin, err := ABSPathify(filepath.Join(c.configPath, file)); nil == err {
|
||||||
if exists(absin) {
|
if Exists(absin) {
|
||||||
results = append(results, absin)
|
results = append(results, absin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
util.go
6
util.go
|
@ -16,7 +16,7 @@ import (
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func absPathify(inPath string) (string, error) {
|
func ABSPathify(inPath string) (string, error) {
|
||||||
if strings.HasPrefix(inPath, "$HOME") {
|
if strings.HasPrefix(inPath, "$HOME") {
|
||||||
inPath = userHomeDir() + inPath[5:]
|
inPath = userHomeDir() + inPath[5:]
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ func userHomeDir() string {
|
||||||
return os.Getenv("HOME")
|
return os.Getenv("HOME")
|
||||||
}
|
}
|
||||||
|
|
||||||
func exists(path string) bool {
|
func Exists(path string) bool {
|
||||||
if fileInfo, err := os.Stat(path); err == nil && fileInfo.Mode().IsRegular() {
|
if fileInfo, err := os.Stat(path); err == nil && fileInfo.Mode().IsRegular() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ func getPrefixForStruct(prefixes []string, fieldStruct *reflect.StructField) []s
|
||||||
func marshalFile(target interface{}, file string, overWrite bool) error {
|
func marshalFile(target interface{}, file string, overWrite bool) error {
|
||||||
var f *os.File
|
var f *os.File
|
||||||
var err error
|
var err error
|
||||||
if exists(file) {
|
if Exists(file) {
|
||||||
if !overWrite {
|
if !overWrite {
|
||||||
return fmt.Errorf("Config: File[%s] is exist", file)
|
return fmt.Errorf("Config: File[%s] is exist", file)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user