package parse

import "github.com/google/martian/v3/parse"

Package parse constructs martian modifiers from JSON messages.

Index

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.

Source Files

parse.go

Version
v3.3.2
Published
Mar 14, 2022
Platform
windows/amd64
Imports
4 packages
Last checked
1 hour ago

Tools for package owners.