gox

package module
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 22 Imported by: 25

README

gox

Golang的基础库,提供各种便捷的方法,包括

  • 字符串
  • 配置
  • 时间处理
  • 基础类型

感谢Jetbrains

本项目通过Jetbrains开源许可IDE编写源代码,特此感谢

Jetbrains图标

Documentation

Index

Constants

View Source
const (
	BytesB  = size.BytesB
	BytesKB = 1024 * BytesB
	BytesMB = 1024 * BytesKB
	BytesGB = 1024 * BytesMB
	BytesTB = 1024 * BytesGB
	BytesPB = 1024 * BytesTB
	BytesEB = 1024 * BytesPB
)

Variables

This section is empty.

Functions

func Atoi

func Atoi[T constraint.Int | constraint.Uint](num string, base int) T

Atoi 增强版进制转换,支持任意进制,最大76进制

func Contains added in v0.1.7

func Contains[T any](items *[]T, item T) bool

Contains 判断元素是否在数组中

func Diff added in v0.3.7

func Diff[T any](first *[]T, second *[]T) (diff []T)

Diff 差集

func Flat added in v0.1.3

func Flat[T flatType](from T) *flatConverter[T]

func FormatInt

func FormatInt[T constraint.Int](num T, base uint8, callback callback.FormatInt[T]) string

FormatInt 增强版进制转换,最大支持76进制

func FormatUint added in v0.6.3

func FormatUint[T constraint.Uint](num T, base uint8, callback callback.FormatUint[T]) string

func Gid

func Gid() (id uint64)

Gid 当前协程编号

func If added in v0.1.3

func If[T any](condition bool, result T) (t T)

If 模块条件表达式,主要用法是减少大括号

func Iff added in v0.2.5

func Iff[T any](condition bool, result callback.Callback[T]) (t T)

Iff 模块条件表达式,主要用法是减少大括号

func Ift added in v0.2.5

func Ift[T any](condition bool, first T, second T) (t T)

Ift 模拟三元表达式,主要用法是减少大括号

func Ifx added in v0.1.9

func Ifx[T any](condition bool, first callback.Callback[T], second callback.Callback[T]) (t T)

Ifx 模拟三元表达式,主要用法是减少大括号

func Index added in v0.1.3

func Index[T any](items *[]T, item T) (index int)

Index 在列表中找出元素的下标

func Set added in v0.1.3

func Set[T any](setter func(value T), first T, second T)

Set 设置方法,当`first`值为零值时,设置为`second`的值,否则设置`first`的值

func Stack added in v0.3.7

func Stack(stack int, skip int) string

Stack 返回当前执行堆栈

func String

func String(from string) *text.String

String 字符串操作

func StringBuilder added in v0.2.6

func StringBuilder(items ...any) *text.Builder

StringBuilder 创建字符串构建器

func Ternary added in v0.2.1

func Ternary[T any](condition bool, first T, second T) (t T)

Ternary 模拟三元表达式,主要用法是减少大括号

func TernaryFunc added in v0.2.5

func TernaryFunc[T any](condition bool, first callback.Callback[T], second callback.Callback[T]) (t T)

TernaryFunc 模拟三元表达式,主要用法是减少大括号

func ToString added in v0.2.1

func ToString(from any) string

ToString 转换成字符串

func ToStrings added in v0.2.1

func ToStrings(from ...any) []string

ToStrings 转换成字符串列表

Types

type Bitmap added in v0.5.7

type Bitmap struct {
	// contains filtered or unexported fields
}

Bitmap 位图,通过使用位运算来设置位的开关

func NewBitmap added in v0.5.7

func NewBitmap() *Bitmap

NewBitmap 创建位图

func (*Bitmap) All added in v0.6.0

func (b *Bitmap) All(position uint, positions ...uint) (contains bool)

func (*Bitmap) Any added in v0.6.0

func (b *Bitmap) Any(position uint, positions ...uint) (contains bool)

func (*Bitmap) Contains added in v0.5.7

func (b *Bitmap) Contains(position uint) bool

func (*Bitmap) FromBytes added in v0.5.8

func (b *Bitmap) FromBytes(bytes []byte) (err error)

func (*Bitmap) FromHex added in v0.5.8

func (b *Bitmap) FromHex(value string) (err error)

func (*Bitmap) MarshalJSON added in v0.5.8

func (b *Bitmap) MarshalJSON() ([]byte, error)

func (*Bitmap) Set added in v0.5.7

func (b *Bitmap) Set(position uint, positions ...uint) *Bitmap

func (*Bitmap) UnmarshalJSON added in v0.5.8

func (b *Bitmap) UnmarshalJSON(data []byte) (err error)

func (*Bitmap) Unset added in v0.5.7

func (b *Bitmap) Unset(position uint, positions ...uint) *Bitmap

type Bytes added in v0.5.0

type Bytes = size.Bytes

Bytes 字节大小

func ParseBytes

func ParseBytes(from string) (Bytes, error)

ParseBytes 解析字节大小

type Callback added in v1.9.1

type Callback[T any] func(*T) error

Callback 通用回调

type Empty added in v0.3.8

type Empty struct {
}

Empty 空结构体

type Feature added in v0.5.4

type Feature uint

Feature 功能 和 Features 一起使用来达到功能开关和检查功能是否开启的目的

type Features added in v0.5.4

type Features struct {
	// contains filtered or unexported fields
}

Features 一个通用的开关

func NewFeatures added in v0.5.4

func NewFeatures() *Features

NewFeatures 创建开关

func (*Features) All added in v0.5.4

func (f *Features) All(feature Feature, features ...Feature) (enabled bool)

func (*Features) Any added in v0.5.4

func (f *Features) Any(feature Feature, features ...Feature) (enabled bool)

func (*Features) Disable added in v0.5.4

func (f *Features) Disable(feature Feature, features ...Feature) *Features

func (*Features) Enable added in v0.5.4

func (f *Features) Enable(feature Feature, features ...Feature) *Features

func (*Features) MarshalJSON added in v0.5.9

func (f *Features) MarshalJSON() ([]byte, error)

func (*Features) UnmarshalJSON added in v0.5.9

func (f *Features) UnmarshalJSON(data []byte) error

type Field

type Field[T any] Kv[string, T]

Field 字段,一个键值对,要求键必须是字符串

type Fields

type Fields[T any] []Field[T]

Fields 字段列表

func (Fields[T]) Add added in v0.2.2

func (f Fields[T]) Add(fields ...Field[T]) Fields[T]

func (Fields[T]) String

func (f Fields[T]) String() string

type Incomparable added in v0.6.1

type Incomparable [0]func()

Incomparable 不可比较 包含本结构的结构体不能用于排序和比较大小

type Int64 added in v1.9.3

type Int64 int64

Int64 支持字符串形式

func (Int64) MarshalJSON added in v1.9.3

func (i Int64) MarshalJSON() ([]byte, error)

func (*Int64) UnmarshalJSON added in v1.9.3

func (i *Int64) UnmarshalJSON(bytes []byte) (err error)

type Key

type Key[T any] interface {
	// Key 返回键值
	Key() T
}

Key 键

type Kv added in v0.1.3

type Kv[K any, V any] interface {
	Key[K]
	Value[V]
}

Kv 键值对

type Labels added in v0.3.8

type Labels map[string]string

Labels 标签

func (Labels) String added in v0.3.8

func (l Labels) String() string

type Mapper added in v1.9.3

type Mapper[T any] interface {
	Map(T) string
}

type Microsecond added in v0.3.9

type Microsecond struct {
	time.Time
}

Microsecond 微秒

func NewMicrosecond added in v0.4.0

func NewMicrosecond(from time.Time) *Microsecond

NewMicrosecond 从时间创建微秒

func ParseMicrosecond added in v0.3.9

func ParseMicrosecond(from string) (microsecond *Microsecond, err error)

ParseMicrosecond 从字符串解析微秒

func (Microsecond) MarshalJSON added in v0.3.9

func (m Microsecond) MarshalJSON() ([]byte, error)

func (*Microsecond) UnmarshalJSON added in v0.3.9

func (m *Microsecond) UnmarshalJSON(bytes []byte) (err error)

type Millisecond added in v0.3.9

type Millisecond struct {
	time.Time
}

Millisecond 毫秒

func NewMillisecond added in v0.4.0

func NewMillisecond(from time.Time) *Millisecond

NewMillisecond 从时间创建毫秒

func ParseMillisecond added in v0.3.9

func ParseMillisecond(from string) (millisecond *Millisecond, err error)

ParseMillisecond 从字符串解析毫秒

func (Millisecond) MarshalJSON added in v0.3.9

func (m Millisecond) MarshalJSON() ([]byte, error)

func (*Millisecond) UnmarshalJSON added in v0.3.9

func (m *Millisecond) UnmarshalJSON(bytes []byte) (err error)

type Nanosecond added in v0.3.9

type Nanosecond struct {
	time.Time
}

Nanosecond 纳秒

func NewNanosecond added in v0.4.0

func NewNanosecond(from time.Time) *Nanosecond

NewNanosecond 从时间创建毫秒

func ParseNanosecond added in v0.3.9

func ParseNanosecond(from string) (nanosecond *Nanosecond, err error)

ParseNanosecond 从字符串解析毫秒

func (Nanosecond) MarshalJSON added in v0.3.9

func (n Nanosecond) MarshalJSON() ([]byte, error)

func (*Nanosecond) UnmarshalJSON added in v0.3.9

func (n *Nanosecond) UnmarshalJSON(bytes []byte) (err error)

type Object added in v0.1.3

type Object struct {
}

Object 基础对象

type Package added in v0.1.3

type Package string

Package 包名

func (*Package) Name added in v0.1.3

func (p *Package) Name() (name string)

func (*Package) String added in v0.1.3

func (p *Package) String() string

type Pointer added in v0.6.5

type Pointer[T any] *T

Pointer 指针

func NewPointer added in v0.6.5

func NewPointer[T any](from T) Pointer[T]

NewPointer 快速创建指针

type Pointerized added in v0.6.1

type Pointerized [0]sync.Mutex

Pointerized 限制结构体只能使用指针形式

type Reset added in v1.9.2

type Reset[T any] func(*T)

Reset 字段重置回调,用于更新字段

type Resettable added in v1.9.3

type Resettable[T any] interface {
	Reset(Reset[T])
}

Resettable 可被重新设置的

type Second added in v0.3.9

type Second struct {
	time.Time
}

Second 秒

func NewSecond added in v0.4.0

func NewSecond(from time.Time) *Second

NewSecond 从时间创建秒

func ParseSecond added in v0.3.9

func ParseSecond(from string) (second *Second, err error)

ParseSecond 从字符串解析秒

func (Second) MarshalJSON added in v0.3.9

func (s Second) MarshalJSON() ([]byte, error)

func (*Second) UnmarshalJSON added in v0.3.9

func (s *Second) UnmarshalJSON(bytes []byte) (err error)

type Slice added in v0.6.4

type Slice[T any] []T

Slice 切片,既可以兼容单个值也可以兼容数组

func NewSlice added in v0.6.6

func NewSlice[T any](items ...T) Slice[T]

NewSlice 快速创建数组

func (*Slice[T]) Capacity added in v0.6.7

func (s *Slice[T]) Capacity() int

func (*Slice[T]) Clone added in v0.6.5

func (s *Slice[T]) Clone() (t Slice[T])

func (*Slice[T]) Length added in v0.6.7

func (s *Slice[T]) Length() int

func (*Slice[T]) UnmarshalJSON added in v0.6.4

func (s *Slice[T]) UnmarshalJSON(bytes []byte) (err error)

func (*Slice[T]) UnmarshalXML added in v0.6.4

func (s *Slice[T]) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) (err error)

type Uint64 added in v1.9.3

type Uint64 uint64

Uint64 支持字符串形式

func (Uint64) MarshalJSON added in v1.9.3

func (u Uint64) MarshalJSON() ([]byte, error)

func (*Uint64) UnmarshalJSON added in v1.9.3

func (u *Uint64) UnmarshalJSON(bytes []byte) (err error)

type Value

type Value[T any] interface {
	// Value 返回具体的值
	Value() T
}

Value 值

Jump to

Keyboard shortcuts

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