util

package
v8.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFileModificationTime

func GetFileModificationTime(fn string) (int64, error)

get the file modification times for a configuration file.

func HostNameToShort

func HostNameToShort(host string) string

HostNameToShort takes a hostname which may be a Fully Qualified Domain Name or a short hostname, and returns the short hostname. If host is already a short hostname, it is returned unmodified.

func MakeNoCloser

func MakeNoCloser(wr io.Writer) io.WriteCloser

Types

type AtomicPtr

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

AtomicPtr provides atomic getting and setting of a pointer. It may be default-constructed or via NewAtomicPtr. It must not be copied after first use.

No further synchronization is provided, besides the atomic pointer exchange. If value pointed to is modified concurrently, users must perform their own synchronization.

func NewAtomicPtr

func NewAtomicPtr[T any](ptr *T) *AtomicPtr[T]

NewAtomicPtr creates a new AtomicPtr[T] initialized with ptr.

func (*AtomicPtr[T]) Get

func (ag *AtomicPtr[T]) Get() *T

Get returns the pointer. This is safe for multiple concurrent goroutines.

No further synchronization is provided, besides the atomic pointer exchange. If the returned object is modified concurrently, users must perform their own synchronization.

func (*AtomicPtr[T]) Set

func (ag *AtomicPtr[T]) Set(ptr *T)

Set sets the AtomicPtr's pointer. This is safe for multiple concurrent goroutines.

No further synchronization is provided, besides the atomic pointer exchange. If the set object is modified concurrently, users must perform their own synchronization

type ConfigFile

type ConfigFile struct {
	Filename       string
	LastModifyTime int64
}

type NoCloser

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

WriteNoCloser wraps an io.Writer and returns an io.WriteCloser for which Close will be a no-op.

This allows for passing a WriteCloser to something that ordinarily takes ownership and closes, Without that Close() closing the real Writer. For example, to prevent closing os.Stdout.

This can also be used to turn an io.Writer into an io.WriteCloser.

func (NoCloser) Close

func (nw NoCloser) Close() error

func (NoCloser) Write

func (nc NoCloser) Write(p []byte) (n int, err error)

type NopWriter

type NopWriter struct{}

NopWriter is a no-op io.WriteCloser. It always returns the length of the given bytes as written. Writes to this go nowhere. Close may be called, and is also a no-op.

func (NopWriter) Close

func (nw NopWriter) Close() error

func (NopWriter) Write

func (nw NopWriter) Write(p []byte) (n int, err error)

Write implements io.Writer. It always returns the length of the given bytes as written.

type SyncMap

type SyncMap[KT any, VT any] struct {
	// contains filtered or unexported fields
}

SyncMap is a strongly-typed sync.Map.

func (*SyncMap[KT, VT]) Load

func (sm *SyncMap[KT, VT]) Load(key KT) (VT, bool)

func (*SyncMap[KT, VT]) LoadOrStore

func (sm *SyncMap[KT, VT]) LoadOrStore(key KT, val VT) (actual VT, loaded bool)

func (*SyncMap[KT, VT]) Range

func (sm *SyncMap[KT, VT]) Range(f func(key KT, value VT) bool)

func (*SyncMap[KT, VT]) Store

func (sm *SyncMap[KT, VT]) Store(key KT, val VT)

Jump to

Keyboard shortcuts

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