wwgo

package module
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayDiffInt added in v0.0.7

func ArrayDiffInt(a []int, b []int) []int

ArrayDiffInt returns a slice of all values from a that are not in b. Deprecated: use DiffSlice instead.

func ArrayDiffInt32 added in v0.0.2

func ArrayDiffInt32(a []int32, b []int32) []int32

ArrayDiffInt32 returns a slice of all values from a that are not in b. Deprecated: use DiffSlice instead.

func ArrayDiffStr added in v0.0.2

func ArrayDiffStr(a []string, b []string) []string

ArrayDiffStr returns a slice of all values from a that are not in b. Deprecated: use DiffSlice instead.

func ArrayDiffUuid added in v0.2.6

func ArrayDiffUuid(a []uuid.UUID, b []uuid.UUID) []uuid.UUID

ArrayDiffUuid returns a slice of all values from a that are not in b. Deprecated: use DiffSlice instead.

func ArrayDiffUuidRef added in v0.2.6

func ArrayDiffUuidRef(a []*uuid.UUID, b []*uuid.UUID) []*uuid.UUID

ArrayDiffUuidRef returns a slice of all values from a that are not in b. Deprecated: use DiffSlice instead.

func ArrayFillStr added in v0.0.2

func ArrayFillStr(value string, count int) []string

func ArrayFilterAndJoinStr added in v0.0.2

func ArrayFilterAndJoinStr(a []string, sep string) string

ArrayFilterAndJoinStr returns a string of all values from a that are not empty, joined by sep.

func ArrayFilterFnStr added in v0.0.2

func ArrayFilterFnStr(a []string, fn func(v string) bool) []string

ArrayFilterFnStr returns a slice of all values from a that pass the filter function. Deprecated: use FilterSlice instead.

func ArrayFilterStr added in v0.0.2

func ArrayFilterStr(a []string) []string

ArrayFilterStr returns a slice of all values from a that are not empty.

func ArrayIncludesInt added in v0.0.2

func ArrayIncludesInt(haystack []int, needle int) bool

ArrayIncludesInt returns true if the slice contains the value. Deprecated: use SliceIncludes instead.

func ArrayIncludesInt32 added in v0.0.2

func ArrayIncludesInt32(haystack []int32, needle int32) bool

ArrayIncludesInt32 returns true if the slice contains the value. Deprecated: use SliceIncludes instead.

func ArrayIncludesStr added in v0.0.2

func ArrayIncludesStr(haystack []string, needle string) bool

ArrayIncludesStr returns true if the slice contains the value. Deprecated: use SliceIncludes instead.

func ArrayIncludesUUID added in v0.0.2

func ArrayIncludesUUID(haystack []uuid.UUID, needle uuid.UUID) bool

ArrayIncludesUUID returns true if the slice contains the value. Deprecated: use SliceIncludes instead.

func ArrayMapStr added in v0.0.2

func ArrayMapStr(a []string, fn func(v string) string) []string

ArrayMapStr returns a slice of all values from a mapped by fn(). Deprecated: use MapSlice instead.

func BoolFromSqlTinyInt added in v0.0.2

func BoolFromSqlTinyInt(v int8) bool

func BoolRef added in v0.0.2

func BoolRef(v bool) *bool

BoolRef returns a fresh pointer for the value. Deprecated: use ToPtr instead.

func CliAsk

func CliAsk(question string, defaultAnswer string) string

func CliAskPassword

func CliAskPassword(question string) string

func CliAskRequired

func CliAskRequired(question string, defaultAnswer string) string

func CliConfirm

func CliConfirm(question string) bool

func DecimalFromRef added in v0.13.5

func DecimalFromRef(v *decimal.Decimal) decimal.Decimal

DecimalFromRef returns the value of the pointer, or the zero decimal if nil.

func DecimalRef added in v0.1.3

func DecimalRef(v decimal.Decimal) *decimal.Decimal

DecimalRef returns a fresh pointer for the value. Deprecated: use ToPtr instead.

func DecimalRefFromSql added in v0.2.0

func DecimalRefFromSql(v decimal.NullDecimal) *decimal.Decimal

DecimalRefFromSql will return nil for a 'null' SQL value.

func DerefPtrSlice added in v0.15.1

func DerefPtrSlice[T any](s []*T) []T

DerefPtrSlice converts a slice of pointers to a slice of values.

func DerefPtrSliceSlice added in v0.15.1

func DerefPtrSliceSlice[T any](s [][]*T) [][]T

DerefPtrSliceSlice converts a slice of slices of pointers to a slice of slices of values.

func DiffSlice added in v0.15.1

func DiffSlice[T comparable](a []T, b []T) []T

DiffSlice returns a slice of all values from a that are not in b.

func FilterSlice added in v0.15.1

func FilterSlice[T any](s []T, f func(T) bool) []T

FilterSlice returns a slice of all values from s that pass the filter function.

func FormatDate added in v0.0.2

func FormatDate(t time.Time, format string) string

FormatDate supports ordinal days.

func GenerateRandomKey added in v0.0.2

func GenerateRandomKey(length int) []byte

func GenerateRandomString added in v0.0.2

func GenerateRandomString(length int, charset []rune) string

func GqlTime added in v0.0.2

func GqlTime(v time.Time) string

func GqlTimeRefSql added in v0.0.2

func GqlTimeRefSql(v sql.NullTime) *string

func IfThenElse added in v0.15.1

func IfThenElse[T any](cond bool, t T, f T) T

IfThenElse is a ternary helper function.

func Int32FromRef added in v0.13.5

func Int32FromRef(v *int32) int32

Int32FromRef returns the value of the pointer, or 0 if nil.

func Int32MustParse added in v0.0.2

func Int32MustParse(v string) int32

func Int32Ref added in v0.0.2

func Int32Ref(v int32) *int32

Int32Ref returns a fresh pointer for the value. Deprecated: use ToPtr instead.

func Int64FromRef added in v0.13.5

func Int64FromRef(v *int64) int64

Int64FromRef returns the value of the pointer, or 0 if nil.

func Int64MustParse added in v0.0.2

func Int64MustParse(v string) int64

func Int64Ref added in v0.0.2

func Int64Ref(v int64) *int64

Int64Ref returns a fresh pointer for the value. Deprecated: use ToPtr instead.

func IntArray2StrArray added in v0.0.8

func IntArray2StrArray(in []int) []string

func IntFromRef added in v0.13.5

func IntFromRef(v *int) int

IntFromRef returns the value of the pointer, or 0 if nil.

func IntRef added in v0.0.2

func IntRef(v int) *int

IntRef returns a fresh pointer for the value. Deprecated: use ToPtr instead.

func IntRefFromSql added in v0.2.0

func IntRefFromSql(v sql.NullInt32) *int

IntRefFromSql will return nil for a 'null' SQL value.

func JoinIntArray added in v0.0.8

func JoinIntArray(in []int, sep string) string

func JoinStringers added in v0.16.5

func JoinStringers[T fmt.Stringer](items []T, sep string) string

func MapSlice added in v0.15.1

func MapSlice[IN any, OUT any](s []IN, f func(IN) OUT) []OUT

MapSlice returns a slice of all values from s mapped by f().

func NewDefaultLogger

func NewDefaultLogger() zerolog.Logger

func Plural added in v0.0.3

func Plural(count int, singular string, plural string) string

func PrintErrWithStack

func PrintErrWithStack(err error)

func RenderTemplatePlain added in v0.0.2

func RenderTemplatePlain(tplStr string, data interface{}) (string, error)

func ScreamingSnakeCaseToHuman added in v0.15.1

func ScreamingSnakeCaseToHuman(s string) string

ScreamingSnakeCaseToHuman converts HUMAN_READABLE to 'human readable'.

func SendSlackWebhook added in v0.6.4

func SendSlackWebhook(ctx context.Context, webhookUrl string, message SlackMessagePayload) error

func SliceIncludes added in v0.15.1

func SliceIncludes[T comparable](s []T, v T) bool

SliceIncludes returns true if the slice contains the value.

func SliceToPtrSlice added in v0.15.1

func SliceToPtrSlice[T any](s []T) []*T

SliceToPtrSlice converts a slice of values to a slice of pointers.

func SqlNullDecimalRef added in v0.2.0

func SqlNullDecimalRef(v *decimal.Decimal) decimal.NullDecimal

SqlNullDecimalRef will return a sql 'null' value if the pointer is nil.

func SqlNullInt32 added in v0.0.2

func SqlNullInt32(v int32) sql.NullInt32

SqlNullInt32 will return a sql 'null' value if the value is 0.

func SqlNullIntRef added in v0.1.3

func SqlNullIntRef(v *int) sql.NullInt32

SqlNullIntRef will return a sql 'null' value if the pointer is nil.

func SqlNullStr added in v0.0.2

func SqlNullStr(v string) sql.NullString

SqlNullStr will return a sql 'null' value if the string is empty.

func SqlNullStrRef added in v0.0.2

func SqlNullStrRef(v *string) sql.NullString

SqlNullStrRef will return a sql 'null' value if the pointer is nil.

func SqlNullTime added in v0.0.2

func SqlNullTime(v time.Time) sql.NullTime

SqlNullTime will return a sql 'null' value if the time is 0.

func SqlNullTimeRef added in v0.2.0

func SqlNullTimeRef(v *time.Time) sql.NullTime

SqlNullTimeRef will return a sql 'null' value if the pointer is nil.

func SqlNullUuid added in v0.1.5

func SqlNullUuid(v uuid.UUID) uuid.NullUUID

SqlNullUuid will return a sql 'null' value if the uuid is empty.

func SqlNullUuidRef added in v0.1.5

func SqlNullUuidRef(v *uuid.UUID) uuid.NullUUID

SqlNullUuidRef will return a sql 'null' value if the pointer is nil.

func SqlTimeToStrRef added in v0.0.2

func SqlTimeToStrRef(v sql.NullTime) *string

func SqlTinyIntFromBool added in v0.0.2

func SqlTinyIntFromBool(v bool) int8

func StrFromRef added in v0.0.2

func StrFromRef(v *string) string

StrFromRef returns the value of the pointer, or "" if nil.

func StrNilIfEmpty added in v0.2.4

func StrNilIfEmpty(v string) *string

StrNilIfEmpty returns nil if the string is empty.

func StrRef added in v0.0.2

func StrRef(v string) *string

StrRef returns a fresh pointer for the value. Deprecated: use ToPtr instead.

func StrRefFromSql added in v0.2.0

func StrRefFromSql(v sql.NullString) *string

StrRefFromSql will return nil for a 'null' SQL value.

func StrSliceToStrRefSlice added in v0.0.2

func StrSliceToStrRefSlice(v []string) []*string

func TimeFromGqlTime added in v0.0.2

func TimeFromGqlTime(v string) (time.Time, error)

func TimeFromRef added in v0.13.5

func TimeFromRef(v *time.Time) time.Time

TimeFromRef returns the value of the pointer, or the zero time if nil.

func TimeRef added in v0.0.2

func TimeRef(v time.Time) *time.Time

TimeRef returns a fresh pointer for the value. Deprecated: use ToPtr instead.

func TimeRefFromGqlTimeRef added in v0.0.2

func TimeRefFromGqlTimeRef(v *string) *time.Time

func TimeRefFromSql added in v0.2.0

func TimeRefFromSql(v sql.NullTime) *time.Time

TimeRefFromSql will return nil for a 'null' SQL value.

func ToPtr added in v0.15.1

func ToPtr[T any](v T) *T

ToPtr returns a fresh pointer for the value.

func ToStringSlice added in v0.17.1

func ToStringSlice[T fmt.Stringer](input []T) []string

func TruncateStr added in v0.6.7

func TruncateStr(str string, maxLen int) string

TruncateStr multibyte/UTF-8 safe truncate to a maximum number of characters.

func TruncateStrBytes added in v0.6.7

func TruncateStrBytes(str string, maxBytes int) string

TruncateStrBytes multibyte/UTF-8 safe truncate to a maximum number of bytes.

func UuidRef added in v0.0.2

func UuidRef(id uuid.UUID) *uuid.UUID

UuidRef returns a fresh pointer for the value. Deprecated: use ToPtr instead.

func UuidRefFromSql added in v0.2.5

func UuidRefFromSql(v uuid.NullUUID) *uuid.UUID

UuidRefFromSql will return nil for a 'null' SQL value.

Types

type Alerter added in v0.16.0

type Alerter interface {
	SendAlert(ctx context.Context, msg string) error
}

type CategoryAlerter added in v0.16.0

type CategoryAlerter interface {
	SendAlert(ctx context.Context, category string, msg string) error
}

type ClientError added in v0.0.6

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

ClientError represents an error that should be displayed to the user.

func NewClientError added in v0.0.6

func NewClientError(code string, message string, err error) *ClientError

func (*ClientError) Error added in v0.0.6

func (err *ClientError) Error() string

func (*ClientError) GqlErrorCode added in v0.0.6

func (err *ClientError) GqlErrorCode() string

func (*ClientError) StackTrace added in v0.0.6

func (err *ClientError) StackTrace() errors.StackTrace

func (*ClientError) Unwrap added in v0.0.6

func (err *ClientError) Unwrap() error

type CronFn added in v0.15.9

type CronFn func(ctx context.Context, log zerolog.Logger) error

type CronTab added in v0.15.8

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

func NewCronTab added in v0.15.8

func NewCronTab(
	log zerolog.Logger,
	alerter CategoryAlerter,
	siteName string,
	timeZone *time.Location,

	crons map[string]CronFn,
) (*CronTab, error)

func (*CronTab) Start added in v0.15.8

func (c *CronTab) Start(ctx context.Context)

Start the crons in the background.

type ErrAndPanicGroup added in v0.15.1

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

func NewErrAndPanicGroup added in v0.15.1

func NewErrAndPanicGroup() *ErrAndPanicGroup

func NewErrAndPanicGroupWithContext added in v0.15.1

func NewErrAndPanicGroupWithContext(ctx context.Context) (*ErrAndPanicGroup, context.Context)

func (*ErrAndPanicGroup) Go added in v0.15.1

func (g *ErrAndPanicGroup) Go(fn func() error)

func (*ErrAndPanicGroup) Wait added in v0.15.1

func (g *ErrAndPanicGroup) Wait() error

type Events added in v0.17.5

type Events[T any] struct {
	// contains filtered or unexported fields
}

func NewEvents added in v0.17.5

func NewEvents[T any](log zerolog.Logger) *Events[T]

func (*Events[T]) CancelWatch added in v0.17.5

func (f *Events[T]) CancelWatch(id uuid.UUID)

func (*Events[T]) EventIsBeingWatched added in v0.17.5

func (f *Events[T]) EventIsBeingWatched(eventName string) bool

func (*Events[T]) TriggerEvent added in v0.17.5

func (f *Events[T]) TriggerEvent(eventName string, event *T)

func (*Events[T]) WaitForGroup added in v0.17.5

func (f *Events[T]) WaitForGroup(ctx context.Context, id uuid.UUID) *T

func (*Events[T]) WatchForEvent added in v0.17.5

func (f *Events[T]) WatchForEvent(event string) uuid.UUID

func (*Events[T]) WatchForEvents added in v0.17.5

func (f *Events[T]) WatchForEvents(events []string) uuid.UUID

type SlackMessagePayload added in v0.6.4

type SlackMessagePayload struct {
	Channel   *string `json:"channel"`
	Username  *string `json:"username"`
	Text      string  `json:"text"`
	IconEmoji *string `json:"icon_emoji"`
}

type SlackWebhookClient added in v0.6.4

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

func NewSlackClient added in v0.16.0

func NewSlackClient(log zerolog.Logger, webhookUrl string, defaultChannel string) *SlackWebhookClient

func NewSlackWebhookClientFromEnv added in v0.6.4

func NewSlackWebhookClientFromEnv(log zerolog.Logger) *SlackWebhookClient

func (*SlackWebhookClient) Send added in v0.6.4

func (s *SlackWebhookClient) Send(ctx context.Context, message SlackMessagePayload)

func (*SlackWebhookClient) TrySend added in v0.16.0

func (s *SlackWebhookClient) TrySend(ctx context.Context, message SlackMessagePayload) error

type WatchedEventsGroup added in v0.17.5

type WatchedEventsGroup[T any] struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis
tools

Jump to

Keyboard shortcuts

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