1
0
Fork 0
mirror of https://github.com/drone/drone-cli.git synced 2024-06-07 06:26:03 +02:00
drone-cli/vendor/github.com/docker/distribution/context/util.go
Brad Rydzewski f18b9fe2ac update dep
2018-02-14 13:06:05 -08:00

25 lines
689 B
Go

package context
import (
"time"
)
// Since looks up key, which should be a time.Time, and returns the duration
// since that time. If the key is not found, the value returned will be zero.
// This is helpful when inferring metrics related to context execution times.
func Since(ctx Context, key interface{}) time.Duration {
if startedAt, ok := ctx.Value(key).(time.Time); ok {
return time.Since(startedAt)
}
return 0
}
// GetStringValue returns a string value from the context. The empty string
// will be returned if not found.
func GetStringValue(ctx Context, key interface{}) (value string) {
if valuev, ok := ctx.Value(key).(string); ok {
value = valuev
}
return value
}