Documentation ¶
Index ¶
- Variables
- func DurationToHuman(d time.Duration) (str string)
- func ExpandHome(path string) string
- func FileExists(filename string) bool
- func InIntList(haystack []int, needle int) bool
- func InStringList(haystack []string, needle string) bool
- func InStringListAll(haystack []string, needles []string) bool
- func ParseFutureTime(s string, now time.Time) (time.Time, error)
- func ParsePriority(priority string) (int, error)
- func PriorityString(priority int) (string, error)
- func RandomString(length int) string
- func ShortTopicURL(s string) string
- func SplitNoEmpty(s string, sep string) []string
- type CachingEmbedFS
- type Limiter
Constants ¶
This section is empty.
Variables ¶
var ErrLimitReached = errors.New("limit reached")
ErrLimitReached is the error returned by the Limiter and LimitWriter when the predefined limit has been reached
Functions ¶
func DurationToHuman ¶ added in v1.3.0
DurationToHuman converts a duration to a human readable format
func ExpandHome ¶ added in v1.8.0
ExpandHome replaces "~" with the user's home directory
func FileExists ¶
FileExists checks if a file exists, and returns true if it does
func InStringList ¶ added in v1.5.2
InStringList returns true if needle is contained in haystack
func InStringListAll ¶ added in v1.8.0
InStringListAll returns true if all needles are contained in haystack
func ParseFutureTime ¶ added in v1.6.0
ParseFutureTime parses a date/time string to a time.Time. It supports unix timestamps, durations and natural language dates
func ParsePriority ¶ added in v1.8.0
ParsePriority parses a priority string into its equivalent integer value
func PriorityString ¶ added in v1.9.0
PriorityString converts a priority number to a string
func RandomString ¶
RandomString returns a random string with a given length
func ShortTopicURL ¶ added in v1.9.0
ShortTopicURL shortens the topic URL to be human-friendly, removing the http:// or https://
func SplitNoEmpty ¶ added in v1.8.0
SplitNoEmpty splits a string using strings.Split, but filters out empty strings
Types ¶
type CachingEmbedFS ¶ added in v1.5.0
CachingEmbedFS is a wrapper around embed.FS that allows setting a ModTime, so that the default static file server can send 304s back. It can be used like this:
var ( //go:embed docs docsStaticFs embed.FS docsStaticCached = &util.CachingEmbedFS{ModTime: time.Now(), FS: docsStaticFs} ) http.FileServer(http.FS(docsStaticCached)).ServeHTTP(w, r)
type Limiter ¶ added in v1.1.3
type Limiter struct {
// contains filtered or unexported fields
}
Limiter is a helper that allows adding values up to a well-defined limit. Once the limit is reached ErrLimitReached will be returned. Limiter may be used by multiple goroutines.
func NewLimiter ¶ added in v1.1.3
NewLimiter creates a new Limiter
func (*Limiter) Add ¶ added in v1.1.3
Add adds n to the limiters internal value, but only if the limit has not been reached. If the limit would be exceeded after adding n, ErrLimitReached is returned.
func (*Limiter) Set ¶ added in v1.1.3
Set sets the value of the limiter to n. This function ignores the limit. It is meant to set the value based on reality.