contract

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: MIT Imports: 9 Imported by: 118

Documentation

Index

Constants

View Source
const DefaultIndent = "  "

Variables

This section is empty.

Functions

func ApplyComp

func ApplyComp[T any](c *T, modifiers ...CompOption[T]) T

func ApplyMeta

func ApplyMeta[T any](m *T, modifiers ...MetaOption[T]) T

Types

type CompOption

type CompOption[T any] func(*T)

type FSysFileReader

type FSysFileReader interface {
	FSysReadFile(fsys fs.ReadFileFS, path string) ([]byte, error)
}

type Geocoder

type Geocoder interface {
	TimezoneFromCoordinates(ctx context.Context, latitude, longitude float64) (string, error)
	CityFromCoordinates(ctx context.Context, latitude, longitude float64) (string, error)
	SwapTimezone(t time.Time, tz string, toUTC, toMidnight bool) (time.Time, error)
	IsUTC(t time.Time) bool
}

type GzipReader

type GzipReader interface {
	Read(r io.Reader) (io.Reader, error)
}

type GzipUtil

type GzipUtil interface {
	WriteGzip(w *gzip.Writer, r io.Reader) error
	CloseGzipWriter(w *gzip.Writer) error
	ReadGzip(r io.Reader) ([]byte, error)
	NewGzipReader(r io.Reader) (*gzip.Reader, error)
	CopyToBuffer(r *gzip.Reader, buf *bytes.Buffer) error
	CloseGzipReader(r *gzip.Reader) error
}

type GzipWriter

type GzipWriter interface {
	Write(r io.Reader) (io.Reader, int64, error)
}

type HTTPDoer

type HTTPDoer interface {
	Do(ctx context.Context, r *http.Request) (*http.Response, error)
}

type HTTPRequester

type HTTPRequester interface {
	NewRequest(ctx context.Context, method, url string, opts RequestOptions) (*http.Request, error)
}

type HTTPWriter

type HTTPWriter interface {
	Write(w http.ResponseWriter, b []byte) (int, error)
}

type JSONOption

type JSONOption func(*JSONOptions)

func WithJSONEscapeHTML

func WithJSONEscapeHTML(escape bool) JSONOption

func WithJSONIndent

func WithJSONIndent(indent string) JSONOption

func WithJSONUseNumber

func WithJSONUseNumber(use bool) JSONOption

type JSONOptions

type JSONOptions struct {
	Indent     string // Enables indentation if non-empty.
	EscapeHTML bool   // Determines if HTML characters should be escaped.
	UseNumber  bool   // If true, decodes numbers as `json.Number` instead of `float64`.
}

JSONOptions defines settings for encoding/decoding.

func ApplyJSONOptions

func ApplyJSONOptions(opts *JSONOptions, modifiers ...JSONOption) JSONOptions

type Level

type Level = slog.Level
const (
	Debug Level = slog.LevelDebug
	Info  Level = slog.LevelInfo
	Warn  Level = slog.LevelWarn
	Error Level = slog.LevelError
)

type Logger

type Logger interface {
	Log(ctx context.Context, l Level, v any, prefix string, msg ...string)
	Wrap(ctx context.Context, fn func() (any, error)) error
}

type MapsAPI

type MapsAPI interface {
	Timezone(ctx context.Context, r *maps.TimezoneRequest) (*maps.TimezoneResult, error)
	Geocode(ctx context.Context, r *maps.GeocodingRequest) ([]maps.GeocodingResult, error)
}

type Marshaler

type Marshaler interface {
	Marshal(v any, opts JSONOptions) ([]byte, error)
}

type MetaOption

type MetaOption[T any] func(*T)

type Reader

type Reader interface {
	Read(io.Reader) ([]byte, error)
}

type RequestOption

type RequestOption func(*RequestOptions)

func WithRequestBody

func WithRequestBody(body io.Reader) RequestOption

func WithRequestHeader

func WithRequestHeader(header http.Header) RequestOption

type RequestOptions

type RequestOptions struct {
	Header http.Header
	Body   io.Reader
}

func ApplyRequestOptions

func ApplyRequestOptions(opts *RequestOptions, modifiers ...RequestOption) RequestOptions

type Tool

type Tool[C any] struct {
	Client C
	Logger Logger
}

func NewTool

func NewTool[C any](client C, opts ToolOptions[C]) *Tool[C]

type ToolOption

type ToolOption[C any] func(*ToolOptions[C])

func WithLogger

func WithLogger[C any](l Logger) ToolOption[C]

type ToolOptions

type ToolOptions[C any] struct {
	Logger Logger
}

func ApplyOptions

func ApplyOptions[C any](opts *ToolOptions[C], modifiers ...ToolOption[C]) ToolOptions[C]

type Unmarshaler

type Unmarshaler interface {
	Unmarshal(data io.Reader, v any, opts JSONOptions) error
}

Jump to

Keyboard shortcuts

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