bouncermain

package
v0.0.0-...-d6e4ea7 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSize = errors.New("request: 'size' must be a positive non-zero integer")
	ErrKeyError    = errors.New("conflict: key already released or expired")
	ErrTimedOut    = errors.New("timeout: 'maxwait' exceeded while waiting for token")
	ErrEventClosed = errors.New("conflict: event was already sent and closed")
	ErrNotFound    = errors.New("request: object not found")
)

Functions

func EventSendHandler

func EventSendHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func EventStats

func EventStats(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func EventWaitHandler

func EventWaitHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func Main

func Main()

func RecvTimeout

func RecvTimeout(ch <-chan bool, d time.Duration) (v bool, err error)

func Router

func Router() *httprouter.Router

func SemaphoreAcquireHandler

func SemaphoreAcquireHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func SemaphoreReleaseHandler

func SemaphoreReleaseHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func SemaphoreStats

func SemaphoreStats(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func SetField

func SetField(s interface{}, f string, v interface{}) error

SetField assigns value v to field f of struct s.

func TokenBucketAcquireHandler

func TokenBucketAcquireHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func TokenBucketStats

func TokenBucketStats(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func ViewStats

func ViewStats(w http.ResponseWriter, r *http.Request, ps httprouter.Params, f statsFunc)

func WatchdogKickHandler

func WatchdogKickHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func WatchdogStats

func WatchdogStats(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func WatchdogWaitHandler

func WatchdogWaitHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func WellKnownReady

func WellKnownReady(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

Types

type Event

type Event struct {
	Name string

	Stats *Metrics
	// contains filtered or unexported fields
}

func (*Event) GetStats

func (event *Event) GetStats() *Metrics

func (*Event) Send

func (event *Event) Send() (err error)

func (*Event) Wait

func (event *Event) Wait(maxwait time.Duration) (err error)

type Metrics

type Metrics struct {
	Nominal    uint64 `json:"nominal"`
	Acquired   uint64 `json:"acquired"`
	Released   uint64 `json:"released"`
	WaitTime   uint64 `json:"total_wait_time"`
	TimedOut   uint64 `json:"timed_out"`
	Expired    uint64 `json:"expired"`
	Reacquired uint64 `json:"reacquired"`
	CreatedAt  string `json:"created_at"`
}

type Reply

type Reply struct {
	Body   string
	Status int
}

func (*Reply) WriteResponse

func (rep *Reply) WriteResponse(w http.ResponseWriter, r *http.Request, err error)

type Request

type Request struct {
	Expires  time.Duration `schema:"expires"`
	Interval time.Duration `schema:"interval"`
	Key      string        `schema:"key"`
	MaxWait  time.Duration `schema:"maxwait"`
	Size     uint64        `schema:"size"`
	Arrival  time.Time     `schema:"-"`
}

func (*Request) Decode

func (req *Request) Decode(values url.Values) (err error)

type Semaphore

type Semaphore struct {
	Name string
	Size uint64
	Keys map[string]time.Duration

	Stats *Metrics
	// contains filtered or unexported fields
}

func (*Semaphore) Acquire

func (semaphore *Semaphore) Acquire(maxwait time.Duration, expires time.Duration, key string) (token string, err error)

func (*Semaphore) GetStats

func (semaphore *Semaphore) GetStats() *Metrics

func (*Semaphore) Release

func (semaphore *Semaphore) Release(key string) error

type TokenBucket

type TokenBucket struct {
	Name     string
	Size     uint64
	Interval time.Duration
	Stats    *Metrics
	// contains filtered or unexported fields
}

func (*TokenBucket) Acquire

func (bucket *TokenBucket) Acquire(maxwait time.Duration, arrival time.Time) (err error)

func (*TokenBucket) GetStats

func (bucket *TokenBucket) GetStats() *Metrics

type Watchdog

type Watchdog struct {
	Name string

	Stats *Metrics
	// contains filtered or unexported fields
}

func (*Watchdog) GetStats

func (watchdog *Watchdog) GetStats() *Metrics

func (*Watchdog) Kick

func (watchdog *Watchdog) Kick(expires time.Duration) (err error)

func (*Watchdog) Wait

func (watchdog *Watchdog) Wait(maxwait time.Duration) (err error)

Jump to

Keyboard shortcuts

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