Documentation ¶
Index ¶
- Constants
- func Shrink(c context.Context, d time.Duration) (time.Duration, context.Context, context.CancelFunc)
- type DTime
- type Date
- type DateTime
- func (DateTime) GormDataType() string
- func (d DateTime) MarshalJSON() ([]byte, error)
- func (d *DateTime) Scan(value interface{}) error
- func (d DateTime) String() string
- func (d *DateTime) UnmarshalJSON(src []byte) error
- func (d *DateTime) UnmarshalText(value string) error
- func (d DateTime) Value() (driver.Value, error)
- type Stamp
Examples ¶
Constants ¶
View Source
const DTimeFormat = "15:04:05"
View Source
const DateFormat = "2006-01-02"
View Source
const DateTimeFormat = "2006-01-02 15:04:05"
Variables ¶
This section is empty.
Functions ¶
func Shrink ¶
func Shrink(c context.Context, d time.Duration) (time.Duration, context.Context, context.CancelFunc)
Shrink 用于链路超时时间以及当前节点的超时时间控制
Example ¶
// timeout.Shrink 方法提供全链路的超时控制 // 只需要传入一个父节点的ctx 和需要设置的超时时间,他会帮你确认这个ctx是否之前设置过超时时间, // 如果设置过超时时间的话会和你当前设置的超时时间进行比较,选择一个最小的进行设置,保证链路超时时间不会被下游影响 // d: 代表剩余的超时时间 // nCtx: 新的context对象 // cancel: 如果是成功真正设置了超时时间会返回一个cancel()方法,未设置成功会返回一个无效的cancel,不过别担心,还是可以正常调用的 d, nCtx, cancel := Shrink(context.Background(), 5*time.Second) // d 根据需要判断 // 一般判断该服务的下游超时时间,如果d过于小,可以直接放弃 select { case <-nCtx.Done(): cancel() default: // ... } _ = d
Output:
Types ¶
type DTime ¶ added in v1.0.1
func (DTime) GormDataType ¶ added in v1.0.1
func (DTime) MarshalJSON ¶ added in v1.0.1
func (*DTime) UnmarshalJSON ¶ added in v1.0.1
func (*DTime) UnmarshalText ¶ added in v1.0.1
type Date ¶ added in v1.0.1
func (Date) GormDataType ¶ added in v1.0.1
func (Date) MarshalJSON ¶ added in v1.0.1
func (*Date) UnmarshalJSON ¶ added in v1.0.1
func (*Date) UnmarshalText ¶ added in v1.0.1
type DateTime ¶ added in v1.0.1
func (DateTime) GormDataType ¶ added in v1.0.1
func (DateTime) MarshalJSON ¶ added in v1.0.1
func (*DateTime) UnmarshalJSON ¶ added in v1.0.1
func (*DateTime) UnmarshalText ¶ added in v1.0.1
Click to show internal directories.
Click to hide internal directories.