serverutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: Apache-2.0 Imports: 11 Imported by: 15

Documentation

Overview

Package serverutil provides helper functions for Upspin servers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Glob

func Glob(pattern string, lookup LookupFunc, ls ListFunc) ([]*upspin.DirEntry, error)

Glob executes a DirServer.Glob operation for the specified pattern using the provided LookupFunc and ListFunc to retrieve data.

func IsLoopback

func IsLoopback(addr string) bool

IsLoopback returns true if the name only resolves to loopback addresses.

Types

type ListFunc

type ListFunc func(upspin.PathName) ([]*upspin.DirEntry, error)

ListFunc lists the entries in the directory specified by path. It should handle access control internally, returning a Private or Permission error if the caller does not have access. It should return an ErrFollowLink error iff the given path name is a link. In that one case, it should also return only the DirEntry for that path.

type LookupFunc

type LookupFunc func(upspin.PathName) (*upspin.DirEntry, error)

LookupFunc is a DirServer.Lookup implementation.

type RateCounter

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

RateCounter is a counter that tracks how many values have been added per unit of time, averaged over a certain period. RateCounter is an expvar and thus can be used to count time-based events such as requests per second.

func NewRateCounter

func NewRateCounter(samples int, d time.Duration) *RateCounter

NewRateCounter creates a new counter that reports how many values have been added per unit of time, averaged over a rolling window with a given number of samples. For example, to measure unit per second averaged over the last sixty one-second samples: NewRateCount(60, time.Second).

func (*RateCounter) Add

func (r *RateCounter) Add(val int64)

Add adds val to the counter.

func (*RateCounter) Rate

func (r *RateCounter) Rate() float64

Rate returns the rate that values are Added to the counter, per unit of time, averaged over the number of buckets.

func (*RateCounter) String

func (r *RateCounter) String() string

String implements expvar.Val

type RateLimiter

type RateLimiter struct {
	// Backoff specifies an initial backoff duration for a key.
	// After the first request for a given key the key will be denied until
	// the backoff has passed. If another request arrives after the backoff
	// but before Max, the backoff duration is doubled.
	Backoff time.Duration

	// Max specifies a maximum backoff duration.
	Max time.Duration
	// contains filtered or unexported fields
}

RateLimiter implements a rate limiter with exponential backoff, up to a specified maximum.

func (*RateLimiter) Pass

func (r *RateLimiter) Pass(key string) (bool, time.Duration)

Pass attempts to pass key through the rate limiter, returning true if key is within the rate limit. If it returns false it also returns the duration that must elapse before the key will be allowed to pass again.

Directories

Path Synopsis
Dirserver is a wrapper for a directory implementation that presents it as an HTTP interface.
Dirserver is a wrapper for a directory implementation that presents it as an HTTP interface.
Package frontend provides a web server that serves documentation and meta tags to instruct "go get" where to find the Upspin source repository.
Package frontend provides a web server that serves documentation and meta tags to instruct "go get" where to find the Upspin source repository.
Keyserver is a wrapper for a key implementation that presents it as an HTTP interface.
Keyserver is a wrapper for a key implementation that presents it as an HTTP interface.
Package perm implements mutation permission checking for servers.
Package perm implements mutation permission checking for servers.
Package signup provides an http.Handler implementation that serves and validates KeyServer signup requests.
Package signup provides an http.Handler implementation that serves and validates KeyServer signup requests.
Storeserver is a wrapper for a store implementation that presents it as an HTTP interface.
Storeserver is a wrapper for a store implementation that presents it as an HTTP interface.
Package upspinserver is a combined DirServer and StoreServer for use on stand-alone machines.
Package upspinserver is a combined DirServer and StoreServer for use on stand-alone machines.
Package web provides an http.Handler implementation that serves content from the Upspin namespace.
Package web provides an http.Handler implementation that serves content from the Upspin namespace.

Jump to

Keyboard shortcuts

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