mirror of
https://gitee.com/johng/gf.git
synced 2024-12-03 04:37:49 +08:00
add default value for gcfg.Get* functions; rename gconv.TimeDuration to gconv.Duration, and do corresponding changes to caller packages
This commit is contained in:
parent
fdfefbb94d
commit
718997327a
@ -80,7 +80,7 @@ func (v *Var) Time(format...string) time.Time {
|
|||||||
// TimeDuration converts and returns <v> as time.Duration.
|
// TimeDuration converts and returns <v> as time.Duration.
|
||||||
// If value of <v> is string, then it uses time.ParseDuration for conversion.
|
// If value of <v> is string, then it uses time.ParseDuration for conversion.
|
||||||
func (v *Var) TimeDuration() time.Duration {
|
func (v *Var) TimeDuration() time.Duration {
|
||||||
return gconv.TimeDuration(v.Val())
|
return gconv.Duration(v.Val())
|
||||||
}
|
}
|
||||||
|
|
||||||
// GTime converts and returns <v> as *gtime.Time.
|
// GTime converts and returns <v> as *gtime.Time.
|
||||||
|
@ -178,8 +178,8 @@ func (j *Json) GetTime(pattern string, format... string) time.Time {
|
|||||||
return gconv.Time(j.Get(pattern), format...)
|
return gconv.Time(j.Get(pattern), format...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Json) GetTimeDuration(pattern string, def...interface{}) time.Duration {
|
func (j *Json) GetDuration(pattern string, def...interface{}) time.Duration {
|
||||||
return gconv.TimeDuration(j.Get(pattern, def...))
|
return gconv.Duration(j.Get(pattern, def...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Json) GetGTime(pattern string, format... string) *gtime.Time {
|
func (j *Json) GetGTime(pattern string, format... string) *gtime.Time {
|
||||||
|
@ -130,8 +130,8 @@ func (p *Parser) GetTime(pattern string, format...string) time.Time {
|
|||||||
return p.json.GetTime(pattern, format...)
|
return p.json.GetTime(pattern, format...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) GetTimeDuration(pattern string, def...interface{}) time.Duration {
|
func (p *Parser) GetDuration(pattern string, def...interface{}) time.Duration {
|
||||||
return p.json.GetTimeDuration(pattern, def...)
|
return p.json.GetDuration(pattern, def...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) GetGTime(pattern string, format...string) *gtime.Time {
|
func (p *Parser) GetGTime(pattern string, format...string) *gtime.Time {
|
||||||
|
@ -201,10 +201,10 @@ func Redis(name...string) *gredis.Redis {
|
|||||||
redisConfig.MaxActive = gconv.Int(v)
|
redisConfig.MaxActive = gconv.Int(v)
|
||||||
}
|
}
|
||||||
if v, ok := parse["idleTimeout"]; ok {
|
if v, ok := parse["idleTimeout"]; ok {
|
||||||
redisConfig.IdleTimeout = gconv.TimeDuration(v)*time.Second
|
redisConfig.IdleTimeout = gconv.Duration(v)*time.Second
|
||||||
}
|
}
|
||||||
if v, ok := parse["maxConnLifetime"]; ok {
|
if v, ok := parse["maxConnLifetime"]; ok {
|
||||||
redisConfig.MaxConnLifetime = gconv.TimeDuration(v)*time.Second
|
redisConfig.MaxConnLifetime = gconv.Duration(v)*time.Second
|
||||||
}
|
}
|
||||||
addConfigMonitor(key, config)
|
addConfigMonitor(key, config)
|
||||||
return gredis.New(redisConfig)
|
return gredis.New(redisConfig)
|
||||||
@ -225,7 +225,7 @@ func Redis(name...string) *gredis.Redis {
|
|||||||
glog.Errorfln(`configuration for redis not found for group "%s"`, group)
|
glog.Errorfln(`configuration for redis not found for group "%s"`, group)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
glog.Errorfln(`incomplete configuration for redis: "redis" node not found in config file "%s"`, config.GetFilePath())
|
glog.Errorfln(`incomplete configuration for redis: "redis" node not found in config file "%s"`, config.FilePath())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -238,7 +238,7 @@ func Redis(name...string) *gredis.Redis {
|
|||||||
// 添加对单例对象的配置文件inotify监控
|
// 添加对单例对象的配置文件inotify监控
|
||||||
func addConfigMonitor(key string, config *gcfg.Config) {
|
func addConfigMonitor(key string, config *gcfg.Config) {
|
||||||
// 使用gfsnotify进行文件监控,当配置文件有任何变化时,清空对象单例缓存
|
// 使用gfsnotify进行文件监控,当配置文件有任何变化时,清空对象单例缓存
|
||||||
if path := config.GetFilePath(); path != "" {
|
if path := config.FilePath(); path != "" {
|
||||||
gfsnotify.Add(path, func(event *gfsnotify.Event) {
|
gfsnotify.Add(path, func(event *gfsnotify.Event) {
|
||||||
instances.Remove(key)
|
instances.Remove(key)
|
||||||
})
|
})
|
||||||
@ -246,7 +246,7 @@ func addConfigMonitor(key string, config *gcfg.Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 模板内置方法:config
|
// 模板内置方法:config
|
||||||
func funcConfig(pattern string, file...string) string {
|
func funcConfig(pattern string, file...interface{}) string {
|
||||||
return Config().GetString(pattern, file...)
|
return Config().GetString(pattern, file...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,8 +224,8 @@ func (s *Session) GetGTime(key string, format...string) *gtime.Time {
|
|||||||
return gconv.GTime(s.Get(key), format...)
|
return gconv.GTime(s.Get(key), format...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) GetTimeDuration(key string, def...interface{}) time.Duration {
|
func (s *Session) GetDuration(key string, def...interface{}) time.Duration {
|
||||||
return gconv.TimeDuration(s.Get(key, def...))
|
return gconv.Duration(s.Get(key, def...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将变量转换为对象,注意 pointer 参数必须为struct指针
|
// 将变量转换为对象,注意 pointer 参数必须为struct指针
|
||||||
|
@ -21,6 +21,8 @@ import (
|
|||||||
"github.com/gogf/gf/g/os/gfsnotify"
|
"github.com/gogf/gf/g/os/gfsnotify"
|
||||||
"github.com/gogf/gf/g/os/glog"
|
"github.com/gogf/gf/g/os/glog"
|
||||||
"github.com/gogf/gf/g/os/gspath"
|
"github.com/gogf/gf/g/os/gspath"
|
||||||
|
"github.com/gogf/gf/g/os/gtime"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -39,7 +41,7 @@ type Config struct {
|
|||||||
|
|
||||||
// New returns a new configuration management object.
|
// New returns a new configuration management object.
|
||||||
// The param <file> specifies the default configuration file name for reading.
|
// The param <file> specifies the default configuration file name for reading.
|
||||||
func New(file ...string) *Config {
|
func New(file...string) *Config {
|
||||||
name := DEFAULT_CONFIG_FILE
|
name := DEFAULT_CONFIG_FILE
|
||||||
if len(file) > 0 {
|
if len(file) > 0 {
|
||||||
name = file[0]
|
name = file[0]
|
||||||
@ -78,7 +80,7 @@ func (c *Config) filePath(file...string) (path string) {
|
|||||||
if len(file) > 0 {
|
if len(file) > 0 {
|
||||||
name = file[0]
|
name = file[0]
|
||||||
}
|
}
|
||||||
path = c.GetFilePath(name)
|
path = c.FilePath(name)
|
||||||
if path == "" {
|
if path == "" {
|
||||||
buffer := bytes.NewBuffer(nil)
|
buffer := bytes.NewBuffer(nil)
|
||||||
if c.paths.Len() > 0 {
|
if c.paths.Len() > 0 {
|
||||||
@ -101,7 +103,8 @@ func (c *Config) filePath(file...string) (path string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetPath sets the configuration directory path for file search.
|
// SetPath sets the configuration directory path for file search.
|
||||||
// The param <path> can be absolute or relative path, but absolute path is suggested.
|
// The param <path> can be absolute or relative path,
|
||||||
|
// but absolute path is strongly recommended.
|
||||||
func (c *Config) SetPath(path string) error {
|
func (c *Config) SetPath(path string) error {
|
||||||
// Absolute path.
|
// Absolute path.
|
||||||
realPath := gfile.RealPath(path)
|
realPath := gfile.RealPath(path)
|
||||||
@ -149,7 +152,7 @@ func (c *Config) SetPath(path string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetViolenceCheck sets whether to perform level conflict check.
|
// SetViolenceCheck sets whether to perform hierarchical conflict check.
|
||||||
// This feature needs to be enabled when there is a level symbol in the key name.
|
// This feature needs to be enabled when there is a level symbol in the key name.
|
||||||
// The default is off.
|
// The default is off.
|
||||||
// Turning on this feature is quite expensive,
|
// Turning on this feature is quite expensive,
|
||||||
@ -205,11 +208,17 @@ func (c *Config) AddPath(path string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated.
|
||||||
|
// Alias of FilePath.
|
||||||
|
func (c *Config) GetFilePath(file...string) (path string) {
|
||||||
|
return c.FilePath(file...)
|
||||||
|
}
|
||||||
|
|
||||||
// GetFilePath returns the absolute path of the specified configuration file.
|
// GetFilePath returns the absolute path of the specified configuration file.
|
||||||
// If <file> is not passed, it returns the configuration file path of the default name.
|
// If <file> is not passed, it returns the configuration file path of the default name.
|
||||||
// If the specified configuration file does not exist,
|
// If the specified configuration file does not exist,
|
||||||
// an empty string is returned.
|
// an empty string is returned.
|
||||||
func (c *Config) GetFilePath(file...string) (path string) {
|
func (c *Config) FilePath(file...string) (path string) {
|
||||||
name := c.name.Val()
|
name := c.name.Val()
|
||||||
if len(file) > 0 {
|
if len(file) > 0 {
|
||||||
name = file[0]
|
name = file[0]
|
||||||
@ -280,171 +289,192 @@ func (c *Config) getJson(file...string) *gjson.Json {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Get(pattern string, file...string) interface{} {
|
func (c *Config) Get(pattern string, def...interface{}) interface{} {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.Get(pattern)
|
return j.Get(pattern, def...)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetVar(pattern string, file...string) gvar.VarRead {
|
func (c *Config) GetVar(pattern string, def...interface{}) gvar.VarRead {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return gvar.New(j.Get(pattern), true)
|
return gvar.New(j.Get(pattern, def...), true)
|
||||||
}
|
}
|
||||||
return gvar.New(nil, true)
|
return gvar.New(nil, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Contains(pattern string, file...string) bool {
|
func (c *Config) Contains(pattern string) bool {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.Contains(pattern)
|
return j.Contains(pattern)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetMap(pattern string, file...string) map[string]interface{} {
|
func (c *Config) GetMap(pattern string, def...interface{}) map[string]interface{} {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetMap(pattern)
|
return j.GetMap(pattern, def...)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetArray(pattern string, file...string) []interface{} {
|
func (c *Config) GetArray(pattern string, def...interface{}) []interface{} {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetArray(pattern)
|
return j.GetArray(pattern, def...)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetString(pattern string, file...string) string {
|
func (c *Config) GetString(pattern string, def...interface{}) string {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetString(pattern)
|
return j.GetString(pattern, def...)
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetStrings(pattern string, file...string) []string {
|
func (c *Config) GetStrings(pattern string, def...interface{}) []string {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetStrings(pattern)
|
return j.GetStrings(pattern, def...)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetInterfaces(pattern string, file...string) []interface{} {
|
func (c *Config) GetInterfaces(pattern string, def...interface{}) []interface{} {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetInterfaces(pattern)
|
return j.GetInterfaces(pattern, def...)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetBool(pattern string, file...string) bool {
|
func (c *Config) GetBool(pattern string, def...interface{}) bool {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetBool(pattern)
|
return j.GetBool(pattern, def...)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetFloat32(pattern string, file...string) float32 {
|
func (c *Config) GetFloat32(pattern string, def...interface{}) float32 {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetFloat32(pattern)
|
return j.GetFloat32(pattern, def...)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetFloat64(pattern string, file...string) float64 {
|
func (c *Config) GetFloat64(pattern string, def...interface{}) float64 {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetFloat64(pattern)
|
return j.GetFloat64(pattern, def...)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetFloats(pattern string, file...string) []float64 {
|
func (c *Config) GetFloats(pattern string, def...interface{}) []float64 {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetFloats(pattern)
|
return j.GetFloats(pattern, def...)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetInt(pattern string, file...string) int {
|
func (c *Config) GetInt(pattern string, def...interface{}) int {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetInt(pattern)
|
return j.GetInt(pattern, def...)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *Config) GetInt8(pattern string, file...string) int8 {
|
func (c *Config) GetInt8(pattern string, def...interface{}) int8 {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetInt8(pattern)
|
return j.GetInt8(pattern, def...)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetInt16(pattern string, file...string) int16 {
|
func (c *Config) GetInt16(pattern string, def...interface{}) int16 {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetInt16(pattern)
|
return j.GetInt16(pattern, def...)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetInt32(pattern string, file...string) int32 {
|
func (c *Config) GetInt32(pattern string, def...interface{}) int32 {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetInt32(pattern)
|
return j.GetInt32(pattern, def...)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetInt64(pattern string, file...string) int64 {
|
func (c *Config) GetInt64(pattern string, def...interface{}) int64 {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetInt64(pattern)
|
return j.GetInt64(pattern, def...)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetInts(pattern string, file...string) []int {
|
func (c *Config) GetInts(pattern string, def...interface{}) []int {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetInts(pattern)
|
return j.GetInts(pattern, def...)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetUint(pattern string, file...string) uint {
|
func (c *Config) GetUint(pattern string, def...interface{}) uint {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetUint(pattern)
|
return j.GetUint(pattern, def...)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetUint8(pattern string, file...string) uint8 {
|
func (c *Config) GetUint8(pattern string, def...interface{}) uint8 {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetUint8(pattern)
|
return j.GetUint8(pattern, def...)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetUint16(pattern string, file...string) uint16 {
|
func (c *Config) GetUint16(pattern string, def...interface{}) uint16 {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetUint16(pattern)
|
return j.GetUint16(pattern, def...)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetUint32(pattern string, file...string) uint32 {
|
func (c *Config) GetUint32(pattern string, def...interface{}) uint32 {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetUint32(pattern)
|
return j.GetUint32(pattern, def...)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetUint64(pattern string, file...string) uint64 {
|
func (c *Config) GetUint64(pattern string, def...interface{}) uint64 {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetUint64(pattern)
|
return j.GetUint64(pattern, def...)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetToStruct(pattern string, objPointer interface{}, file...string) error {
|
func (c *Config) GetTime(pattern string, format...string) time.Time {
|
||||||
if j := c.getJson(file...); j != nil {
|
if j := c.getJson(); j != nil {
|
||||||
return j.GetToStruct(pattern, objPointer)
|
return j.GetTime(pattern, format...)
|
||||||
|
}
|
||||||
|
return time.Time{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) GetDuration(pattern string, def...interface{}) time.Duration {
|
||||||
|
if j := c.getJson(); j != nil {
|
||||||
|
return j.GetDuration(pattern, def...)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) GetGTime(pattern string, format...string) *gtime.Time {
|
||||||
|
if j := c.getJson(); j != nil {
|
||||||
|
return j.GetGTime(pattern, format...)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) GetToStruct(pattern string, pointer interface{}, def...interface{}) error {
|
||||||
|
if j := c.getJson(); j != nil {
|
||||||
|
return j.GetToStruct(pattern, pointer)
|
||||||
}
|
}
|
||||||
return errors.New("config file not found")
|
return errors.New("config file not found")
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ var (
|
|||||||
|
|
||||||
// Instance returns an instance of Config with default settings.
|
// Instance returns an instance of Config with default settings.
|
||||||
// The param <name> is the name for the instance.
|
// The param <name> is the name for the instance.
|
||||||
func Instance(name ...string) *Config {
|
func Instance(name...string) *Config {
|
||||||
key := DEFAULT_GROUP_NAME
|
key := DEFAULT_GROUP_NAME
|
||||||
if len(name) > 0 {
|
if len(name) > 0 {
|
||||||
key = name[0]
|
key = name[0]
|
||||||
|
@ -71,7 +71,7 @@ array = [1,2,3]
|
|||||||
"disk" : "127.0.0.1:6379,0",
|
"disk" : "127.0.0.1:6379,0",
|
||||||
"cache" : "127.0.0.1:6379,1",
|
"cache" : "127.0.0.1:6379,1",
|
||||||
})
|
})
|
||||||
gtest.AssertEQ(c.GetFilePath(), gfile.Pwd() + gfile.Separator + path)
|
gtest.AssertEQ(c.FilePath(), gfile.Pwd() + gfile.Separator + path)
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ func Test_SetFileName(t *testing.T) {
|
|||||||
"disk" : "127.0.0.1:6379,0",
|
"disk" : "127.0.0.1:6379,0",
|
||||||
"cache" : "127.0.0.1:6379,1",
|
"cache" : "127.0.0.1:6379,1",
|
||||||
})
|
})
|
||||||
gtest.AssertEQ(c.GetFilePath(), gfile.Pwd() + gfile.Separator + path)
|
gtest.AssertEQ(c.FilePath(), gfile.Pwd() + gfile.Separator + path)
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ func Test_Instance(t *testing.T) {
|
|||||||
"disk" : "127.0.0.1:6379,0",
|
"disk" : "127.0.0.1:6379,0",
|
||||||
"cache" : "127.0.0.1:6379,1",
|
"cache" : "127.0.0.1:6379,1",
|
||||||
})
|
})
|
||||||
gtest.AssertEQ(c.GetFilePath(), gfile.Pwd() + gfile.Separator + path)
|
gtest.AssertEQ(c.FilePath(), gfile.Pwd() + gfile.Separator + path)
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
@ -34,7 +34,7 @@ var (
|
|||||||
// 默认定时器属性参数值
|
// 默认定时器属性参数值
|
||||||
defaultSlots = cmdenv.Get("gf.gtimer.slots", gDEFAULT_SLOT_NUMBER).Int()
|
defaultSlots = cmdenv.Get("gf.gtimer.slots", gDEFAULT_SLOT_NUMBER).Int()
|
||||||
defaultLevel = cmdenv.Get("gf.gtimer.level", gDEFAULT_WHEEL_LEVEL).Int()
|
defaultLevel = cmdenv.Get("gf.gtimer.level", gDEFAULT_WHEEL_LEVEL).Int()
|
||||||
defaultInterval = cmdenv.Get("gf.gtimer.interval", gDEFAULT_WHEEL_INTERVAL).TimeDuration()*time.Millisecond
|
defaultInterval = cmdenv.Get("gf.gtimer.interval", gDEFAULT_WHEEL_INTERVAL).Duration()*time.Millisecond
|
||||||
// 默认的wheel管理对象
|
// 默认的wheel管理对象
|
||||||
defaultTimer = New(defaultSlots, defaultInterval, defaultLevel)
|
defaultTimer = New(defaultSlots, defaultInterval, defaultLevel)
|
||||||
)
|
)
|
||||||
|
@ -17,10 +17,10 @@ func Time(i interface{}, format...string) time.Time {
|
|||||||
return GTime(i, format...).Time
|
return GTime(i, format...).Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimeDuration converts <i> to time.Duration.
|
// Duration converts <i> to time.Duration.
|
||||||
// If <i> is string, then it uses time.ParseDuration to convert it.
|
// If <i> is string, then it uses time.ParseDuration to convert it.
|
||||||
// If <i> is numeric, then it converts <i> as nanoseconds.
|
// If <i> is numeric, then it converts <i> as nanoseconds.
|
||||||
func TimeDuration(i interface{}) time.Duration {
|
func Duration(i interface{}) time.Duration {
|
||||||
s := String(i)
|
s := String(i)
|
||||||
if !gstr.IsNumeric(s) {
|
if !gstr.IsNumeric(s) {
|
||||||
d, _ := time.ParseDuration(s)
|
d, _ := time.ParseDuration(s)
|
||||||
|
@ -20,6 +20,6 @@ func Test_Time(t *testing.T) {
|
|||||||
t1 := "2011-10-10 01:02:03.456"
|
t1 := "2011-10-10 01:02:03.456"
|
||||||
gtest.AssertEQ(gconv.GTime(t1), gtime.NewFromStr(t1))
|
gtest.AssertEQ(gconv.GTime(t1), gtime.NewFromStr(t1))
|
||||||
gtest.AssertEQ(gconv.Time(t1), gtime.NewFromStr(t1).Time)
|
gtest.AssertEQ(gconv.Time(t1), gtime.NewFromStr(t1).Time)
|
||||||
gtest.AssertEQ(gconv.TimeDuration(100), 100*time.Nanosecond)
|
gtest.AssertEQ(gconv.Duration(100), 100*time.Nanosecond)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user