types

package
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CorsMiddleware

func CorsMiddleware(options *Cors, ctx *HttpContext, next func(error))

func MiddlewareWrapper

func MiddlewareWrapper(options *Cors) func(*HttpContext, func(error))

Types

type Callable

type Callable func()

type CodeMessage

type CodeMessage struct {
	Code    int    `json:"code" mapstructure:"code" msgpack:"code"`
	Message string `json:"message,omitempty" mapstructure:"message,omitempty" msgpack:"message,omitempty"`
}

type Cors

type Cors struct {
	Origin               any    `json:"origin,omitempty" mapstructure:"origin,omitempty" msgpack:"origin,omitempty"`
	Methods              any    `json:"methods,omitempty" mapstructure:"methods,omitempty" msgpack:"methods,omitempty"`
	AllowedHeaders       any    `json:"allowedHeaders,omitempty" mapstructure:"allowedHeaders,omitempty" msgpack:"allowedHeaders,omitempty"`
	Headers              any    `json:"headers,omitempty" mapstructure:"headers,omitempty" msgpack:"headers,omitempty"`
	ExposedHeaders       any    `json:"exposedHeaders,omitempty" mapstructure:"exposedHeaders,omitempty" msgpack:"exposedHeaders,omitempty"`
	MaxAge               string `json:"maxAge,omitempty" mapstructure:"maxAge,omitempty" msgpack:"maxAge,omitempty"`
	Credentials          bool   `json:"credentials,omitempty" mapstructure:"credentials,omitempty" msgpack:"credentials,omitempty"`
	PreflightContinue    bool   `json:"preflightContinue,omitempty" mapstructure:"preflightContinue,omitempty" msgpack:"preflightContinue,omitempty"`
	OptionsSuccessStatus int    `json:"optionsSuccessStatus,omitempty" mapstructure:"optionsSuccessStatus,omitempty" msgpack:"optionsSuccessStatus,omitempty"`
}

type ErrorMessage

type ErrorMessage struct {
	*CodeMessage

	Req     *HttpContext   `json:"req,omitempty" mapstructure:"req,omitempty" msgpack:"req,omitempty"`
	Context map[string]any `json:"context,omitempty" mapstructure:"context,omitempty" msgpack:"context,omitempty"`
}

type HttpCompression

type HttpCompression struct {
	Threshold int `json:"threshold,omitempty" mapstructure:"threshold,omitempty" msgpack:"threshold,omitempty"`
}

type HttpContext

type HttpContext struct {
	events.EventEmitter

	Websocket    *WebSocketConn
	WebTransport *webtransport.Conn

	Cleanup Callable

	ResponseHeaders *utils.ParameterBag
	// contains filtered or unexported fields
}

func NewHttpContext

func NewHttpContext(w http.ResponseWriter, r *http.Request) *HttpContext

func (*HttpContext) Context

func (c *HttpContext) Context() context.Context

func (*HttpContext) Done

func (c *HttpContext) Done() <-chan Void

func (*HttpContext) Flush

func (c *HttpContext) Flush()

func (*HttpContext) Get

func (c *HttpContext) Get(key string, _default ...string) string

func (*HttpContext) GetHost

func (c *HttpContext) GetHost() (string, error)

func (*HttpContext) GetMethod

func (c *HttpContext) GetMethod() string

func (*HttpContext) GetPathInfo

func (c *HttpContext) GetPathInfo() string

func (*HttpContext) GetStatusCode

func (c *HttpContext) GetStatusCode() int

func (*HttpContext) Gets

func (c *HttpContext) Gets(key string, _default ...[]string) []string

func (*HttpContext) Headers

func (c *HttpContext) Headers() *utils.ParameterBag

func (*HttpContext) IsDone

func (c *HttpContext) IsDone() bool

func (*HttpContext) Method

func (c *HttpContext) Method() string

func (*HttpContext) Path

func (c *HttpContext) Path() string

func (*HttpContext) Query

func (c *HttpContext) Query() *utils.ParameterBag

func (*HttpContext) Request

func (c *HttpContext) Request() *http.Request

func (*HttpContext) Response

func (c *HttpContext) Response() http.ResponseWriter

func (*HttpContext) Secure

func (c *HttpContext) Secure() bool

func (*HttpContext) SetStatusCode

func (c *HttpContext) SetStatusCode(statusCode int)

func (*HttpContext) UserAgent

func (c *HttpContext) UserAgent() string

func (*HttpContext) Write

func (c *HttpContext) Write(wb []byte) (int, error)

type HttpServer

type HttpServer struct {
	events.EventEmitter
	*ServeMux
	// contains filtered or unexported fields
}

func CreateServer deprecated

func CreateServer(defaultHandler http.Handler) *HttpServer

Deprecated: this method will be removed in the next major release, please use NewWebServer instead.

func NewWebServer

func NewWebServer(defaultHandler http.Handler) *HttpServer

func (*HttpServer) Close

func (s *HttpServer) Close(fn func(error)) (err error)

func (*HttpServer) Listen

func (s *HttpServer) Listen(addr string, fn Callable) *http.Server

func (*HttpServer) ListenHTTP3TLS

func (s *HttpServer) ListenHTTP3TLS(addr string, certFile string, keyFile string, quicConfig *quic.Config, fn Callable) *http3.Server

func (*HttpServer) ListenTLS

func (s *HttpServer) ListenTLS(addr string, certFile string, keyFile string, fn Callable) *http.Server

func (*HttpServer) ListenWebTransportTLS

func (s *HttpServer) ListenWebTransportTLS(addr string, certFile string, keyFile string, quicConfig *quic.Config, fn Callable) *webtransport.Server

type Kv

type Kv struct {
	Key   string
	Value string
}

type Map

type Map[TKey comparable, TValue any] struct {
	// contains filtered or unexported fields
}

Map is like a Go map[interface{}]interface{} but is safe for concurrent use by multiple goroutines without additional locking or coordination. Loads, stores, and deletes run in amortized constant time.

The Map type is specialized. Most code should use a plain Go map instead, with separate locking or coordination, for better type safety and to make it easier to maintain other invariants along with the map content.

The Map type is optimized for two common use cases: (1) when the entry for a given key is only ever written once but read many times, as in caches that only grow, or (2) when multiple goroutines read, write, and overwrite entries for disjoint sets of keys. In these two cases, use of a Map may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex.

The zero Map is empty and ready for use. A Map must not be copied after first use.

In the terminology of the Go memory model, Map arranges that a write operation “synchronizes before” any read operation that observes the effect of the write, where read and write operations are defined as follows. Load, LoadAndDelete, LoadOrStore, Swap, CompareAndSwap, and CompareAndDelete are read operations; Delete, LoadAndDelete, Store, and Swap are write operations; LoadOrStore is a write operation when it returns loaded set to false; CompareAndSwap is a write operation when it returns swapped set to true; and CompareAndDelete is a write operation when it returns deleted set to true.

func (*Map[TKey, TValue]) Clear

func (m *Map[TKey, TValue]) Clear()

Clear deletes all the keys.

func (*Map[TKey, TValue]) CompareAndDelete

func (m *Map[TKey, TValue]) CompareAndDelete(key TKey, old TValue) (deleted bool)

CompareAndDelete deletes the entry for key if its value is equal to old. The old value must be of a comparable type.

If there is no current value for key in the map, CompareAndDelete returns false (even if the old value is the nil interface value).

func (*Map[TKey, TValue]) CompareAndSwap

func (m *Map[TKey, TValue]) CompareAndSwap(key TKey, old TValue, new TValue) bool

CompareAndSwap swaps the old and new values for key if the value stored in the map is equal to old. The old value must be of a comparable type.

func (*Map[TKey, TValue]) Delete

func (m *Map[TKey, TValue]) Delete(key TKey)

Delete deletes the value for a key.

func (*Map[TKey, TValue]) Keys

func (m *Map[TKey, TValue]) Keys() (keys []TKey)

func (*Map[TKey, TValue]) Len

func (m *Map[TKey, TValue]) Len() (n int)

func (*Map[TKey, TValue]) Load

func (m *Map[TKey, TValue]) Load(key TKey) (value TValue, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*Map[TKey, TValue]) LoadAndDelete

func (m *Map[TKey, TValue]) LoadAndDelete(key TKey) (value TValue, loaded bool)

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

func (*Map[TKey, TValue]) LoadOrStore

func (m *Map[TKey, TValue]) LoadOrStore(key TKey, value TValue) (actual TValue, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*Map[TKey, TValue]) Range

func (m *Map[TKey, TValue]) Range(f func(key TKey, value TValue) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently (including by f), Range may reflect any mapping for that key from any point during the Range call. Range does not block other methods on the receiver; even f itself may call any method on m.

Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.

func (*Map[TKey, TValue]) Store

func (m *Map[TKey, TValue]) Store(key TKey, value TValue)

Store sets the value for a key.

func (*Map[TKey, TValue]) Swap

func (m *Map[TKey, TValue]) Swap(key TKey, value TValue) (previous TValue, loaded bool)

Swap swaps the value for a key and returns the previous value if any. The loaded result reports whether the key was present.

func (*Map[TKey, TValue]) Values

func (m *Map[TKey, TValue]) Values() (values []TValue)

type PerMessageDeflate

type PerMessageDeflate struct {
	Threshold int `json:"threshold,omitempty" mapstructure:"threshold,omitempty" msgpack:"threshold,omitempty"`
}

type ServeMux

type ServeMux struct {
	DefaultHandler http.Handler // Default Handler
	// contains filtered or unexported fields
}

func NewServeMux

func NewServeMux(defaultHandler http.Handler) *ServeMux

NewServeMux allocates and returns a new ServeMux.

func (*ServeMux) Handle

func (mux *ServeMux) Handle(pattern string, handler http.Handler)

Handle registers the handler for the given pattern. If a handler already exists for pattern, Handle panics.

func (*ServeMux) HandleFunc

func (mux *ServeMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc registers the handler function for the given pattern.

func (*ServeMux) Handler

func (mux *ServeMux) Handler(r *http.Request) (h http.Handler, pattern string)

Handler returns the handler to use for the given request, consulting r.Method, r.Host, and r.URL.Path. It always returns a non-nil handler. If the path is not in its canonical form, the handler will be an internally-generated handler that redirects to the canonical path. If the host contains a port, it is ignored when matching handlers.

The path and host are used unchanged for CONNECT requests.

Handler also returns the registered pattern that matches the request or, in the case of internally-generated redirects, the pattern that will match after following the redirect.

If there is no registered handler that applies to the request, Handler returns a “page not found” handler and an empty pattern.

func (*ServeMux) ServeHTTP

func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL.

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T comparable](keys ...T) *Set[T]

func (*Set[T]) Add

func (s *Set[T]) Add(keys ...T) bool

func (*Set[T]) All

func (s *Set[T]) All() map[T]Void

func (*Set[T]) Clear

func (s *Set[T]) Clear() bool

func (*Set[T]) Delete

func (s *Set[T]) Delete(keys ...T) bool

func (*Set[T]) Has

func (s *Set[T]) Has(key T) bool

func (*Set[T]) Keys

func (s *Set[T]) Keys() (list []T)

func (*Set[T]) Len

func (s *Set[T]) Len() int

type Void

type Void struct{}
var (
	NULL Void
)

type WebSocketConn

type WebSocketConn struct {
	events.EventEmitter
	*websocket.Conn
}

Jump to

Keyboard shortcuts

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