package priority

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

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

Index

Variables

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")
)

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.

Source Files

priority_group.go

Version
v3.3.3 (latest)
Published
Aug 16, 2022
Platform
windows/amd64
Imports
6 packages
Last checked
9 hours ago

Tools for package owners.