utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcctInfo

func AcctInfo(acct string) (username, host string)

AcctInfo splits an account string into a username and host.

func Contains

func Contains[T comparable](list []T, item T) bool

Contains returns true if the list contains the item, false otherwise.

func GetFieldsAttributes

func GetFieldsAttributes(values map[string][]string) (fields []accountField)

GetFieldsAttributes converts a map of fields to a slice of accountFields The map of fields is expected to have keys in the form fields_attributes[<index>][<tag>] Where <index> is an integer and <tag> is one of "name" or "value". The order of the accountFields in the returned slice is determined by the order of the <index> values.

func GetHeaderToken

func GetHeaderToken(header http.Header) (string, error)

GetHeaderToken extracts the token from the Authorization header, if any.

func GetMentions

func GetMentions(text string) []string

func JoinURL

func JoinURL(server string, p ...string) string

func SliceIfNull

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

SliceIfNull returns the given slice if it is not nil, or an empty slice if it is nil.

func StrEvaluation

func StrEvaluation(str ...string) (v string, ok bool)

StrEvaluation evaluates a list of strings and returns the first non-empty string, or an empty string if no non-empty strings are found.

func Unique

func Unique[T comparable](list []T) []T

Unique returns a new list containing only the unique elements of list. The order of the elements is preserved.

Types

type Map

type Map = map[string]any

type StrMap

type StrMap = map[string]string

Jump to

Keyboard shortcuts

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