优化缓存机制 补充错误码
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package zm_lib
|
||||
|
||||
import (
|
||||
"complie-erlang/cache"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func PersistentFlagsStringVar(cmd *cobra.Command, varK *string, cache cache.Cache, globalKey string, defaultValue string, desc string) error {
|
||||
pluginKey := fmt.Sprintf("%s.%s", cmd.Use, globalKey)
|
||||
plugin, err := cache.GetDefault(pluginKey, defaultValue)
|
||||
cmd.PersistentFlags().StringVar(varK, globalKey, plugin.(string), fmt.Sprintf("%s (global.key:\"%s\")", desc, pluginKey))
|
||||
return err
|
||||
}
|
||||
@@ -67,6 +67,16 @@ func FindPathByBasePath(basefun func() (basePath string, err error), path string
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
path = filepath.Join(filepath.Dir(basePath), path)
|
||||
|
||||
info, err := os.Stat(basePath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !info.IsDir() {
|
||||
path = filepath.Join(filepath.Dir(basePath), path)
|
||||
} else {
|
||||
path = filepath.Join(basePath, path)
|
||||
}
|
||||
|
||||
return path, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user