types

package
v3.0.0-rc.13 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 27 Imported by: 13

Documentation

Index

Examples

Constants

View Source
const (
	// Version current version number
	EventVersion = "0.0.3"
)
View Source
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

View Source
var (
	ErrResponseAlreadyWritten = errors.New("response has already been written")
	ErrInvalidStatusCode      = errors.New("invalid status code")
)
View Source
var (
	ErrSliceEmpty        = errors.New("slice is empty")
	ErrIndexOutOfBounds  = errors.New("index out of bounds")
	ErrInvalidSliceRange = errors.New("invalid slice range")
)

Define custom error types

View Source
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

func IndexByte(b []byte, c byte) int

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

func (s *Atomic[TValue]) CompareAndSwap(old, new TValue) (swapped bool)

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.

func (*Atomic[TValue]) Store

func (s *Atomic[TValue]) Store(val TValue)

Store atomically stores val into x.

func (*Atomic[TValue]) Swap

func (s *Atomic[TValue]) Swap(new TValue) (old TValue)

Swap atomically stores new into x and returns the previous value. If the previous 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

func NewBuffer(buf []byte) *Buffer

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

func NewBufferString(s string) *Buffer

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) Available

func (b *Buffer) Available() int

Available returns how many bytes are unused in the buffer.

func (*Buffer) AvailableBuffer

func (b *Buffer) AvailableBuffer() []byte

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

func (b *Buffer) Bytes() []byte

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

func (b *Buffer) Cap() int

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

func (b *Buffer) Clone() *Buffer

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

func (b *Buffer) Grow(n int)

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

func (b *Buffer) Len() int

Len returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Bytes()).

func (*Buffer) Next

func (b *Buffer) Next(n int) []byte

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

func (b *Buffer) Read(p []byte) (n int, err error)

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

func (b *Buffer) ReadByte() (byte, error)

ReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error io.EOF.

func (*Buffer) ReadBytes

func (b *Buffer) ReadBytes(delim byte) (line []byte, err error)

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

func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)

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

func (b *Buffer) ReadRune() (r rune, size int, err error)

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

func (b *Buffer) ReadString(delim byte) (line string, err error)

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) Seek

func (b *Buffer) Seek(offset int64, whence int) (int64, error)

Seek implements the io.Seeker interface.

func (*Buffer) Size

func (b *Buffer) Size() int64

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

func (b *Buffer) String() 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

func (b *Buffer) Truncate(n int)

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

func (b *Buffer) UnreadByte() error

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

func (b *Buffer) UnreadRune() error

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

func (b *Buffer) Write(p []byte) (n int, err error)

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

func (b *Buffer) WriteByte(c byte) error

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

func (b *Buffer) WriteRune(r rune) (n int, err error)

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

func (b *Buffer) WriteString(s string) (n int, err error)

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

func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)

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 Callable

type Callable = func()

type CodeMessage

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

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

func NewEventEmitter

func NewEventEmitter() EventEmitter

New returns a new, empty, EventEmitter

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 EventName

type EventName string

EventName is just a type of string, it's the event name

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

func (*HttpContext) Write

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

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) 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 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 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[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

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) (swapped 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 Optional

type Optional[T any] interface {
	IsPresent() bool
	IsEmpty() bool
	Get() T
}

func NewSome

func NewSome[T any](value T) Optional[T]

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) All

func (p *ParameterBag) All() map[string][]string

Returns the parameters.

func (*ParameterBag) Count

func (p *ParameterBag) Count() int

Returns the number of parameters.

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) Keys

func (p *ParameterBag) Keys() []string

Returns the parameter keys.

func (*ParameterBag) Peek

func (p *ParameterBag) Peek(key string, _default ...string) string

func (*ParameterBag) Remove

func (p *ParameterBag) Remove(key string)

Removes a parameter.

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

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[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]) Add

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

Add adds the provided keys to the set.

func (*Set[KType]) All

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

All returns a copy of the set's internal map.

func (*Set[KType]) Clear

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

Clear removes all items from the set.

func (*Set[KType]) Delete

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

Delete removes the provided keys from the set.

func (*Set[KType]) Has

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

Has checks if the set contains the provided key.

func (*Set[KType]) Keys

func (s *Set[KType]) Keys() []KType

Keys returns a slice containing all keys in the set.

func (*Set[KType]) Len

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

Len returns the number of items in the set.

func (*Set[KType]) MarshalJSON

func (s *Set[KType]) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Set[KType]) MarshalMsgpack

func (s *Set[KType]) MarshalMsgpack() ([]byte, error)

MarshalMsgpack implements the msgpack.Marshaler interface.

func (*Set[KType]) UnmarshalJSON

func (s *Set[KType]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Set[KType]) UnmarshalMsgpack

func (s *Set[KType]) UnmarshalMsgpack(data []byte) error

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 NewSlice

func NewSlice[T any](elements ...T) *Slice[T]

NewSlice creates and returns a new Slice.

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]) Clear

func (s *Slice[T]) Clear()

Clear removes all the elements in 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

func (s *Slice[T]) Filter(condition func(T) bool) (filtered []T)

Filter returns a new slice containing all elements that satisfy the provided function.

func (*Slice[T]) FindIndex

func (s *Slice[T]) FindIndex(condition func(T) bool) int

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

func (s *Slice[T]) Get(index int) (element T, err error)

Get returns the element at the specified index, or an error if the index is out of bounds.

func (*Slice[T]) Len

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

Len returns the number of elements in the slice.

func (*Slice[T]) Pop

func (s *Slice[T]) Pop() (element T, err error)

Pop removes the last element from the slice and returns it, or an error if the slice is empty.

func (*Slice[T]) Push

func (s *Slice[T]) Push(elements ...T) int

Push adds one or more elements to the end of the slice and returns the new length.

func (*Slice[T]) Range

func (s *Slice[T]) Range(f func(T, int) bool, reverse ...bool)

Range executes the provided function once for each slice element.

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

func (s *Slice[T]) Remove(condition func(T) bool)

Remove removes the first element in the slice that satisfies the conditional function.

func (*Slice[T]) RemoveAll

func (s *Slice[T]) RemoveAll(condition func(T) bool)

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

func (s *Slice[T]) Set(index int, element T) error

Set sets the element at the specified index, and returns an error if the index is out of bounds.

func (*Slice[T]) Shift

func (s *Slice[T]) Shift() (element T, err error)

Shift removes the first element from the slice and returns it, or an error if the slice is empty.

func (*Slice[T]) Slice

func (s *Slice[T]) Slice(start, end int) ([]T, error)

Slice returns a new slice containing the elements between start and end.

func (*Slice[T]) Splice

func (s *Slice[T]) Splice(start, deleteCount int, insert ...T) ([]T, error)

Splice removes elements from the slice at the specified start index and inserts new elements at that position.

func (*Slice[T]) Unshift

func (s *Slice[T]) Unshift(elements ...T) int

Unshift adds one or more elements to the beginning of the slice and returns the new length.

type Some

type Some[T any] struct {
	// contains filtered or unexported fields
}

func (*Some[T]) Get

func (s *Some[T]) Get() T

func (*Some[T]) IsEmpty

func (s *Some[T]) IsEmpty() bool

IsEmpty returns true if this Some is nil

func (*Some[T]) IsPresent

func (s *Some[T]) IsPresent() bool

IsPresent returns true if this Some is not nil

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 Void

type Void = struct{}
var (
	NULL Void
)

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

Jump to

Keyboard shortcuts

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