rand

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package rand contains a Caddy handler that allows random data to be returned.

Index

Constants

This section is empty.

Variables

View Source
var NewRand = func(seed int64) io.Reader { return rand.New(rand.NewSource(seed)) }

NewRand function creates a new random data generator.

Functions

This section is empty.

Types

type HeaderKey

type HeaderKey interface {
	Key() string
	Default() int64
}

type HeaderSeed

type HeaderSeed struct{}

func (HeaderSeed) Default

func (HeaderSeed) Default() int64

Default returns the current unix micro time.

func (HeaderSeed) Key

func (HeaderSeed) Key() string

Key returns `Rand-Seed`.

type HeaderSize

type HeaderSize struct{}

func (HeaderSize) Default

func (HeaderSize) Default() int64

Default returns -1.

func (HeaderSize) Key

func (HeaderSize) Key() string

Key return `Rand-Size`.

type HeaderValue

type HeaderValue[K HeaderKey] int64

func (*HeaderValue[K]) GetValue

func (h *HeaderValue[K]) GetValue(headers http.Header)

GetValue extracts a value from the HTTP headers.

type HeaderValues

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

HeaderValues struct holds the seed and size values extracted from headers.

func NewHeaderValues

func NewHeaderValues(headers http.Header) *HeaderValues

NewHeaderValues creates a new HeaderValues instance from HTTP headers.

func (*HeaderValues) Seed

func (h *HeaderValues) Seed() int64

Seed returns the seed value.

func (*HeaderValues) Size

func (h *HeaderValues) Size() int64

Size returns the size value

type Rand

type Rand struct{}

Rand struct represents the custom Caddy HTTP handler for generating random data.

func (*Rand) CaddyModule

func (r *Rand) CaddyModule() caddy.ModuleInfo

CaddyModule implemnts caddy.Module.

func (*Rand) ServeHTTP

func (r *Rand) ServeHTTP(resp http.ResponseWriter, req *http.Request, _ caddyhttp.Handler) (err error)

ServeHTTP handles sending random data to the client. The following headers can be optionally set to modify the generation of data: - `Rand-Seed`: int64 seed value for the random data generator. - `Rand-Size`: int64 size in bytes of data to generate. A value less than zero represents an infinite stream.

func (*Rand) UnmarshalCaddyfile

func (r *Rand) UnmarshalCaddyfile(*caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler.

Jump to

Keyboard shortcuts

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