Documentation
¶
Index ¶
- Constants
- Variables
- func Action(c cmdOptions) cli.ActionFunc
- func AtoiU32(s string) (uint32, error)
- func CollectStack() []byte
- func ConfigureAcronym(key, val string)
- func ContentDisposition(hdr http.Header, contentType, filename string, attachment bool)
- func CryptRandSeq(n int) string
- func DefaultIfNilOrZero[T comparable](v *T, def T) T
- func FromPanicValue(i any) error
- func Keys[K comparable, V any](m map[K]V) []K
- func LoggingRoundTripper() http.RoundTripper
- func NanoID(n int) string
- func NilIfZero[T comparable](val T) *T
- func PGUUID(u *uuid.UUID) pgtype.UUID
- func PtrTo[T any](t T) *T
- func RandSeq(n int) string
- func RemoteAddr(as string) (netip.Addr, error)
- func ToCamel(s string) string
- func ToDelimited(s string, delimiter uint8) string
- func ToKebab(s string) string
- func ToLowerCamel(s string) string
- func ToScreamingDelimited(s string, delimiter uint8, ignore string, screaming bool) string
- func ToScreamingKebab(s string) string
- func ToScreamingSnake(s string) string
- func ToSnake(s string) string
- func ToSnakeWithIgnore(s string, ignore string) string
- func WithDefaultBounds(i Interval) tbOpt
- func WithLocation(l *time.Location) tbOpt
- func ZeroFields(s any)
- func ZeroIfNil[T any](v *T) T
- type ErrInvalidInterval
- type Interval
- type Pagination
- type SortDirection
- type TimeBounder
- func (tb *TimeBounder) Bounds(t time.Time) (lowerBound, upperBound time.Time)
- func (tb *TimeBounder) GetDailyBounds(date time.Time) (lowerBound, upperBound time.Time)
- func (tb *TimeBounder) GetMonthlyBounds(date time.Time) (lowerBound, upperBound time.Time)
- func (tb *TimeBounder) GetQuarterlyBounds(date time.Time) (lowerBound, upperBound time.Time)
- func (tb *TimeBounder) GetWeeklyBounds(date time.Time) (lowerBound, upperBound time.Time)
- func (tb *TimeBounder) GetYearlyBounds(date time.Time) (lowerBound, upperBound time.Time)
- type TimeRange
Constants ¶
const ( AppName = "stillbox" EnvPrefix = "STILLBOX_" )
const ( DaysInWeek = 7 MonthsInQuarter = 3 )
const (
TimeFormat = "Jan 2 15:04:05"
)
Variables ¶
var ( ErrPageOutOfRange = errors.New("requested page out of range") ErrBadOrder = errors.New("invalid order") ErrBadDirection = errors.New("invalid direction") )
var ( FuncMap = template.FuncMap{ "f": fmtFloat, "dict": func(values ...any) (map[string]any, error) { if len(values)%2 != 0 { return nil, errors.New("invalid dict call") } dict := make(map[string]any, len(values)/2) for i := 0; i < len(values); i += 2 { key, ok := values[i].(string) if !ok { return nil, errors.New("dict keys must be strings") } dict[key] = values[i+1] } return dict, nil }, "formTime": func(t jsontypes.Time) string { return time.Time(t).Format("2006-01-02T15:04") }, "ago": func(s string) (string, error) { d, err := time.ParseDuration(s) if err != nil { return "", err } return time.Now().Add(-d).Format("2006-01-02T15:04"), nil }, } )
Functions ¶
func Action ¶
func Action(c cmdOptions) cli.ActionFunc
func CollectStack ¶
func CollectStack() []byte
func ConfigureAcronym ¶
func ConfigureAcronym(key, val string)
ConfigureAcronym allows you to add additional words which will be considered acronyms
func ContentDisposition ¶
func CryptRandSeq ¶
func DefaultIfNilOrZero ¶
func DefaultIfNilOrZero[T comparable](v *T, def T) T
func FromPanicValue ¶
FromPanicValue is used to recover errgroup panics.
func Keys ¶
func Keys[K comparable, V any](m map[K]V) []K
Keys returns an unsorted slice of the keys in m
func LoggingRoundTripper ¶
func LoggingRoundTripper() http.RoundTripper
func NilIfZero ¶
func NilIfZero[T comparable](val T) *T
func ToDelimited ¶
ToDelimited converts a string to delimited.snake.case (in this case `delimiter = '.'`)
func ToLowerCamel ¶
ToLowerCamel converts a string to lowerCamelCase
func ToScreamingDelimited ¶
ToScreamingDelimited converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `delimiter = '.'; screaming = true`) or delimited.snake.case (in this case `delimiter = '.'; screaming = false`)
func ToScreamingKebab ¶
ToScreamingKebab converts a string to SCREAMING-KEBAB-CASE
func ToScreamingSnake ¶
ToScreamingSnake converts a string to SCREAMING_SNAKE_CASE
func ToSnakeWithIgnore ¶
func WithDefaultBounds ¶
func WithDefaultBounds(i Interval) tbOpt
func WithLocation ¶
func ZeroFields ¶
func ZeroFields(s any)
ZeroFields takes a struct or a pointer to struct and if any pointer fields point to a zero value for the pointed type, they are set to nil. It also recurses into embedded fields.
Types ¶
type ErrInvalidInterval ¶
type ErrInvalidInterval string
func (ErrInvalidInterval) Error ¶
func (in ErrInvalidInterval) Error() string
type Pagination ¶
Pagination describes a request for a particular page and records per page.
func (Pagination) OffsetPerPage ¶
func (p Pagination) OffsetPerPage(perPageDefault int) (offset int32, perPage int32)
OffsetPerPage computes a sane offset and records per page based on p and perPageDefault.
type SortDirection ¶
type SortDirection string
const ( DirAsc SortDirection = "asc" DirDesc SortDirection = "desc" )
func (*SortDirection) DirString ¶
func (t *SortDirection) DirString(def SortDirection) string
DirString returns the direction or a default.
func (*SortDirection) IsValid ¶
func (t *SortDirection) IsValid() bool
IsValid returns whether t is valid.
type TimeBounder ¶
type TimeBounder struct {
// contains filtered or unexported fields
}
func NewTimeBounder ¶
func NewTimeBounder(opts ...tbOpt) *TimeBounder
func (*TimeBounder) Bounds ¶
func (tb *TimeBounder) Bounds(t time.Time) (lowerBound, upperBound time.Time)
func (*TimeBounder) GetDailyBounds ¶
func (tb *TimeBounder) GetDailyBounds(date time.Time) (lowerBound, upperBound time.Time)
func (*TimeBounder) GetMonthlyBounds ¶
func (tb *TimeBounder) GetMonthlyBounds(date time.Time) (lowerBound, upperBound time.Time)
func (*TimeBounder) GetQuarterlyBounds ¶
func (tb *TimeBounder) GetQuarterlyBounds(date time.Time) (lowerBound, upperBound time.Time)
func (*TimeBounder) GetWeeklyBounds ¶
func (tb *TimeBounder) GetWeeklyBounds(date time.Time) (lowerBound, upperBound time.Time)
func (*TimeBounder) GetYearlyBounds ¶
func (tb *TimeBounder) GetYearlyBounds(date time.Time) (lowerBound, upperBound time.Time)