rest

package
v0.0.0-...-cc8cd10 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHandlers

func RegisterHandlers(mux httpMux, endpoints []*Endpoint)

RegisterHandlers registers endpoint handlers to the given HTTP mux.

Types

type Endpoint

type Endpoint struct {
	Path   string
	Method string
	// contains filtered or unexported fields
}

func NewEndpoint

func NewEndpoint(path, method string, respResolver ResponseResolver) *Endpoint

func (*Endpoint) Response

func (p *Endpoint) Response() Response

Response yields the next response that should be returned when the endpoint is hit.

type Response

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

func NewResponse

func NewResponse(opts ...ResponseOption) (Response, error)

type ResponseOption

type ResponseOption func(*Response) error

func WithResponseBody

func WithResponseBody(body []byte) ResponseOption

func WithResponseDelay

func WithResponseDelay(delay time.Duration) ResponseOption

func WithResponseHeaders

func WithResponseHeaders(headers map[string]string) ResponseOption

func WithResponseStatus

func WithResponseStatus(statusCode int) ResponseOption

type ResponseResolver

type ResponseResolver interface {
	NextResponse() Response
}

type SequenceBehavior

type SequenceBehavior string
const (
	SequenceBehaviorLoop       SequenceBehavior = "loop"
	SequenceBehaviorRepeatLast SequenceBehavior = "repeatLast"
)

type SequencedResponse

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

func NewSequencedResponse

func NewSequencedResponse(endBehavior SequenceBehavior, sequence []Response) (*SequencedResponse, error)

func (*SequencedResponse) NextResponse

func (s *SequencedResponse) NextResponse() Response

type StaticResponse

type StaticResponse Response

func (StaticResponse) NextResponse

func (r StaticResponse) NextResponse() Response

type WeightedResponse

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

func NewWeightedResponse

func NewWeightedResponse(entries []WeightedResponseEntry, numGenerator numberGenerator) (*WeightedResponse, error)

NewWeightedResponse builds a weighted response strategy from the given responses. If numGenerator is nil, a random source is used.

func (*WeightedResponse) NextResponse

func (w *WeightedResponse) NextResponse() Response

type WeightedResponseEntry

type WeightedResponseEntry struct {
	Response Response
	Weight   int
}

Jump to

Keyboard shortcuts

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