timeout

package
v0.0.0-...-b628505 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

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 Compare

func Compare(c1, c2 context.Context) context.Context

Compare 用于比较两个context的超时时间,返回超时时间最小的context

func HumanDurationFormat

func HumanDurationFormat(stamp int64, designation ...time.Time) string

func Shrink

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

type DTime time.Time

func (DTime) GormDataType

func (DTime) GormDataType() string

func (DTime) MarshalJSON

func (d DTime) MarshalJSON() ([]byte, error)

func (*DTime) Scan

func (d *DTime) Scan(value interface{}) error

func (DTime) String

func (d DTime) String() string

func (*DTime) UnmarshalJSON

func (d *DTime) UnmarshalJSON(src []byte) error

func (*DTime) UnmarshalText

func (d *DTime) UnmarshalText(value string) error

func (DTime) Value

func (d DTime) Value() (driver.Value, error)

type Date

type Date time.Time

func (Date) GormDataType

func (Date) GormDataType() string

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

func (*Date) Scan

func (d *Date) Scan(value interface{}) error

func (Date) String

func (d Date) String() string

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(src []byte) error

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(value string) error

func (Date) Value

func (d Date) Value() (driver.Value, error)

type DateStruct

type DateStruct struct {
	time.Time
}

func (*DateStruct) GormDataType

func (m *DateStruct) GormDataType() string

GormDataType gorm 定义数据库字段类型 Author [SliverHorn](https://github.com/SliverHorn)

func (*DateStruct) MarshalJSON

func (m *DateStruct) MarshalJSON() ([]byte, error)

MarshalJSON 序列化 Author [SliverHorn](https://github.com/SliverHorn)

func (*DateStruct) Scan

func (m *DateStruct) Scan(value interface{}) error

Scan 扫描 Author [SliverHorn](https://github.com/SliverHorn)

func (*DateStruct) String

func (m *DateStruct) String() string

String 输出 DateTime 变量为字符串 Author [SliverHorn](https://github.com/SliverHorn)

func (*DateStruct) ToDateTime

func (m *DateStruct) ToDateTime() *DateTimeStruct

ToDateTime Date to Datetime Author [SliverHorn](https://github.com/SliverHorn)

func (*DateStruct) UnmarshalJSON

func (m *DateStruct) UnmarshalJSON(src []byte) error

UnmarshalJSON 反序列化 Author [SliverHorn](https://github.com/SliverHorn)

func (*DateStruct) UnmarshalText

func (m *DateStruct) UnmarshalText(value string) error

UnmarshalText 通过 string 序列化成 Date Author [SliverHorn](https://github.com/SliverHorn)

func (*DateStruct) UnmarshalTextByLayout

func (m *DateStruct) UnmarshalTextByLayout(layout, value string) error

UnmarshalTextByLayout 通过 string 序列化成 Date by layout Author [SliverHorn](https://github.com/SliverHorn)

func (*DateStruct) Value

func (m *DateStruct) Value() (driver.Value, error)

Value 值 Author [SliverHorn](https://github.com/SliverHorn)

type DateTime

type DateTime time.Time

func (DateTime) GormDataType

func (DateTime) GormDataType() string

func (DateTime) MarshalJSON

func (d DateTime) MarshalJSON() ([]byte, error)

func (*DateTime) Scan

func (d *DateTime) Scan(value interface{}) error

func (DateTime) String

func (d DateTime) String() string

func (*DateTime) UnmarshalJSON

func (d *DateTime) UnmarshalJSON(src []byte) error

func (*DateTime) UnmarshalText

func (d *DateTime) UnmarshalText(value string) error

func (DateTime) Value

func (d DateTime) Value() (driver.Value, error)

type DateTimeStruct

type DateTimeStruct struct {
	time.Time
}

func (*DateTimeStruct) GormDataType

func (m *DateTimeStruct) GormDataType() string

GormDataType gorm 定义数据库字段类型 Author [SliverHorn](https://github.com/SliverHorn)

func (*DateTimeStruct) MarshalJSON

func (m *DateTimeStruct) MarshalJSON() ([]byte, error)

MarshalJSON 序列化 Author [SliverHorn](https://github.com/SliverHorn)

func (*DateTimeStruct) Scan

func (m *DateTimeStruct) Scan(value interface{}) error

Scan 扫描 Author [SliverHorn](https://github.com/SliverHorn)

func (*DateTimeStruct) String

func (m *DateTimeStruct) String() string

String 输出 DateTime 变量为字符串 Author [SliverHorn](https://github.com/SliverHorn)

func (*DateTimeStruct) ToDate

func (m *DateTimeStruct) ToDate() *DateStruct

ToDate DateTime 2 Date Author [SliverHorn](https://github.com/SliverHorn)

func (*DateTimeStruct) UnmarshalJSON

func (m *DateTimeStruct) UnmarshalJSON(src []byte) error

UnmarshalJSON 反序列化 Author [SliverHorn](https://github.com/SliverHorn)

func (*DateTimeStruct) UnmarshalText

func (m *DateTimeStruct) UnmarshalText(value string) error

UnmarshalText 通过 string 反序列化成 DateTime Author [SliverHorn](https://github.com/SliverHorn)

func (*DateTimeStruct) UnmarshalTextByLayout

func (m *DateTimeStruct) UnmarshalTextByLayout(layout, value string) error

UnmarshalTextByLayout 通过 string 序列化成 DateTime Author [SliverHorn](https://github.com/SliverHorn)

func (*DateTimeStruct) Value

func (m *DateTimeStruct) Value() (driver.Value, error)

Value 值 Author [SliverHorn](https://github.com/SliverHorn)

type DbJSON

type DbJSON []byte

func DBJSONFromObject

func DBJSONFromObject(obj interface{}) DbJSON

func (*DbJSON) Get

func (j *DbJSON) Get(obj interface{}) error

func (DbJSON) GormDataType

func (DbJSON) GormDataType() string

func (DbJSON) MarshalJSON

func (j DbJSON) MarshalJSON() ([]byte, error)

func (*DbJSON) Scan

func (j *DbJSON) Scan(value interface{}) error

func (*DbJSON) Set

func (j *DbJSON) Set(obj interface{}) (err error)

func (*DbJSON) UnmarshalJSON

func (j *DbJSON) UnmarshalJSON(src []byte) (err error)

func (*DbJSON) UnmarshalText

func (j *DbJSON) UnmarshalText(value string) error

func (DbJSON) Value

func (j DbJSON) Value() (driver.Value, error)

type Stamp

type Stamp int64

Stamp 用于MySQL时间戳转换 实现了 sql.Scanner 接口

func (*Stamp) Scan

func (jt *Stamp) Scan(src interface{}) (err error)

Scan 扫描赋值

func (Stamp) Time

func (jt Stamp) Time() time.Time

Time 转化time.Time

func (Stamp) Value

func (jt Stamp) Value() driver.Value

Value 获取driver.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL