system

package
v1.11.11 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 16 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLockerLocked = errors.Sentinel("locker: cannot acquire lock, already locked")
View Source
var Version = "develop"

Functions

func FirstNotEmpty added in v1.3.0

func FirstNotEmpty(v ...string) string

FirstNotEmpty returns the first string passed in that is not an empty value.

func FormatBytes added in v1.2.0

func FormatBytes[T int | int16 | int32 | int64 | uint | uint16 | uint32 | uint64](b T) string

func GetDockerInfo added in v1.11.0

func GetDockerInfo(ctx context.Context) (types.Version, system.Info, error)

func MustInt added in v1.3.0

func MustInt(v string) int

func ScanReader added in v1.2.0

func ScanReader(r io.Reader, callback func(line []byte)) error

ScanReader reads up to 64KB of line from the reader and emits that value over the websocket. If a line exceeds that size, it is truncated and only that amount is sent over.

Types

type Atomic added in v1.11.0

type Atomic[T any] struct {
	// contains filtered or unexported fields
}

func NewAtomic added in v1.11.0

func NewAtomic[T any](v T) *Atomic[T]

func (*Atomic[T]) Load added in v1.11.0

func (a *Atomic[T]) Load() T

Load loads the string value and returns it.

func (*Atomic[T]) MarshalJSON added in v1.11.0

func (a *Atomic[T]) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Atomic[T] value into JSON.

func (*Atomic[T]) Store added in v1.11.0

func (a *Atomic[T]) Store(v T)

Store stores the string value passed atomically.

func (*Atomic[T]) UnmarshalJSON added in v1.11.0

func (a *Atomic[T]) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the JSON value into the Atomic[T] value.

type AtomicBool

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

func NewAtomicBool added in v1.2.0

func NewAtomicBool(v bool) *AtomicBool

func (*AtomicBool) Load added in v1.2.0

func (ab *AtomicBool) Load() bool

func (*AtomicBool) MarshalJSON added in v1.2.0

func (ab *AtomicBool) MarshalJSON() ([]byte, error)

func (*AtomicBool) Store added in v1.2.0

func (ab *AtomicBool) Store(v bool)

func (*AtomicBool) SwapIf added in v1.2.0

func (ab *AtomicBool) SwapIf(v bool) bool

SwapIf stores the value "v" if the current value stored in the AtomicBool is the opposite boolean value. If successfully swapped, the response is "true", otherwise "false" is returned.

func (*AtomicBool) UnmarshalJSON added in v1.2.0

func (ab *AtomicBool) UnmarshalJSON(b []byte) error

type AtomicString added in v1.1.0

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

AtomicString allows for reading/writing to a given struct field without having to worry about a potential race condition scenario. Under the hood it uses a simple sync.RWMutex to control access to the value.

func NewAtomicString added in v1.1.0

func NewAtomicString(v string) *AtomicString

func (*AtomicString) Load added in v1.1.0

func (as *AtomicString) Load() string

Load loads the string value and returns it.

func (*AtomicString) MarshalJSON added in v1.2.0

func (as *AtomicString) MarshalJSON() ([]byte, error)

func (*AtomicString) Store added in v1.1.0

func (as *AtomicString) Store(v string)

Store stores the string value passed atomically.

func (*AtomicString) UnmarshalJSON added in v1.2.0

func (as *AtomicString) UnmarshalJSON(b []byte) error

type DockerCgroups added in v1.11.0

type DockerCgroups struct {
	Driver  string `json:"driver"`
	Version string `json:"version"`
}

type DockerContainers added in v1.11.0

type DockerContainers struct {
	Total   int `json:"total"`
	Running int `json:"running"`
	Paused  int `json:"paused"`
	Stopped int `json:"stopped"`
}

type DockerInformation added in v1.11.0

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

type DockerRunc struct {
	Version string `json:"version"`
}

type DockerStorage added in v1.11.0

type DockerStorage struct {
	Driver     string `json:"driver"`
	Filesystem string `json:"filesystem"`
}

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

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

func NewLocker added in v1.6.0

func NewLocker() *Locker

NewLocker returns a new Locker instance.

func (*Locker) Acquire added in v1.6.0

func (l *Locker) Acquire() error

Acquire will acquire the power lock if it is not currently locked. If it is already locked, acquire will fail to acquire the lock, and will return false.

func (*Locker) Destroy added in v1.6.0

func (l *Locker) Destroy()

Destroy cleans up the power locker by closing the channel.

func (*Locker) IsLocked added in v1.6.0

func (l *Locker) IsLocked() bool

IsLocked returns the current state of the locker channel. If there is currently a value in the channel, it is assumed to be locked.

func (*Locker) Release added in v1.6.0

func (l *Locker) Release()

Release will drain the locker channel so that we can properly re-acquire it at a later time. If the channel is not currently locked this function is a no-op and will immediately return.

func (*Locker) TryAcquire added in v1.6.0

func (l *Locker) TryAcquire(ctx context.Context) error

TryAcquire will attempt to acquire a power-lock until the context provided is canceled.

type Rate added in v1.6.0

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

Rate defines a rate limiter of n items (limit) per duration of time.

func NewRate added in v1.6.0

func NewRate(limit uint64, duration time.Duration) *Rate

func (*Rate) Reset added in v1.6.0

func (r *Rate) Reset()

Reset resets the internal state of the rate limiter back to zero.

func (*Rate) Try added in v1.6.0

func (r *Rate) Try() bool

Try returns true if under the rate limit defined, or false if the rate limit has been exceeded for the current duration.

type SinkName added in v1.6.1

type SinkName string

SinkName represents one of the registered sinks for a server.

const (
	// LogSink handles console output for game servers, including messages being
	// sent via Wings to the console instance.
	LogSink SinkName = "log"
	// InstallSink handles installation output for a server.
	InstallSink SinkName = "install"
)

type SinkPool added in v1.6.1

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

SinkPool represents a pool with sinks.

func NewSinkPool added in v1.6.1

func NewSinkPool() *SinkPool

NewSinkPool returns a new empty SinkPool. A sink pool generally lives with a server instance for its full lifetime.

func (*SinkPool) Destroy added in v1.6.1

func (p *SinkPool) Destroy()

Destroy destroys the pool by removing and closing all sinks and destroying all of the channels that are present.

func (*SinkPool) Off added in v1.6.1

func (p *SinkPool) Off(c chan []byte)

Off removes a given channel from the sink pool. If no matching sink is found this function is a no-op. If a matching channel is found, it will be removed.

func (*SinkPool) On added in v1.6.1

func (p *SinkPool) On(c chan []byte)

On adds a channel to the sink pool instance.

func (*SinkPool) Push added in v1.6.1

func (p *SinkPool) Push(data []byte)

Push sends a given message to each of the channels registered in the pool. This will use a Ring Buffer channel in order to avoid blocking the channel sends, and attempt to push though the most recent messages in the queue in favor of the oldest messages.

If the channel becomes full and isn't being drained fast enough, this function will remove the oldest message in the channel, and then push the message that it got onto the end, effectively making the channel a rolling buffer.

There is a potential for data to be lost when passing it through this function, but only in instances where the channel buffer is full and the channel is not drained fast enough, in which case dropping messages is most likely the best option anyways. This uses waitgroups to allow every channel to attempt its send concurrently thus making the total blocking time of this function "O(1)" instead of "O(n)".

type System added in v1.11.0

type System struct {
	Architecture  string `json:"architecture"`
	CPUThreads    int    `json:"cpu_threads"`
	MemoryBytes   int64  `json:"memory_bytes"`
	KernelVersion string `json:"kernel_version"`
	OS            string `json:"os"`
	OSType        string `json:"os_type"`
}

Jump to

Keyboard shortcuts

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