parse

package
v3.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: Apache-2.0 Imports: 4 Imported by: 28

Documentation

Overview

Package parse constructs martian modifiers from JSON messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, parseFunc func(b []byte) (*Result, error))

Register registers a parsing function for name that will be used to unmarshal a JSON message into the appropriate modifier.

Types

type ErrUnknownModifier

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

ErrUnknownModifier is the error returned when the message does not contain a field representing a known modifier type.

func (ErrUnknownModifier) Error

func (e ErrUnknownModifier) Error() string

Error returns a formatted error message for an ErrUnknownModifier.

type ModifierType

type ModifierType string

ModifierType is the HTTP message type.

const (
	// Request modifies an HTTP request.
	Request ModifierType = "request"
	// Response modifies an HTTP response.
	Response ModifierType = "response"
)

type Result

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

Result holds the parsed modifier and its type.

func FromJSON

func FromJSON(b []byte) (*Result, error)

FromJSON parses a Modifier JSON message by looking up the named modifier in parseFuncs and passing its modifier to the registered parseFunc. Returns a parse.Result containing the top-level parsed modifier. If no parser has been registered with the given name it returns an error of type ErrUnknownModifier.

func NewResult

func NewResult(mod interface{}, scope []ModifierType) (*Result, error)

NewResult returns a new parse.Result for a given interface{} that implements a modifier and a slice of scopes to generate the result for.

Returns nil, error if a given modifier does not support a given scope

func (*Result) RequestModifier

func (r *Result) RequestModifier() martian.RequestModifier

RequestModifier returns the parsed RequestModifier.

Returns nil if the message has no request modifier.

func (*Result) ResponseModifier

func (r *Result) ResponseModifier() martian.ResponseModifier

ResponseModifier returns the parsed ResponseModifier.

Returns nil if the message has no response modifier.

Jump to

Keyboard shortcuts

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