customtypes

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRouter

func NewRouter() *http.ServeMux

Types

type Event

type Event struct {
	ID         int             `json:"id"`
	Name       string          `json:"name"`
	OccurredAt time.Time       `json:"occurred_at"`
	Metadata   json.RawMessage `json:"metadata,omitempty"`
}

Event uses time.Time and json.RawMessage.

type Item

type Item struct {
	ID     UserID `json:"id"`
	Status Status `json:"status"`
	Name   string `json:"name"`
}

Item demonstrates custom named types embedded in a struct.

type Nullable

type Nullable[T any] struct {
	Value T
	Valid bool
}

Nullable is a generic nullable wrapper that marshals to/from a plain JSON value (or null), rather than the struct encoding used by database/sql Null* types.

func NullOf

func NullOf[T any](v T) Nullable[T]

NullOf is a convenience constructor for a valid Nullable value.

func (Nullable[T]) MarshalJSON

func (n Nullable[T]) MarshalJSON() ([]byte, error)

func (*Nullable[T]) UnmarshalJSON

func (n *Nullable[T]) UnmarshalJSON(data []byte) error

type NullableFields

type NullableFields struct {
	Name   Nullable[string]  `json:"name"`
	Age    Nullable[int64]   `json:"age"`
	Score  Nullable[float64] `json:"score"`
	Active Nullable[bool]    `json:"active"`
}

NullableFields uses the local Nullable[T] type so the JSON wire format is a plain scalar ("Alice", 30, …) rather than {"String":"Alice","Valid":true}.

type Page

type Page[T any] struct {
	Items    []T `json:"items"`
	Total    int `json:"total"`
	PageNum  int `json:"page"`
	PageSize int `json:"page_size"`
}

Page is a generic paginated response wrapper.

type Status

type Status string

Status is a custom named string type — the reflector should render it as a plain string.

const (
	StatusActive   Status = "active"
	StatusInactive Status = "inactive"
	StatusPending  Status = "pending"
)

type UserID

type UserID int64

UserID is a custom named integer type.

Jump to

Keyboard shortcuts

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