mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-02 16:28:39 +08:00
fix golint issues in core/contextx (#477)
This commit is contained in:
parent
425be6b4a1
commit
f6894448bd
@ -5,6 +5,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ShrinkDeadline returns a new Context with proper deadline base on the given ctx and timeout.
|
||||||
|
// And returns a cancel function as well.
|
||||||
func ShrinkDeadline(ctx context.Context, timeout time.Duration) (context.Context, func()) {
|
func ShrinkDeadline(ctx context.Context, timeout time.Duration) (context.Context, func()) {
|
||||||
if deadline, ok := ctx.Deadline(); ok {
|
if deadline, ok := ctx.Deadline(); ok {
|
||||||
leftTime := time.Until(deadline)
|
leftTime := time.Until(deadline)
|
||||||
|
@ -19,6 +19,7 @@ func (cv contextValuer) Value(key string) (interface{}, bool) {
|
|||||||
return v, v != nil
|
return v, v != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For unmarshals ctx into v.
|
||||||
func For(ctx context.Context, v interface{}) error {
|
func For(ctx context.Context, v interface{}) error {
|
||||||
return unmarshaler.UnmarshalValuer(contextValuer{
|
return unmarshaler.UnmarshalValuer(contextValuer{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
|
@ -21,6 +21,7 @@ func (valueOnlyContext) Err() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValueOnlyFrom takes all values from the given ctx, without deadline and error control.
|
||||||
func ValueOnlyFrom(ctx context.Context) context.Context {
|
func ValueOnlyFrom(ctx context.Context) context.Context {
|
||||||
return valueOnlyContext{
|
return valueOnlyContext{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
|
Loading…
Reference in New Issue
Block a user