Documentation ¶
Index ¶
- Constants
- func Chunks[T any](slice []T, chunkSize int) [][]T
- func ConstantTimeEq(s1, s2 string) bool
- func DetectLanguage(detector lingua.LanguageDetector, text string) (langCode string, confidence float64)
- func Do(req *http.Request, maxRetries ...int) (*http.Response, error)
- func Get(ctx context.Context, uri string, maxRetries ...int) (*http.Response, error)
- func JSON(input any) ([]byte, error)
- func MapKeys[K comparable, V any](datamap map[K]V) []K
- func MarkdownEmail(email string) string
- func MarkdownLink(link string) string
- func MarkdownMXID(mxid string) string
- func MarkdownRender(mdtext string) (text, html string)
- func MayTemplate(tplString string, vars any) string
- func MergeSlices[K comparable](slices ...[]K) []K
- func NewContext(parent ...context.Context) context.Context
- func ParseURL(uri string) *url.URL
- func PoolProgress(wp *workpool.WorkPool, callback func(), optionalDuration ...time.Duration)
- func RemoveFromSlice[K comparable](base, toRemove []K) []K
- func ServerFrom(matrixID string) string
- func SetLogLevel(level string)
- func SetName(name string)
- func SetSentryDSN(dsn string)
- func SliceToString(slice []string, delimiter string, hook func(string) string) string
- func StartSpan(ctx context.Context, operation string) *sentry.Span
- func StringToInt(value string, optionalDefaultValue ...int) int
- func StringToSlice(value string, optionalDefaultValue ...string) []string
- func Template(tplString string, vars any) (string, error)
- func Truncate(s string, length int) string
- func URLSafeDecode(safeString string) string
- func URLSafeEncode(unsafeString string) string
- func Uniq[T comparable](slice []T) []T
- func ValuesOrDefault(values url.Values, defaultEncoded string) string
- type List
Constants ¶
const ( // DefaultTimeout for http requests DefaultTimeout = 120 * time.Second // MaxRetries for http requests MaxRetries = 5 // RetryDelay for http requests RetryDelay = 5 * time.Second )
const UnknownLang = "-"
Variables ¶
This section is empty.
Functions ¶
func ConstantTimeEq ¶
ConstantTimeEq checks if 2 strings are equal in constant time
func DetectLanguage ¶
func DetectLanguage(detector lingua.LanguageDetector, text string) (langCode string, confidence float64)
DetectLanguage and return it's ISO 639-1 code and confidence
func MapKeys ¶
func MapKeys[K comparable, V any](datamap map[K]V) []K
MapKeys returns keys of the map
func MarkdownEmail ¶
MarkdownEmail returns markdown link to email
func MarkdownMXID ¶
MarkdownMXID returns markdown link to MXID
func MarkdownRender ¶
MarkdownRender coverts markdown text into text and html forms
func MayTemplate ¶
func MergeSlices ¶
func MergeSlices[K comparable](slices ...[]K) []K
MergeSlices and remove duplicates
func NewContext ¶
NewContext creates a new context with a logger and sentry hub
func PoolProgress ¶
func RemoveFromSlice ¶
func RemoveFromSlice[K comparable](base, toRemove []K) []K
RemoveFromSlice removes elements of toRemove from base slice
func ServerFrom ¶
Server returns server name from the matrix ID (room id/alias, user ID, etc)
func SliceToString ¶
SliceToString converts slice of strings into single string (using strings.Join) with optional hook
func StartSpan ¶
StartSpan starts a new span, and if there is no transaction, it starts a new transaction
func StringToInt ¶
StringToInt converts string to int with optional default value
func StringToSlice ¶
StringToSlice converts comma-separated string to slice with optional default value
func URLSafeDecode ¶
URLSafeDecode decodes url-safe string into the original form
func URLSafeEncode ¶
URLSafeEncode encodes url-unsafe string into url-safe form
Types ¶
type List ¶
type List[T comparable, V any] struct { // contains filtered or unexported fields }
List is unique list
func NewListFromSlice ¶
func NewListFromSlice[T comparable](slice []T) *List[T, T]
NewListFromSlice creates a new list and popupates it from slice
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]) RemoveSlice ¶
func (l *List[T, V]) RemoveSlice(dataslice []T)
RemoveSlice removes items from data using slice