Documentation
¶
Index ¶
- Constants
- Variables
- func CorsMiddleware(options *Cors, ctx *HttpContext, next func(error))
- func IndexByte(b []byte, c byte) int
- func MiddlewareWrapper(options *Cors) func(*HttpContext, func(error))
- type Atomic
- type Buffer
- func (b *Buffer) Available() int
- func (b *Buffer) AvailableBuffer() []byte
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Cap() int
- func (b *Buffer) Clone() *Buffer
- func (b *Buffer) Grow(n int)
- func (b *Buffer) Len() int
- func (b *Buffer) Next(n int) []byte
- func (b *Buffer) Read(p []byte) (n int, err error)
- func (b *Buffer) ReadByte() (byte, error)
- func (b *Buffer) ReadBytes(delim byte) (line []byte, err error)
- func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)
- func (b *Buffer) ReadRune() (r rune, size int, err error)
- func (b *Buffer) ReadString(delim byte) (line string, err error)
- func (b *Buffer) Reset()
- func (b *Buffer) Seek(offset int64, whence int) (int64, error)
- func (b *Buffer) Size() int64
- func (b *Buffer) String() string
- func (b *Buffer) Truncate(n int)
- func (b *Buffer) UnreadByte() error
- func (b *Buffer) UnreadRune() error
- func (b *Buffer) Write(p []byte) (n int, err error)
- func (b *Buffer) WriteByte(c byte) error
- func (b *Buffer) WriteRune(r rune) (n int, err error)
- func (b *Buffer) WriteString(s string) (n int, err error)
- func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)
- type BufferInterface
- func NewBytesBuffer(buf []byte) BufferInterface
- func NewBytesBufferReader(r io.Reader) (BufferInterface, error)
- func NewBytesBufferString(s string) BufferInterface
- func NewStringBuffer(buf []byte) BufferInterface
- func NewStringBufferReader(r io.Reader) (BufferInterface, error)
- func NewStringBufferString(s string) BufferInterface
- type BytesBuffer
- type Callable
- type CodeMessage
- type Cors
- type ErrorMessage
- type EventEmitter
- type EventListener
- type EventName
- type Events
- type ExtendedError
- type HttpCompression
- type HttpContext
- func (c *HttpContext) Context() context.Context
- func (c *HttpContext) Done() <-chan struct{}
- func (c *HttpContext) Flush()
- func (c *HttpContext) GetStatusCode() int
- func (c *HttpContext) Headers() *ParameterBag
- func (c *HttpContext) Host() string
- func (c *HttpContext) IsDone() bool
- func (c *HttpContext) Method() string
- func (c *HttpContext) Path() string
- func (c *HttpContext) PathInfo() string
- func (c *HttpContext) Query() *ParameterBag
- func (c *HttpContext) Request() *http.Request
- func (c *HttpContext) Response() http.ResponseWriter
- func (c *HttpContext) ResponseHeaders() *ParameterBag
- func (c *HttpContext) Secure() bool
- func (c *HttpContext) SetStatusCode(code int) error
- func (c *HttpContext) UserAgent() string
- func (c *HttpContext) Write(data []byte) (int, error)
- type HttpServer
- func (s *HttpServer) Close(fn func(error)) (err error)
- func (s *HttpServer) Listen(addr string, fn Callable) *http.Server
- func (s *HttpServer) ListenHTTP3TLS(addr string, certFile string, keyFile string, quicConfig *quic.Config, ...) *http3.Server
- func (s *HttpServer) ListenTLS(addr string, certFile string, keyFile string, fn Callable) *http.Server
- func (s *HttpServer) ListenWebTransportTLS(addr string, certFile string, keyFile string, quicConfig *quic.Config, ...) *webtransport.Server
- type IncomingHttpHeaders
- type Kv
- type Map
- func (m *Map[TKey, TValue]) Clear()
- func (m *Map[TKey, TValue]) CompareAndDelete(key TKey, old TValue) (deleted bool)
- func (m *Map[TKey, TValue]) CompareAndSwap(key TKey, old TValue, new TValue) (swapped bool)
- func (m *Map[TKey, TValue]) Delete(key TKey)
- func (m *Map[TKey, TValue]) Keys() (keys []TKey)
- func (m *Map[TKey, TValue]) Len() (n int)
- func (m *Map[TKey, TValue]) Load(key TKey) (value TValue, ok bool)
- func (m *Map[TKey, TValue]) LoadAndDelete(key TKey) (value TValue, loaded bool)
- func (m *Map[TKey, TValue]) LoadOrStore(key TKey, value TValue) (actual TValue, loaded bool)
- func (m *Map[TKey, TValue]) Range(f func(key TKey, value TValue) bool)
- func (m *Map[TKey, TValue]) Store(key TKey, value TValue)
- func (m *Map[TKey, TValue]) Swap(key TKey, value TValue) (previous TValue, loaded bool)
- func (m *Map[TKey, TValue]) Values() (values []TValue)
- type Optional
- type ParameterBag
- func (p *ParameterBag) Add(key string, value string)
- func (p *ParameterBag) All() map[string][]string
- func (p *ParameterBag) Count() int
- func (p *ParameterBag) Get(key string, _default ...string) (string, bool)
- func (p *ParameterBag) GetFirst(key string, _default ...string) (string, bool)
- func (p *ParameterBag) GetLast(key string, _default ...string) (string, bool)
- func (p *ParameterBag) Gets(key string, _default ...[]string) ([]string, bool)
- func (p *ParameterBag) Has(key string) bool
- func (p *ParameterBag) Keys() []string
- func (p *ParameterBag) Peek(key string, _default ...string) string
- func (p *ParameterBag) Remove(key string)
- func (p *ParameterBag) Replace(parameters map[string][]string)
- func (p *ParameterBag) Set(key string, value string)
- func (p *ParameterBag) With(parameters map[string][]string)
- type ParsedUrlQuery
- type PerMessageDeflate
- type ServeMux
- func (mux *ServeMux) Handle(pattern string, handler http.Handler)
- func (mux *ServeMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
- func (mux *ServeMux) Handler(r *http.Request) (h http.Handler, pattern string)
- func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type Set
- func (s *Set[KType]) Add(keys ...KType) bool
- func (s *Set[KType]) All() map[KType]Void
- func (s *Set[KType]) Clear() bool
- func (s *Set[KType]) Delete(keys ...KType) bool
- func (s *Set[KType]) Has(key KType) bool
- func (s *Set[KType]) Keys() []KType
- func (s *Set[KType]) Len() int
- func (s *Set[KType]) MarshalJSON() ([]byte, error)
- func (s *Set[KType]) MarshalMsgpack() ([]byte, error)
- func (s *Set[KType]) UnmarshalJSON(data []byte) error
- func (s *Set[KType]) UnmarshalMsgpack(data []byte) error
- type Slice
- func (s *Slice[T]) All() []T
- func (s *Slice[T]) AllAndClear() []T
- func (s *Slice[T]) Clear()
- func (s *Slice[T]) DoRead(op func([]T))
- func (s *Slice[T]) DoWrite(op func([]T) []T)
- func (s *Slice[T]) Filter(condition func(T) bool) (filtered []T)
- func (s *Slice[T]) FindIndex(condition func(T) bool) int
- func (s *Slice[T]) Get(index int) (element T, err error)
- func (s *Slice[T]) Len() int
- func (s *Slice[T]) Pop() (element T, err error)
- func (s *Slice[T]) Push(elements ...T) int
- func (s *Slice[T]) Range(f func(T, int) bool, reverse ...bool)
- func (s *Slice[T]) RangeAndSplice(f func(T, int) (bool, int, int, []T), reverse ...bool) ([]T, error)
- func (s *Slice[T]) Remove(condition func(T) bool)
- func (s *Slice[T]) RemoveAll(condition func(T) bool)
- func (s *Slice[T]) Replace(elements []T)
- func (s *Slice[T]) Set(index int, element T) error
- func (s *Slice[T]) Shift() (element T, err error)
- func (s *Slice[T]) Slice(start, end int) ([]T, error)
- func (s *Slice[T]) Splice(start, deleteCount int, insert ...T) ([]T, error)
- func (s *Slice[T]) Unshift(elements ...T) int
- type Some
- type StringBuffer
- type Void
- type WebSocketConn
- type WebTransportConn
Examples ¶
Constants ¶
const (
// Version current version number
EventVersion = "0.0.3"
)
const MinRead = 512
MinRead is the minimum slice size passed to a Buffer.Read call by Buffer.ReadFrom. As long as the Buffer has at least MinRead bytes beyond what is required to hold the contents of r, Buffer.ReadFrom will not grow the underlying buffer.
Variables ¶
var ( ErrResponseAlreadyWritten = errors.New("response has already been written") ErrInvalidStatusCode = errors.New("invalid status code") )
var ( ErrSliceEmpty = errors.New("slice is empty") ErrIndexOutOfBounds = errors.New("index out of bounds") ErrInvalidSliceRange = errors.New("invalid slice range") )
Define custom error types
var ErrTooLarge = errors.New("bytes.Buffer: too large")
ErrTooLarge is passed to panic if memory cannot be allocated to store data in a buffer.
Functions ¶
func CorsMiddleware ¶
func CorsMiddleware(options *Cors, ctx *HttpContext, next func(error))
func IndexByte ¶
IndexByte returns the index of the first instance of c in b, or -1 if c is not present in b.
func MiddlewareWrapper ¶
func MiddlewareWrapper(options *Cors) func(*HttpContext, func(error))
Types ¶
type Atomic ¶
type Atomic[TValue any] struct { // contains filtered or unexported fields }
Atomic is a type-safe atomic value container. The zero value is the zero value of TValue. An Atomic must not be copied after first use.
func (*Atomic[TValue]) CompareAndSwap ¶
CompareAndSwap executes the compare-and-swap operation for x. It returns true if the swap was successful (old matched the current value), false otherwise.
func (*Atomic[TValue]) Load ¶
func (s *Atomic[TValue]) Load() TValue
Load atomically loads and returns the value stored in x. If the stored value is not of type TValue, returns the zero value of TValue.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
A Buffer is a variable-sized buffer of bytes with Buffer.Read and Buffer.Write methods. The zero value for Buffer is an empty buffer ready to use.
func NewBuffer ¶
NewBuffer creates and initializes a new Buffer using buf as its initial contents. The new Buffer takes ownership of buf, and the caller should not use buf after this call. NewBuffer is intended to prepare a Buffer to read existing data. It can also be used to set the initial size of the internal buffer for writing. To do that, buf should have the desired capacity but a length of zero.
In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.
func NewBufferString ¶
NewBufferString creates and initializes a new Buffer using string s as its initial contents. It is intended to prepare a buffer to read an existing string.
In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.
func (*Buffer) AvailableBuffer ¶
AvailableBuffer returns an empty buffer with b.Available() capacity. This buffer is intended to be appended to and passed to an immediately succeeding Buffer.Write call. The buffer is only valid until the next write operation on b.
func (*Buffer) Bytes ¶
Bytes returns a slice of length b.Len() holding the unread portion of the buffer. The slice is valid for use only until the next buffer modification (that is, only until the next call to a method like Buffer.Read, Buffer.Write, Buffer.Reset, or Buffer.Truncate). The slice aliases the buffer content at least until the next buffer modification, so immediate changes to the slice will affect the result of future reads.
func (*Buffer) Cap ¶
Cap returns the capacity of the buffer's underlying byte slice, that is, the total space allocated for the buffer's data.
func (*Buffer) Clone ¶
Clone creates a deep copy of the Buffer. The returned Buffer has the same content and capacity as the original, but it is an independent copy.
func (*Buffer) Grow ¶
Grow grows the buffer's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to the buffer without another allocation. If n is negative, Grow will panic. If the buffer can't grow it will panic with ErrTooLarge.
func (*Buffer) Len ¶
Len returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Bytes()).
func (*Buffer) Next ¶
Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Buffer.Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The slice is only valid until the next call to a read or write method.
func (*Buffer) Read ¶
Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.
func (*Buffer) ReadByte ¶
ReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error io.EOF.
func (*Buffer) ReadBytes ¶
ReadBytes reads until the first occurrence of delim in the input, returning a slice containing the data up to and including the delimiter. If ReadBytes encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadBytes returns err != nil if and only if the returned data does not end in delim.
func (*Buffer) ReadFrom ¶
ReadFrom reads data from r until EOF and appends it to the buffer, growing the buffer as needed. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned. If the buffer becomes too large, ReadFrom will panic with ErrTooLarge.
func (*Buffer) ReadRune ¶
ReadRune reads and returns the next UTF-8-encoded Unicode code point from the buffer. If no bytes are available, the error returned is io.EOF. If the bytes are an erroneous UTF-8 encoding, it consumes one byte and returns U+FFFD, 1.
func (*Buffer) ReadString ¶
ReadString reads until the first occurrence of delim in the input, returning a string containing the data up to and including the delimiter. If ReadString encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadString returns err != nil if and only if the returned data does not end in delim.
func (*Buffer) Reset ¶
func (b *Buffer) Reset()
Reset resets the buffer to be empty, but it retains the underlying storage for use by future writes. Reset is the same as Buffer.Truncate(0).
func (*Buffer) Size ¶
Size returns the original length of the underlying byte slice. Size is the number of bytes available for reading via ReadAt. The returned value is always the same and is not affected by calls to any other method.
func (*Buffer) String ¶
String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>".
To build strings more efficiently, see the strings.Builder type.
func (*Buffer) Truncate ¶
Truncate discards all but the first n unread bytes from the buffer but continues to use the same allocated storage. It panics if n is negative or greater than the length of the buffer.
func (*Buffer) UnreadByte ¶
UnreadByte unreads the last byte returned by the most recent successful read operation that read at least one byte. If a write has happened since the last read, if the last read returned an error, or if the read read zero bytes, UnreadByte returns an error.
func (*Buffer) UnreadRune ¶
UnreadRune unreads the last rune returned by Buffer.ReadRune. If the most recent read or write operation on the buffer was not a successful Buffer.ReadRune, UnreadRune returns an error. (In this regard it is stricter than Buffer.UnreadByte, which will unread the last byte from any read operation.)
func (*Buffer) Write ¶
Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with ErrTooLarge.
func (*Buffer) WriteByte ¶
WriteByte appends the byte c to the buffer, growing the buffer as needed. The returned error is always nil, but is included to match bufio.Writer's WriteByte. If the buffer becomes too large, WriteByte will panic with ErrTooLarge.
func (*Buffer) WriteRune ¶
WriteRune appends the UTF-8 encoding of Unicode code point r to the buffer, returning its length and an error, which is always nil but is included to match bufio.Writer's WriteRune. The buffer is grown as needed; if it becomes too large, WriteRune will panic with ErrTooLarge.
func (*Buffer) WriteString ¶
WriteString appends the contents of s to the buffer, growing the buffer as needed. The return value n is the length of s; err is always nil. If the buffer becomes too large, WriteString will panic with ErrTooLarge.
func (*Buffer) WriteTo ¶
WriteTo writes data to w until the buffer is drained or an error occurs. The return value n is the number of bytes written; it always fits into an int, but it is int64 to match the io.WriterTo interface. Any error encountered during the write is also returned.
type BufferInterface ¶
type BufferInterface interface {
io.ReadWriteSeeker
io.ReaderFrom
io.WriterTo
io.ByteScanner
io.ByteWriter
io.RuneScanner
io.StringWriter
WriteRune(rune) (int, error)
Bytes() []byte
AvailableBuffer() []byte
fmt.Stringer
fmt.GoStringer
Len() int
Size() int64
Cap() int
Available() int
Truncate(int)
Reset()
Grow(int)
Next(int) []byte
ReadBytes(byte) ([]byte, error)
ReadString(byte) (string, error)
Clone() BufferInterface
}
func NewBytesBuffer ¶
func NewBytesBuffer(buf []byte) BufferInterface
func NewBytesBufferReader ¶
func NewBytesBufferReader(r io.Reader) (BufferInterface, error)
func NewBytesBufferString ¶
func NewBytesBufferString(s string) BufferInterface
func NewStringBuffer ¶
func NewStringBuffer(buf []byte) BufferInterface
func NewStringBufferReader ¶
func NewStringBufferReader(r io.Reader) (BufferInterface, error)
func NewStringBufferString ¶
func NewStringBufferString(s string) BufferInterface
type BytesBuffer ¶
type BytesBuffer struct {
*Buffer
}
bytes buffer
func (*BytesBuffer) Clone ¶
func (b *BytesBuffer) Clone() BufferInterface
func (*BytesBuffer) GoString ¶
func (b *BytesBuffer) GoString() string
type CodeMessage ¶
type Cors ¶
type Cors struct {
// Supported types: string, []any, *regexp.Regexp, bool
Origin any
// Supported types: string, []string
Methods any
// Supported types: nil, string, []string
AllowedHeaders any
// Supported types: nil, string, []string
Headers any
// Supported types: string, []string
ExposedHeaders any
MaxAge string
Credentials bool
PreflightContinue bool
OptionsSuccessStatus int
}
type ErrorMessage ¶
type ErrorMessage struct {
*CodeMessage
Req *HttpContext `json:"req,omitempty" msgpack:"req,omitempty"`
Context map[string]any `json:"context,omitempty" msgpack:"context,omitempty"`
}
type EventEmitter ¶
type EventEmitter interface {
// AddListener is an alias for .On(eventName, listener).
AddListener(EventName, ...EventListener) error
// Emit fires a particular event,
// Synchronously calls each of the listeners registered for the event named
// eventName, in the order they were registered,
// passing the supplied arguments to each.
Emit(EventName, ...any)
// EventNames returns an array listing the events for which the emitter has registered listeners.
// The values in the array will be strings.
EventNames() []EventName
// ListenerCount returns the length of all registered listeners to a particular event
ListenerCount(EventName) int
// Listeners returns a copy of the array of listeners for the event named eventName.
Listeners(EventName) []EventListener
// On registers a particular listener for an event, func receiver parameter(s) is/are optional
On(EventName, ...EventListener) error
// Once adds a one time listener function for the event named eventName.
// The next time eventName is triggered, this listener is removed and then invoked.
Once(EventName, ...EventListener) error
// RemoveAllListeners removes all listeners, or those of the specified eventName.
// Note that it will remove the event itself.
// Returns an indicator if event and listeners were found before the remove.
RemoveAllListeners(EventName) bool
// RemoveListener removes given listener from the event named eventName.
// Returns an indicator whether listener was removed
RemoveListener(EventName, EventListener) bool
// Clear removes all events and all listeners, restores Events to an empty value
Clear()
// Len returns the length of all registered events
Len() int
}
EventEmitter is the message/or/event manager
type EventListener ¶
type EventListener func(...any)
Listener is the type of a Listener, it's a func which receives any,optional, arguments from the caller/emmiter
type Events ¶
type Events map[EventName][]EventListener
Events the type for registered listeners, it's just a map[string][]func(...any)
Example ¶
// regiter our events to the default event emmiter
for evt, listeners := range testEvents {
_event.On(evt, listeners...)
}
user := "user1"
room := "room1"
createUser(user)
joinUserTo(user, room)
leaveFromRoom(user, room)
Output: A new User just created! A new User just created, *from second event listener user1 joined to room: room1 user1 left from the room: room1
func (Events) CopyTo ¶
func (e Events) CopyTo(emitter EventEmitter)
CopyTo copies the event listeners to an EventEmitter
type ExtendedError ¶
type ExtendedError struct {
Message string `json:"message" msgpack:"message"` // Error message
Data any `json:"data" msgpack:"data"` // Additional error data
}
ExtendedError represents an error with an associated message and additional data. This type is used across both client and server Socket.IO implementations to provide structured error information, particularly for connection/middleware errors.
func NewExtendedError ¶
func NewExtendedError(message string, data any) *ExtendedError
NewExtendedError creates a new ExtendedError with the given message and data.
func (*ExtendedError) Err ¶
func (e *ExtendedError) Err() error
Err returns the error interface implementation, allowing ExtendedError to be used as an error.
func (*ExtendedError) Error ¶
func (e *ExtendedError) Error() string
Error implements the error interface, returning the error message.
type HttpCompression ¶
type HttpCompression struct {
Threshold int `json:"threshold,omitempty" msgpack:"threshold,omitempty"`
}
type HttpContext ¶
type HttpContext struct {
EventEmitter
Websocket *WebSocketConn
WebTransport *WebTransportConn
Cleanup Callable
// 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 struct{}
func (*HttpContext) Flush ¶
func (c *HttpContext) Flush()
func (*HttpContext) GetStatusCode ¶
func (c *HttpContext) GetStatusCode() int
func (*HttpContext) Headers ¶
func (c *HttpContext) Headers() *ParameterBag
func (*HttpContext) Host ¶
func (c *HttpContext) Host() string
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) PathInfo ¶
func (c *HttpContext) PathInfo() string
func (*HttpContext) Query ¶
func (c *HttpContext) Query() *ParameterBag
func (*HttpContext) Request ¶
func (c *HttpContext) Request() *http.Request
func (*HttpContext) Response ¶
func (c *HttpContext) Response() http.ResponseWriter
func (*HttpContext) ResponseHeaders ¶
func (c *HttpContext) ResponseHeaders() *ParameterBag
func (*HttpContext) Secure ¶
func (c *HttpContext) Secure() bool
func (*HttpContext) SetStatusCode ¶
func (c *HttpContext) SetStatusCode(code int) error
func (*HttpContext) UserAgent ¶
func (c *HttpContext) UserAgent() string
type HttpServer ¶
type HttpServer struct {
EventEmitter
*ServeMux
// contains filtered or unexported fields
}
func NewWebServer ¶
func NewWebServer(defaultHandler http.Handler) *HttpServer
func (*HttpServer) Close ¶
func (s *HttpServer) Close(fn func(error)) (err error)
func (*HttpServer) ListenHTTP3TLS ¶
func (*HttpServer) ListenWebTransportTLS ¶
func (s *HttpServer) ListenWebTransportTLS(addr string, certFile string, keyFile string, quicConfig *quic.Config, fn Callable) *webtransport.Server
type IncomingHttpHeaders ¶
type IncomingHttpHeaders map[string]any // HTTP headers where any represents either string or []string
func (IncomingHttpHeaders) Header ¶
func (h IncomingHttpHeaders) Header() http.Header
type Map ¶
type Map[TKey comparable, TValue any] struct { // contains filtered or unexported fields }
Map is like a Go map[any]any 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. Map.Load, Map.LoadAndDelete, Map.LoadOrStore, Map.Swap, Map.CompareAndSwap, and Map.CompareAndDelete are read operations; Map.Delete, Map.LoadAndDelete, Map.Store, and Map.Swap are write operations; Map.LoadOrStore is a write operation when it returns loaded set to false; Map.CompareAndSwap is a write operation when it returns swapped set to true; and Map.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 entries, resulting in an empty Map.
func (*Map[TKey, TValue]) CompareAndDelete ¶
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 ¶
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]) Load ¶
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 ¶
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 ¶
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 ¶
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.
type ParameterBag ¶
type ParameterBag struct {
// contains filtered or unexported fields
}
func NewParameterBag ¶
func NewParameterBag(parameters map[string][]string) *ParameterBag
func (*ParameterBag) Add ¶
func (p *ParameterBag) Add(key string, value string)
Add adds the value to key. It appends to any existing values associated with key.
func (*ParameterBag) Get ¶
func (p *ParameterBag) Get(key string, _default ...string) (string, bool)
Returns a parameter by name, defaulting to the last value if present.
func (*ParameterBag) GetFirst ¶
func (p *ParameterBag) GetFirst(key string, _default ...string) (string, bool)
Returns the first value of a parameter by name.
func (*ParameterBag) GetLast ¶
func (p *ParameterBag) GetLast(key string, _default ...string) (string, bool)
Returns the last value of a parameter by name.
func (*ParameterBag) Gets ¶
func (p *ParameterBag) Gets(key string, _default ...[]string) ([]string, bool)
Returns all values of a parameter by name.
func (*ParameterBag) Has ¶
func (p *ParameterBag) Has(key string) bool
Returns true if the parameter is defined.
func (*ParameterBag) Replace ¶
func (p *ParameterBag) Replace(parameters map[string][]string)
Replaces the current parameters by a new set.
func (*ParameterBag) Set ¶
func (p *ParameterBag) Set(key string, value string)
Sets a parameter by name.
func (*ParameterBag) With ¶
func (p *ParameterBag) With(parameters map[string][]string)
Adds or replaces the current parameters with a new set.
type ParsedUrlQuery ¶
type ParsedUrlQuery map[string]any // Query parameters where any represents either string or []string
func (ParsedUrlQuery) Query ¶
func (q ParsedUrlQuery) Query() url.Values
type PerMessageDeflate ¶
type PerMessageDeflate struct {
Threshold int `json:"threshold,omitempty" msgpack:"threshold,omitempty"`
}
type ServeMux ¶
type ServeMux struct {
DefaultHandler http.Handler // Default Handler
// contains filtered or unexported fields
}
func NewServeMux ¶
NewServeMux allocates and returns a new ServeMux.
func (*ServeMux) Handle ¶
Handle registers the handler for the given pattern. If a handler already exists for pattern, Handle panics.
func (*ServeMux) HandleFunc ¶
HandleFunc registers the handler function for the given pattern.
func (*ServeMux) Handler ¶
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.
type Set ¶
type Set[KType comparable] struct { // contains filtered or unexported fields }
func NewSet ¶
func NewSet[KType comparable](keys ...KType) *Set[KType]
NewSet creates a new Set and initializes it with the provided keys.
func (*Set[KType]) Keys ¶
func (s *Set[KType]) Keys() []KType
Keys returns a slice containing all keys in the set.
func (*Set[KType]) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Set[KType]) MarshalMsgpack ¶
MarshalMsgpack implements the msgpack.Marshaler interface.
func (*Set[KType]) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Set[KType]) UnmarshalMsgpack ¶
UnmarshalMsgpack implements the msgpack.Unmarshaler interface.
type Slice ¶
type Slice[T any] struct { // contains filtered or unexported fields }
Slice is a generic type that holds elements of any type.
func (*Slice[T]) All ¶
func (s *Slice[T]) All() []T
All returns a copy of all the elements in the slice.
func (*Slice[T]) AllAndClear ¶
func (s *Slice[T]) AllAndClear() []T
AllAndClear returns all the elements in the slice and clears the slice.
func (*Slice[T]) DoRead ¶
func (s *Slice[T]) DoRead(op func([]T))
DoRead allows a custom read-only operation on the slice with a read lock.
func (*Slice[T]) DoWrite ¶
func (s *Slice[T]) DoWrite(op func([]T) []T)
DoWrite allows a custom write operation on the slice with a write lock.
func (*Slice[T]) Filter ¶
Filter returns a new slice containing all elements that satisfy the provided function.
func (*Slice[T]) FindIndex ¶
FindIndex returns the index of the first element that satisfies the provided function. If no element satisfies the function, it returns -1.
func (*Slice[T]) Get ¶
Get returns the element at the specified index, or an error if the index is out of bounds.
func (*Slice[T]) Pop ¶
Pop removes the last element from the slice and returns it, or an error if the slice is empty.
func (*Slice[T]) Push ¶
Push adds one or more elements to the end of the slice and returns the new length.
func (*Slice[T]) RangeAndSplice ¶
func (s *Slice[T]) RangeAndSplice(f func(T, int) (bool, int, int, []T), reverse ...bool) ([]T, error)
RangeAndSplice executes a function on each slice element and performs splice operations based on the function's return values. reverse is an optional parameter; if provided and true, the iteration will be in reverse order.
func (*Slice[T]) Remove ¶
Remove removes the first element in the slice that satisfies the conditional function.
func (*Slice[T]) RemoveAll ¶
RemoveAll removes elements from the slice that satisfy the provided condition function.
func (*Slice[T]) Replace ¶
func (s *Slice[T]) Replace(elements []T)
Replace replaces the slice elements with the given elements.
func (*Slice[T]) Set ¶
Set sets the element at the specified index, and returns an error if the index is out of bounds.
func (*Slice[T]) Shift ¶
Shift removes the first element from the slice and returns it, or an error if the slice is empty.
type StringBuffer ¶
type StringBuffer struct {
*Buffer
}
string buffer
func (*StringBuffer) Clone ¶
func (sb *StringBuffer) Clone() BufferInterface
func (*StringBuffer) GoString ¶
func (sb *StringBuffer) GoString() string
func (*StringBuffer) MarshalJSON ¶
func (sb *StringBuffer) MarshalJSON() ([]byte, error)
MarshalJSON returns sb as the JSON encoding of m.
func (*StringBuffer) UnmarshalJSON ¶
func (sb *StringBuffer) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes a JSON-encoded string into the StringBuffer.
type WebSocketConn ¶
type WebSocketConn struct {
EventEmitter
*websocket.Conn
}
func (*WebSocketConn) Close ¶
func (t *WebSocketConn) Close() error
type WebTransportConn ¶
type WebTransportConn struct {
EventEmitter
*webtransport.Conn
}
func (*WebTransportConn) CloseWithError ¶
func (t *WebTransportConn) CloseWithError(code wt.SessionErrorCode, msg string) error