timeout

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 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 added in v1.2.12

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

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

func HumanDurationFormat added in v1.2.3

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 added in v1.0.1

type DTime time.Time

func (DTime) GormDataType added in v1.0.1

func (DTime) GormDataType() string

func (DTime) MarshalJSON added in v1.0.1

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

func (*DTime) Scan added in v1.0.1

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

func (DTime) String added in v1.0.1

func (d DTime) String() string

func (*DTime) UnmarshalJSON added in v1.0.1

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

func (*DTime) UnmarshalText added in v1.0.1

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

func (DTime) Value added in v1.0.1

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

type Date added in v1.0.1

type Date time.Time

func (Date) GormDataType added in v1.0.1

func (Date) GormDataType() string

func (Date) MarshalJSON added in v1.0.1

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

func (*Date) Scan added in v1.0.1

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

func (Date) String added in v1.0.1

func (d Date) String() string

func (*Date) UnmarshalJSON added in v1.0.1

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

func (*Date) UnmarshalText added in v1.0.1

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

func (Date) Value added in v1.0.1

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

type DateStruct added in v1.1.2

type DateStruct struct {
	time.Time
}

func (*DateStruct) GormDataType added in v1.1.2

func (m *DateStruct) GormDataType() string

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

func (*DateStruct) MarshalJSON added in v1.1.2

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

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

func (*DateStruct) Scan added in v1.1.2

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

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

func (*DateStruct) String added in v1.1.2

func (m *DateStruct) String() string

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

func (*DateStruct) ToDateTime added in v1.1.2

func (m *DateStruct) ToDateTime() *DateTimeStruct

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

func (*DateStruct) UnmarshalJSON added in v1.1.2

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

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

func (*DateStruct) UnmarshalText added in v1.1.2

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

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

func (*DateStruct) UnmarshalTextByLayout added in v1.1.2

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

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

func (*DateStruct) Value added in v1.1.2

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

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

type DateTime added in v1.0.1

type DateTime time.Time

func (DateTime) GormDataType added in v1.0.1

func (DateTime) GormDataType() string

func (DateTime) MarshalJSON added in v1.0.1

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

func (*DateTime) Scan added in v1.0.1

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

func (DateTime) String added in v1.0.1

func (d DateTime) String() string

func (*DateTime) UnmarshalJSON added in v1.0.1

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

func (*DateTime) UnmarshalText added in v1.0.1

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

func (DateTime) Value added in v1.0.1

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

type DateTimeStruct added in v1.1.2

type DateTimeStruct struct {
	time.Time
}

func (*DateTimeStruct) GormDataType added in v1.1.2

func (m *DateTimeStruct) GormDataType() string

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

func (*DateTimeStruct) MarshalJSON added in v1.1.2

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

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

func (*DateTimeStruct) Scan added in v1.1.2

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

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

func (*DateTimeStruct) String added in v1.1.2

func (m *DateTimeStruct) String() string

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

func (*DateTimeStruct) ToDate added in v1.1.2

func (m *DateTimeStruct) ToDate() *DateStruct

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

func (*DateTimeStruct) UnmarshalJSON added in v1.1.2

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

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

func (*DateTimeStruct) UnmarshalText added in v1.1.2

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

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

func (*DateTimeStruct) UnmarshalTextByLayout added in v1.1.2

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

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

func (*DateTimeStruct) Value added in v1.1.2

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

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

type DbJSON added in v1.1.0

type DbJSON []byte

func DBJSONFromObject added in v1.1.0

func DBJSONFromObject(obj interface{}) DbJSON

func (*DbJSON) Get added in v1.1.0

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

func (DbJSON) GormDataType added in v1.1.0

func (DbJSON) GormDataType() string

func (DbJSON) MarshalJSON added in v1.1.0

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

func (*DbJSON) Scan added in v1.1.0

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

func (*DbJSON) Set added in v1.1.0

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

func (*DbJSON) UnmarshalJSON added in v1.1.0

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

func (*DbJSON) UnmarshalText added in v1.1.0

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

func (DbJSON) Value added in v1.1.0

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

type Stamp added in v1.0.1

type Stamp int64

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

func (*Stamp) Scan added in v1.0.1

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

Scan 扫描赋值

func (Stamp) Time added in v1.0.1

func (jt Stamp) Time() time.Time

Time 转化time.Time

func (Stamp) Value added in v1.0.1

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