utils
import "github.com/Ask-Atlas/AskAtlas/api/internal/utils"
Package utils contains shared helper functions used throughout the application.
Index
- func CursorInt8[C any](c *C, get func(*C) *int64) pgtype.Int8
- func CursorNullUploadStatus[C any](c *C, get func(*C) *string) db.NullUploadStatus
- func CursorText[C any](c *C, get func(*C) *string) pgtype.Text
- func CursorTimestamptz[C any](c *C, get func(*C) *time.Time) pgtype.Timestamptz
- func CursorUUID[C any](c *C, get func(*C) [16]byte) pgtype.UUID
- func Deref[T any](v *T) T
- func Int8(n *int64) pgtype.Int8
- func NonNilStrings(src []string) []string
- func NullUploadStatus(s *string) db.NullUploadStatus
- func PgxToGoogleUUID(u pgtype.UUID) (uuid.UUID, error)
- func Ptr[T any](v T) *T
- func Text(s *string) pgtype.Text
- func TextPtr(t pgtype.Text) *string
- func Timestamptz(t *time.Time) pgtype.Timestamptz
- func TimestamptzPtr(t pgtype.Timestamptz) *time.Time
- func UUID(b [16]byte) pgtype.UUID
func CursorInt8
func CursorInt8[C any](c *C, get func(*C) *int64) pgtype.Int8
CursorInt8 creates a pgtype.Int8 extracted from a paginated cursor.
func CursorNullUploadStatus
func CursorNullUploadStatus[C any](c *C, get func(*C) *string) db.NullUploadStatus
CursorNullUploadStatus creates a db.NullUploadStatus extracted from a paginated cursor.
func CursorText
func CursorText[C any](c *C, get func(*C) *string) pgtype.Text
CursorText creates a pgtype.Text extracted from a paginated cursor.
func CursorTimestamptz
func CursorTimestamptz[C any](c *C, get func(*C) *time.Time) pgtype.Timestamptz
CursorTimestamptz creates a pgtype.Timestamptz extracted from a paginated cursor.
func CursorUUID
func CursorUUID[C any](c *C, get func(*C) [16]byte) pgtype.UUID
CursorUUID creates a pgtype.UUID extracted from a paginated cursor.
func Deref
func Deref[T any](v *T) T
Deref safely dereferences the given pointer, returning its value or the zero value if nil.
func Int8
func Int8(n *int64) pgtype.Int8
Int8 converts an int64 pointer to a pgtype.Int8.
func NonNilStrings
func NonNilStrings(src []string) []string
NonNilStrings returns a non-nil shallow copy of src so JSON encoding emits `[]` rather than `null` for an empty slice. The plain `append([]string(nil), src...)` clone idiom keeps the result nil when len(src) == 0 because Go's append doesn't allocate when there are no elements to append; that nil then JSON-encodes as `null`, which violates wire contracts that declare arrays as non-nullable.
Use at the wire boundary (handler mappers) for any string slice that ships out as a JSON array. Cheap (one allocation per call) and safe (always returns a fresh backing array, so callers can't accidentally alias the source).
func NullUploadStatus
func NullUploadStatus(s *string) db.NullUploadStatus
NullUploadStatus converts a string pointer to a db.NullUploadStatus.
func PgxToGoogleUUID
func PgxToGoogleUUID(u pgtype.UUID) (uuid.UUID, error)
PgxToGoogleUUID converts a pgtype.UUID to a standard Google UUID.
func Ptr
func Ptr[T any](v T) *T
Ptr returns a pointer to the given value.
func Text
func Text(s *string) pgtype.Text
Text converts a string pointer to a pgtype.Text.
func TextPtr
func TextPtr(t pgtype.Text) *string
TextPtr converts a pgtype.Text into a *string pointer, returning nil for SQL NULL. Use this in mappers when the column is nullable and the wire shape wants JSON null (not empty string) on absence. Three domain packages were each carrying their own local textPtr; this shared helper is the single source of truth.
func Timestamptz
func Timestamptz(t *time.Time) pgtype.Timestamptz
Timestamptz converts a time.Time pointer to a pgtype.Timestamptz.
func TimestamptzPtr
func TimestamptzPtr(t pgtype.Timestamptz) *time.Time
TimestamptzPtr converts a pgtype.Timestamptz to a time.Time pointer.
func UUID
func UUID(b [16]byte) pgtype.UUID
UUID converts a byte array to a pgtype.UUID.
Generated by gomarkdoc