conv

package
v0.0.0-...-4ae6852 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnySlice

func AnySlice[T any](vals []T) []any

AnySlice converts a slice of any type to a slice of empty interfaces.

func ApplyVariation

func ApplyVariation(tool types.Tool, variation types.ToolVariation)

func Default

func Default[T comparable](val T, def T) T

Default returns the given value or a default if the value is equal to the zero value of the same type. Example:

Default(0, 5)      // returns 5
Default("", "foo")  // returns "foo"
Default("jane", "joe") // returns "jane"

func FromBytes

func FromBytes(b []byte) *string

FromBytes converts a byte slice to a string pointer. If the byte slice is empty, it returns nil.

func FromNullableUUID

func FromNullableUUID(u uuid.NullUUID) *string

FromNullableUUID converts a uuid.NullUUID to a *string. If the NullUUID is not valid, it returns nil.

func FromPGBool

func FromPGBool[T ~bool](t pgtype.Bool) *T

FromPGBool converts a pgtype.Bool to a bool or subtype of bool. If Bool is not valid, it returns nil.

func FromPGText

func FromPGText[T ~string](t pgtype.Text) *T

FromPGText converts a pgtype.Text to a *string. If the Text is not valid, it returns nil.

func GenerateRandomSlug

func GenerateRandomSlug(size int) (string, error)

GenerateRandomSlug generates a random slug of the given size using lowercase letters and digits. It returns an error if it fails to generate random bytes.

func GetToolURN

func GetToolURN(tool types.Tool) (*urn.Tool, error)

func MarkdownToHTML

func MarkdownToHTML(md []byte) ([]byte, error)

func Ptr

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

Ptr returns a pointer to the given value. This function is useful because it allows you to create pointers to literal values like conv.Ptr(2) or return values from functions/methods.

func PtrEmpty

func PtrEmpty[T comparable](v T) *T

PtrEmpty returns a pointer to the given value or nil if the value is equal to the zero value of the same type. Example:

PtrEmpty(0)      // returns nil
PtrEmpty("")     // returns nil
PtrEmpty(false)  // returns nil
PtrEmpty(2)      // returns *int with value 2

func PtrToPGText

func PtrToPGText(t *string) pgtype.Text

PtrToPGText converts a string pointer to a pgtype.Text with Valid set to true regardless of whether the input is an empty string or not.

func PtrToPGTextEmpty

func PtrToPGTextEmpty(t *string) pgtype.Text

ToPGTextEmpty converts a string pointer to a pgtype.Text with Valid set to true only if the input value is not an empty string.

func PtrValOr

func PtrValOr[T any](ptr *T, def T) T

PtrValOr returns a value of a given pointer or a default if the pointer is is nil. Example:

PtrValOr[int](nil, 5)         // returns *int with value 5
PtrValOr(Ptr(""), "foo")      // returns ""
PtrValOr(Ptr("jane"), "joe")  // returns *string with value "jane"

func PtrValOrEmpty

func PtrValOrEmpty[T comparable](ptr *T, def T) T

PtrValOrEmpty returns a value of a given pointer or a default if the pointer is is nil or the zero value. Example:

PtrValOrEmpty[int](nil, 5)         // returns *int with value 5
PtrValOrEmpty(Ptr(""), "foo")      // returns "foo"
PtrValOrEmpty(Ptr("jane"), "joe")  // returns *string with value "jane"

func Ternary

func Ternary[T any](condition bool, trueVal, falseVal T) T

Ternary returns trueVal if condition is true, otherwise it returns falseVal.

func ToBaseTool

func ToBaseTool(tool *types.Tool) types.BaseToolAttributes

func ToLower

func ToLower[T ~string](s T) string

ToLower converts a string or subtype of string to lowercase.

func ToPGText

func ToPGText(t string) pgtype.Text

ToPGText converts a string to a pgtype.Text with Valid set to true regardless of whether the input is an empty string or not.

func ToPGTextEmpty

func ToPGTextEmpty(t string) pgtype.Text

ToPGTextEmpty converts a string to a pgtype.Text with Valid set to true only if the input value is not an empty string.

func ToSlug

func ToSlug(s string) string

ToSlug converts a string to a URL-friendly "slug". It removes special characters, converts to lowercase, collapses multiple dashes or spaces into a single dash, and trims leading and trailing dashes.

Types

type Secret

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

func NewSecret

func NewSecret(value []byte) Secret

func (Secret) LogValue

func (s Secret) LogValue() slog.Value

func (Secret) MarshalJSON

func (s Secret) MarshalJSON() ([]byte, error)

func (Secret) MarshalText

func (s Secret) MarshalText() ([]byte, error)

func (Secret) Reveal

func (s Secret) Reveal() []byte

func (*Secret) Scan

func (s *Secret) Scan(value any) error

func (Secret) String

func (s Secret) String() string

func (*Secret) UnmarshalJSON

func (s *Secret) UnmarshalJSON(data []byte) error

func (*Secret) UnmarshalText

func (s *Secret) UnmarshalText(text []byte) error

func (Secret) Value

func (s Secret) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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