kit

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: LGPL-3.0 Imports: 15 Imported by: 2

README

kit - auxilary utilities

  • auxilary functions: Go Reference
  • format subpackage: Go Reference
  • template subpackage: Go Reference
  • workpool subpackage: Go Reference

This is a shared utils package, used by other etke.cc projects. Check godoc for the details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

func Chunk[T any](items []T, chunkSize int) (chunks [][]T)

Chunk slices into chunks

func Eq

func Eq(s1, s2 string) bool

Eq checks if 2 strings are equal in constant time

func Hash

func Hash(str string) string

Hash returns sha256 hash of a string

func MapKeys

func MapKeys[T cmp.Ordered, V any](data map[T]V) []T

MapKeys returns map keys only

func MergeMapKeys

func MergeMapKeys[V any](m map[string]V, adds ...map[string]V) []string

MergeMapKeys returns map keys only from multiple maps

func MergeSlices

func MergeSlices[K cmp.Ordered](slices ...[]K) []K

MergeSlices and remove duplicates

func RemoveFromSlice

func RemoveFromSlice[K comparable](base, toRemove []K) []K

RemoveFromSlice removes elements of toRemove from base slice

func Reverse added in v1.3.0

func Reverse[T any](slice []T)

Reverse slice

func SliceToString

func SliceToString(slice []string, delimiter string, hook func(string) string) string

SliceToString converts slice of strings into single string (using strings.Join) with optional hook

func StringToInt

func StringToInt(value string, optionalDefaultValue ...int) int

StringToInt converts string to int with optional default value

func StringToSlice

func StringToSlice(value string, optionalDefaultValue ...string) []string

StringToSlice converts comma-separated string to slice with optional default value

func Truncate

func Truncate(s string, length int) string

Truncate truncates a string to a specified length, adding "..." if truncated

func Uniq

func Uniq(slice []string) []string

Uniq removes duplicates from slice

func Unquote

func Unquote(s string) string

Unquote is a wrapper around strconv.Unquote, but returns original string if unquoting fails

Types

type ErrorResponse

type ErrorResponse struct {
	StatusCode int    `json:"-"`     // HTTP status code, optional, not serialized
	Err        string `json:"error"` // Error message
}

ErrorResponse represents an error response

func NewErrorResponse

func NewErrorResponse(err error, optionalStatusCode ...int) *ErrorResponse

NewErrorResponse creates a new error response

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

Error returns the error message

type List

type List[T cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

List is unique list, V is used only for AddMapKeys

func NewList

func NewList[T cmp.Ordered, V any]() *List[T, V]

NewList creates new list

func NewListFrom

func NewListFrom[T cmp.Ordered](slice []T) *List[T, T]

NewListFrom creates a new list and popupates it from slice

func (*List[T, V]) Add

func (l *List[T, V]) Add(item T)

Add item to the list

func (*List[T, V]) AddMapKeys

func (l *List[T, V]) AddMapKeys(datamap map[T]V)

AddMapKeys adds keys from map to the list

func (*List[T, V]) AddSlice

func (l *List[T, V]) AddSlice(dataslice []T)

AddSlice adds keys from slice to the list

func (*List[T, V]) Len

func (l *List[T, V]) Len() int

Len - data length

func (*List[T, V]) Remove

func (l *List[T, V]) Remove(item T)

Remove item from list

func (*List[T, V]) RemoveSlice

func (l *List[T, V]) RemoveSlice(dataslice []T)

RemoveSlice removes items from data using slice

func (*List[T, V]) Slice

func (l *List[T, V]) Slice() []T

Slice returns list data as slice

type MatrixError

type MatrixError struct {
	Code string `json:"errcode"`
	Err  string `json:"error"`
}

MatrixError represents an error response from the Matrix API

func MatrixErrorFrom

func MatrixErrorFrom(r io.Reader) *MatrixError

MatrixErrorFrom creates a new Matrix error from io.Reader

func NewMatrixError

func NewMatrixError(code, err string) *MatrixError

NewMatrixError creates a new Matrix error

func (MatrixError) Error

func (e MatrixError) Error() string

Error returns the error message

type Mutex added in v1.4.0

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

Mutex is a key-based mutex that allows locking and unlocking based on a key.

func NewMutex added in v1.4.0

func NewMutex() *Mutex

NewMutex creates a new Mutex instance

func (*Mutex) Lock added in v1.4.0

func (km *Mutex) Lock(key string)

Lock locks the mutex for a specific key.

func (*Mutex) Unlock added in v1.4.0

func (km *Mutex) Unlock(key string)

Unlock unlocks the mutex for a specific key.

Directories

Path Synopsis
package format (markdown) is a markdown to html converter, heavily inspired by the mautrix-go/format package
package format (markdown) is a markdown to html converter, heavily inspired by the mautrix-go/format package
Package template provides a handy wrapper around text/template package.
Package template provides a handy wrapper around text/template package.
package workpool provides a simple work pool implementation
package workpool provides a simple work pool implementation

Jump to

Keyboard shortcuts

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