config

package
v0.0.0-...-f506387 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2025 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHTTPMethod = errors.New("invalid HTTP method")
View Source
var ErrInvalidHeaderName = errors.New("invalid header name")
View Source
var ErrInvalidStatusCode = errors.New("invalid HTTP response status code")
View Source
var ErrMinGreaterMax = errors.New("min greater than max")
View Source
var ErrNoEffect = errors.New("no effect")

Functions

func Validate

func Validate(c Config) error

Validate returns an error if c is invalid, otherwise returns nil.

Types

type Config

type Config struct {
	Resources []Resource `yaml:"resources"`
}

func Load

func Load(src io.Reader) (*Config, error)

Load loads config from arbitrary reader.

func LoadFile

func LoadFile(file string) (*Config, error)

LoadFile loads config from file.

type DurRange

type DurRange struct {
	Min time.Duration `yaml:"min"`
	Max time.Duration `yaml:"max"`
}

func (DurRange) Validate

func (r DurRange) Validate() error

type Effect

type Effect struct {
	Delay   *DurRange `yaml:"delay"`
	Replace *Replace  `yaml:"replace"`
}

func (*Effect) Validate

func (e *Effect) Validate() error

type GlobExpression

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

func NewGlobExpression

func NewGlobExpression(expression string) (GlobExpression, error)

func (*GlobExpression) Match

func (g *GlobExpression) Match(s string) bool

func (GlobExpression) String

func (e GlobExpression) String() string

func (*GlobExpression) UnmarshalText

func (g *GlobExpression) UnmarshalText(text []byte) (err error)

type GlobMap

type GlobMap[T any] map[GlobExpression]T

func (GlobMap[T]) Validate

func (h GlobMap[T]) Validate() error

type HTTPMethod

type HTTPMethod string

func (*HTTPMethod) UnmarshalText

func (m *HTTPMethod) UnmarshalText(text []byte) error

type HeaderName

type HeaderName string

func (HeaderName) Validate

func (n HeaderName) Validate() error

type Replace

type Replace struct {
	StatusCode StatusCode            `yaml:"status-code"`
	Body       *string               `yaml:"body"`
	Headers    map[HeaderName]string `yaml:"headers"`
}

type Resource

type Resource struct {
	Methods []HTTPMethod              `yaml:"methods"`
	Path    GlobExpression            `yaml:"path"`
	Headers GlobMap[[]GlobExpression] `yaml:"headers"`
	Query   GlobMap[[]GlobExpression] `yaml:"query"`
	Effect  *Effect                   `yaml:"effect"`
}

type StatusCode

type StatusCode int32

func (StatusCode) Validate

func (c StatusCode) Validate() error

Jump to

Keyboard shortcuts

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