Skip to content

Commit

Permalink
- Fix get simple variables from Just context
Browse files Browse the repository at this point in the history
  • Loading branch information
legion-zver committed Jun 14, 2018
1 parent 2a03b8b commit cf4acfa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
28 changes: 23 additions & 5 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (c *Context) GetDef(key string, def interface{}) interface{} {
// Get bool metadata by key.
func (c *Context) GetBool(key string) (value bool, ok bool) {
if c.Meta != nil {
if i, ok := c.Meta[key]; ok && i != nil {
if i, has := c.Meta[key]; has && i != nil {
value, ok = i.(bool)
}
}
Expand All @@ -308,7 +308,7 @@ func (c *Context) GetBoolDef(key string, def bool) bool {
// Get string metadata by key.
func (c *Context) GetStr(key string) (value string, ok bool) {
if c.Meta != nil {
if i, ok := c.Meta[key]; ok && i != nil {
if i, has := c.Meta[key]; has && i != nil {
value, ok = i.(string)
}
}
Expand All @@ -326,7 +326,7 @@ func (c *Context) GetStrDef(key string, def string) string {
// Get duration metadata by key.
func (c *Context) GetDuration(key string) (value time.Duration, ok bool) {
if c.Meta != nil {
if i, ok := c.Meta[key]; ok && i != nil {
if i, has := c.Meta[key]; has && i != nil {
value, ok = i.(time.Duration)
}
}
Expand All @@ -344,13 +344,23 @@ func (c *Context) GetDurationDef(key string, def time.Duration) time.Duration {
// Get integer metadata by key.
func (c *Context) GetInt(key string) (value int64, ok bool) {
if c.Meta != nil {
if i, ok := c.Meta[key]; ok && i != nil {
if i, has := c.Meta[key]; has && i != nil {
value, ok = i.(int64)
}
}
return
}

// Get unsigned integer metadata by key.
func (c *Context) GetUint(key string) (value uint64, ok bool) {
if c.Meta != nil {
if i, has := c.Meta[key]; has && i != nil {
value, ok = i.(uint64)
}
}
return
}

// Get integer metadata by key with default value.
func (c *Context) GetIntDef(key string, def int64) int64 {
if value, ok := c.GetInt(key); ok {
Expand All @@ -359,10 +369,18 @@ func (c *Context) GetIntDef(key string, def int64) int64 {
return def
}

// Get unsigned integer metadata by key with default value.
func (c *Context) GetUintDef(key string, def uint64) uint64 {
if value, ok := c.GetUint(key); ok {
return value
}
return def
}

// Get integer metadata by key.
func (c *Context) GetFloat(key string) (value float64, ok bool) {
if c.Meta != nil {
if i, ok := c.Meta[key]; ok && i != nil {
if i, has := c.Meta[key]; has && i != nil {
value, ok = i.(float64)
}
}
Expand Down
2 changes: 1 addition & 1 deletion just.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

const (
Version = "v0.1.15"
Version = "v0.1.16"
DebugEnvName = "JUST_DEBUG_MODE"
)

Expand Down

0 comments on commit cf4acfa

Please sign in to comment.