util

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GJSONEscaper = strings.NewReplacer(
	`\`, `\\`,
	".", `\.`,
	"|", `\|`,
	"#", `\#`,
	"@", `\@`,
	"*", `\*`,
	"?", `\?`)
View Source
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).

Functions

func ExtensionFromMimetype

func ExtensionFromMimetype(mimetype string) string

func GJSONPath added in v0.12.2

func GJSONPath(path ...string) string

func MarshalAndDeleteEmpty added in v0.12.1

func MarshalAndDeleteEmpty(marshalable interface{}, paths []string) ([]byte, error)

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 RandomBytes(n int) []byte

func RandomString added in v0.12.0

func RandomString(n int) string

RandomString generates a random string of the given length.

func RandomToken added in v0.12.1

func RandomToken(namespace string, randomLength int) string

Types

type DualError added in v0.12.0

type DualError struct {
	High error
	Low  error
}

func NewDualError added in v0.12.0

func NewDualError(high, low error) DualError

func (DualError) Error added in v0.12.0

func (err DualError) Error() string

func (DualError) Is added in v0.12.0

func (err DualError) Is(other error) bool

func (DualError) Unwrap added in v0.12.0

func (err DualError) Unwrap() error

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.

Jump to

Keyboard shortcuts

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