Documentation
¶
Index ¶
- Variables
- func CallerWithFunctionName(pc uintptr, file string, line int) string
- func ExtensionFromMimetype(mimetype string) string
- func FormatDuration(d time.Duration) string
- func GJSONPath(path ...string) string
- func MapRingBuffer[Key comparable, Value, Output any](rb *RingBuffer[Key, Value], callback func(key Key, val Value) (Output, error)) ([]Output, error)
- func MarshalAndDeleteEmpty(marshalable interface{}, paths []string) ([]byte, error)
- func RandomBytes(n int) []byte
- func RandomString(n int) string
- func RandomToken(namespace string, randomLength int) string
- type DualError
- type ReturnableOnce
- type RingBuffer
- func (rb *RingBuffer[Key, Value]) Contains(val Key) bool
- func (rb *RingBuffer[Key, Value]) Get(key Key) (val Value, found bool)
- func (rb *RingBuffer[Key, Value]) Iter(callback func(key Key, val Value) error) error
- func (rb *RingBuffer[Key, Value]) Push(key Key, val Value)
- func (rb *RingBuffer[Key, Value]) Replace(key Key, val Value) bool
- func (rb *RingBuffer[Key, Value]) Size() int
- type SyncMap
- func (sm *SyncMap[Key, Value]) Clone() *SyncMap[Key, Value]
- func (sm *SyncMap[Key, Value]) CopyData() map[Key]Value
- func (sm *SyncMap[Key, Value]) Delete(key Key)
- func (sm *SyncMap[Key, Value]) Get(key Key) (value Value, ok bool)
- func (sm *SyncMap[Key, Value]) GetOrSet(key Key, value Value) (actual Value, wasGet bool)
- func (sm *SyncMap[Key, Value]) Pop(key Key) (value Value, ok bool)
- func (sm *SyncMap[Key, Value]) Set(key Key, value Value)
- func (sm *SyncMap[Key, Value]) Swap(key Key, value Value) (oldValue Value, wasReplaced bool)
Constants ¶
This section is empty.
Variables ¶
var ( // StopIteration can be returned by the RingBuffer.Iter or MapRingBuffer callbacks to stop iteration immediately. StopIteration = errors.New("stop iteration") // SkipItem can be returned by the MapRingBuffer callback to skip adding a specific item. SkipItem = errors.New("skip item") )
var Day = 24 * time.Hour
var GJSONEscaper = strings.NewReplacer(
`\`, `\\`,
".", `\.`,
"|", `\|`,
"#", `\#`,
"@", `\@`,
"*", `\*`,
"?", `\?`)
var MimeExtensionSanityOverrides = map[string]string{
"image/png": ".png",
"image/webp": ".webp",
"image/jpeg": ".jpg",
"image/tiff": ".tiff",
"image/heif": ".heic",
"image/heic": ".heic",
"audio/mpeg": ".mp3",
"audio/ogg": ".ogg",
"audio/webm": ".webm",
"audio/x-caf": ".caf",
"video/mp4": ".mp4",
"video/mpeg": ".mpeg",
"video/webm": ".webm",
"text/plain": ".txt",
"text/html": ".html",
"application/xml": ".xml",
}
MimeExtensionSanityOverrides includes extensions for various common mimetypes.
This is necessary because sometimes the OS mimetype database and Go interact in weird ways, which causes very obscure extensions to be first in the array for common mimetypes (e.g. image/jpeg -> .jpe, text/plain -> ,v).
var Week = 7 * Day
Functions ¶
func CallerWithFunctionName ¶ added in v0.15.2
CallerWithFunctionName is an implementation for zerolog.CallerMarshalFunc that includes the caller function name in addition to the file and line number.
Use as
zerolog.CallerMarshalFunc = util.CallerWithFunctionName
func ExtensionFromMimetype ¶
func FormatDuration ¶ added in v0.15.3
func MapRingBuffer ¶ added in v0.15.1
func MapRingBuffer[Key comparable, Value, Output any](rb *RingBuffer[Key, Value], callback func(key Key, val Value) (Output, error)) ([]Output, error)
func MarshalAndDeleteEmpty ¶ added in v0.12.1
MarshalAndDeleteEmpty marshals a JSON object, then uses gjson to delete empty objects at the given gjson paths.
This can be used as a convenient way to create a marshaler that omits empty non-pointer structs. See mautrix.RespSync for example.
func RandomBytes ¶ added in v0.12.0
func RandomString ¶ added in v0.12.0
RandomString generates a random string of the given length.
func RandomToken ¶ added in v0.12.1
Types ¶
type DualError ¶ added in v0.12.0
func NewDualError ¶ added in v0.12.0
type ReturnableOnce ¶ added in v0.14.0
type ReturnableOnce[Value any] struct { // contains filtered or unexported fields }
ReturnableOnce is a wrapper for sync.Once that can return a value
func (*ReturnableOnce[Value]) Do ¶ added in v0.14.0
func (ronce *ReturnableOnce[Value]) Do(fn func() (Value, error)) (Value, error)
type RingBuffer ¶ added in v0.14.0
type RingBuffer[Key comparable, Value any] struct { // contains filtered or unexported fields }
func NewRingBuffer ¶ added in v0.14.0
func NewRingBuffer[Key comparable, Value any](size int) *RingBuffer[Key, Value]
func (*RingBuffer[Key, Value]) Contains ¶ added in v0.14.0
func (rb *RingBuffer[Key, Value]) Contains(val Key) bool
func (*RingBuffer[Key, Value]) Get ¶ added in v0.14.0
func (rb *RingBuffer[Key, Value]) Get(key Key) (val Value, found bool)
func (*RingBuffer[Key, Value]) Iter ¶ added in v0.15.1
func (rb *RingBuffer[Key, Value]) Iter(callback func(key Key, val Value) error) error
func (*RingBuffer[Key, Value]) Push ¶ added in v0.14.0
func (rb *RingBuffer[Key, Value]) Push(key Key, val Value)
func (*RingBuffer[Key, Value]) Replace ¶ added in v0.14.0
func (rb *RingBuffer[Key, Value]) Replace(key Key, val Value) bool
func (*RingBuffer[Key, Value]) Size ¶ added in v0.15.1
func (rb *RingBuffer[Key, Value]) Size() int
type SyncMap ¶ added in v0.14.0
type SyncMap[Key comparable, Value any] struct { // contains filtered or unexported fields }
SyncMap is a simple map with a built-in mutex.
func NewSyncMap ¶ added in v0.14.0
func NewSyncMap[Key comparable, Value any]() *SyncMap[Key, Value]
func (*SyncMap[Key, Value]) CopyData ¶ added in v0.14.0
func (sm *SyncMap[Key, Value]) CopyData() map[Key]Value
CopyData returns a copy of the data in the map as a normal (non-atomic) map.
func (*SyncMap[Key, Value]) Delete ¶ added in v0.14.0
func (sm *SyncMap[Key, Value]) Delete(key Key)
Delete removes a key from the map.
func (*SyncMap[Key, Value]) Get ¶ added in v0.14.0
Get gets a value in the map.
The boolean return parameter is the same as with normal Go map access (true if the key exists, false if not).
func (*SyncMap[Key, Value]) GetOrSet ¶ added in v0.14.0
GetOrSet gets a value in the map if the key already exists, otherwise inserts the given value and returns it.
The boolean return parameter is true if the key already exists, and false if the given value was inserted.
func (*SyncMap[Key, Value]) Pop ¶ added in v0.14.0
Pop removes a key from the map and returns the old value.
The boolean return parameter is the same as with normal Go map access (true if the key exists, false if not).
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package base58 provides an API for working with modified base58 and Base58Check encodings.
|
Package base58 provides an API for working with modified base58 and Base58Check encodings. |
Package variationselector provides utility functions for adding and removing emoji variation selectors (16) that matches the suggestions in the Matrix spec.
|
Package variationselector provides utility functions for adding and removing emoji variation selectors (16) that matches the suggestions in the Matrix spec. |