stdjson

package
v0.30.15 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// KnownTypeFields holds the list of json property names
	// that can contain type discriminators.
	KnownTypeFields = []string{"$type", "@type"}

	// KnownValuesFields holds the list of json property names
	// that can contain values for discriminated arrays.
	KnownValuesFields = []string{"$values", "@values"}
)
View Source
var (
	// CamelCase directs the json encoding of keys to use camelcase notation.
	CamelCase = miruken.Options(Options{
		Transformers: []transform.Transformer{
			transform.OnlyForDirection(
				transform.Marshal,
				transform.CamelCaseKeys(false)),
		},
	})
)

Functions

func Feature

func Feature(config ...func(*Installer)) miruken.Feature

Types

type Either

type Either[L, R any] struct {
	Left  bool            `json:"left"`
	Value json.RawMessage `json:"value"`
}

Either is a surrogate for either.Monad using standard json.

func (Either[L, R]) Original

func (s Either[L, R]) Original(
	composer miruken.Handler,
) (any, error)

type Installer

type Installer struct{}

Installer configure json support.

func (*Installer) DependsOn

func (i *Installer) DependsOn() []miruken.Feature

func (*Installer) Install

func (i *Installer) Install(setup *miruken.SetupBuilder) error

type Mapper

type Mapper struct{}

Mapper formats to and from json using encoding/json.

func (*Mapper) FromBytes

func (m *Mapper) FromBytes(
	_ *struct {
		maps.Format `from:"application/json"`
	}, byt []byte,
	_ *struct {
		args.Optional
		args.FromOptions
	}, options Options,
	_ *struct {
		args.Optional
		args.FromOptions
	}, apiOptions api.Options,
	maps *maps.It,
	ctx miruken.HandleContext,
) (any, error)

func (*Mapper) FromReader

func (m *Mapper) FromReader(
	_ *struct {
		maps.Format `from:"application/json"`
	}, reader io.Reader,
	_ *struct {
		args.Optional
		args.FromOptions
	}, options Options,
	_ *struct {
		args.Optional
		args.FromOptions
	}, apiOptions api.Options,
	maps *maps.It,
	ctx miruken.HandleContext,
) (any, error)

func (*Mapper) ToJson

func (m *Mapper) ToJson(
	_ *struct {
		maps.Format `to:"application/json"`
	}, it *maps.It,
	_ *struct {
		args.Optional
		args.FromOptions
	}, options Options,
	_ *struct {
		args.Optional
		args.FromOptions
	}, apiOptions api.Options,
	ctx miruken.HandleContext,
) (json any, err error)

type MessageSurrogate

type MessageSurrogate struct {
	Payload json.RawMessage `json:"payload"`
}

MessageSurrogate is a json standard surrogate for api.Message.

type Options

type Options struct {
	Prefix       string
	Indent       string
	EscapeHTML   miruken.Option[bool]
	Transformers []transform.Transformer
}

Options provide options for controlling json encoding.

type ScheduledResult

type ScheduledResult []Either[error, any]

ScheduledResult is a surrogate for api.ScheduledResult over json.

func (ScheduledResult) Original

func (s ScheduledResult) Original(composer miruken.Handler) (any, error)

type SurrogateMapper

type SurrogateMapper struct{}

SurrogateMapper maps concepts to values that are more suitable for transmission over a standard polymorphic json api.

func (*SurrogateMapper) DecodeMessage

func (m *SurrogateMapper) DecodeMessage(
	_ *struct {
		maps.It
		maps.Format `from:"application/json"`
	}, reader io.Reader,
	it *maps.It,
	ctx miruken.HandleContext,
) (msg api.Message, err error)

func (*SurrogateMapper) EncodeMessage

func (m *SurrogateMapper) EncodeMessage(
	_ *struct {
		maps.Format `to:"application/json"`
	}, msg api.Message,
	it *maps.It,
	ctx miruken.HandleContext,
) (io.Writer, error)

func (*SurrogateMapper) New

func (m *SurrogateMapper) New(
	_ *struct {
		creates.It `key:"stdjson.ScheduledResult"`
	}, create *creates.It,
) any

func (*SurrogateMapper) ReplaceScheduledResult

func (m *SurrogateMapper) ReplaceScheduledResult(
	_ *struct {
		maps.It
		maps.Format `to:"application/json"`
	}, result api.ScheduledResult,
	ctx miruken.HandleContext,
) ([]byte, error)

Jump to

Keyboard shortcuts

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