Documentation
¶
Index ¶
- Variables
- func FirstNotEmpty(v ...string) string
- func FormatBytes[T int | int16 | int32 | int64 | uint | uint16 | uint32 | uint64](b T) string
- func GetDockerInfo(ctx context.Context) (types.Version, system.Info, error)
- func MustInt(v string) int
- func ScanReader(r io.Reader, callback func(line []byte)) error
- type Atomic
- type AtomicBool
- type AtomicString
- type ContextBag
- type DockerCgroups
- type DockerContainers
- type DockerInformation
- type DockerRunc
- type DockerStorage
- type Information
- type Locker
- type Rate
- type SinkName
- type SinkPool
- type System
Constants ¶
This section is empty.
Variables ¶
var ErrLockerLocked = errors.Sentinel("locker: 無法取得鎖定,目前已被鎖定")
var Version = "develop"
Functions ¶
func FormatBytes ¶
Types ¶
type Atomic ¶
type Atomic[T any] struct { // contains filtered or unexported fields }
func (*Atomic[T]) MarshalJSON ¶
MarshalJSON 將 Atomic[T] 的值序列化為 JSON。
func (*Atomic[T]) UnmarshalJSON ¶
UnmarshalJSON 將 JSON 值反序列化為 Atomic[T] 的值。
type AtomicBool ¶
type AtomicBool struct {
// contains filtered or unexported fields
}
func NewAtomicBool ¶
func NewAtomicBool(v bool) *AtomicBool
func (*AtomicBool) Load ¶
func (ab *AtomicBool) Load() bool
func (*AtomicBool) MarshalJSON ¶
func (ab *AtomicBool) MarshalJSON() ([]byte, error)
func (*AtomicBool) Store ¶
func (ab *AtomicBool) Store(v bool)
func (*AtomicBool) SwapIf ¶
func (ab *AtomicBool) SwapIf(v bool) bool
SwapIf 若 AtomicBool 目前儲存的值與相反的布林值不同,就會儲存值 「v」。若成功交換,回應為「true」,否則回傳「false」。
func (*AtomicBool) UnmarshalJSON ¶
func (ab *AtomicBool) UnmarshalJSON(b []byte) error
type AtomicString ¶
type AtomicString struct {
// contains filtered or unexported fields
}
AtomicString 讓你可以讀寫指定的結構欄位,而不必擔心潛在的競態 條件情況。其底層使用一個簡單的 sync.RWMutex 來控制對此值的存取。
func NewAtomicString ¶
func NewAtomicString(v string) *AtomicString
func (*AtomicString) MarshalJSON ¶
func (as *AtomicString) MarshalJSON() ([]byte, error)
func (*AtomicString) UnmarshalJSON ¶
func (as *AtomicString) UnmarshalJSON(b []byte) error
type ContextBag ¶
type ContextBag struct {
// contains filtered or unexported fields
}
func NewContextBag ¶
func NewContextBag(ctx context.Context) *ContextBag
func (*ContextBag) Cancel ¶
func (cb *ContextBag) Cancel(key string)
func (*ContextBag) CancelAll ¶
func (cb *ContextBag) CancelAll()
type DockerCgroups ¶
type DockerContainers ¶
type DockerInformation ¶
type DockerInformation struct {
Version string `json:"version"`
Cgroups DockerCgroups `json:"cgroups"`
Containers DockerContainers `json:"containers"`
Storage DockerStorage `json:"storage"`
Runc DockerRunc `json:"runc"`
}
type DockerRunc ¶
type DockerRunc struct {
Version string `json:"version"`
}
type DockerStorage ¶
type Information ¶
type Information struct {
Version string `json:"version"`
Docker DockerInformation `json:"docker"`
System System `json:"system"`
}
func GetSystemInformation ¶
func GetSystemInformation() (*Information, error)
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
type Rate ¶
type Rate struct {
// contains filtered or unexported fields
}
Rate 定義了一個速率限制器,在每段時間長度(duration)內限制 n 個項目 (limit)。
type SinkPool ¶
type SinkPool struct {
// contains filtered or unexported fields
}
SinkPool 代表一個包含多個 sink 的池。
func NewSinkPool ¶
func NewSinkPool() *SinkPool
NewSinkPool 回傳一個新的空 SinkPool。sink 池通常會伴隨伺服器實例 的整個生命週期存在。
func (*SinkPool) Destroy ¶
func (p *SinkPool) Destroy()
Destroy 藉由移除並關閉所有 sink,並銷毀所有目前存在的 channel, 來銷毀此池。
func (*SinkPool) Push ¶
Push 將指定的訊息傳送給池中已註冊的每一個 channel。此函式會使用 環形緩衝區(Ring Buffer)的 channel 概念,以避免阻塞 channel 的傳送, 並嘗試優先推送佇列中較新的訊息,而非較舊的訊息。
若 channel 已滿且未能及時被消耗,此函式會移除 channel 中最舊的 訊息,然後將取得的訊息推送到尾端,實際上讓此 channel 成為一個 滾動式緩衝區。
透過此函式傳遞資料時,有可能會遺失資料,但僅限於 channel 緩衝區 已滿且未能及時被消耗的情況,這種情況下捨棄訊息很可能仍是最好的 選擇。此函式使用 waitgroup,讓每個 channel 能同時嘗試傳送,因此 此函式的總阻塞時間為「O(1)」而非「O(n)」。