priority

package
v3.0.0-...-e766414 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package priority allows grouping modifiers and applying them in priority order.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrModifierNotFound is the error returned when attempting to remove a
	// modifier when the modifier does not exist in the group.
	ErrModifierNotFound = errors.New("modifier not found in group")
)

Functions

This section is empty.

Types

type Group

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

Group is a group of request and response modifiers ordered by their priority.

func NewGroup

func NewGroup() *Group

NewGroup returns a priority group.

func (*Group) AddRequestModifier

func (pg *Group) AddRequestModifier(reqmod martian.RequestModifier, priority int64)

AddRequestModifier adds a RequestModifier with the given priority.

If a modifier is added with a priority that is equal to an existing priority the newer modifier will be added before the existing modifier in the chain.

func (*Group) AddResponseModifier

func (pg *Group) AddResponseModifier(resmod martian.ResponseModifier, priority int64)

AddResponseModifier adds a ResponseModifier with the given priority.

If a modifier is added with a priority that is equal to an existing priority the newer modifier will be added before the existing modifier in the chain.

func (*Group) ModifyRequest

func (pg *Group) ModifyRequest(req *http.Request) error

ModifyRequest modifies the request. Modifiers are run in descending order of their priority. If an error is returned by a RequestModifier the error is returned and no further modifiers are run.

func (*Group) ModifyResponse

func (pg *Group) ModifyResponse(res *http.Response) error

ModifyResponse modifies the response. Modifiers are run in descending order of their priority. If an error is returned by a ResponseModifier the error is returned and no further modifiers are run.

func (*Group) RemoveRequestModifier

func (pg *Group) RemoveRequestModifier(reqmod martian.RequestModifier) error

RemoveRequestModifier removes the the highest priority given RequestModifier. Returns ErrModifierNotFound if the given modifier does not exist in the group.

func (*Group) RemoveResponseModifier

func (pg *Group) RemoveResponseModifier(resmod martian.ResponseModifier) error

RemoveResponseModifier removes the the highest priority given ResponseModifier. Returns ErrModifierNotFound if the given modifier does not exist in the group.

Jump to

Keyboard shortcuts

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