normalize

package
v0.3.0-vainstr Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: Unlicense Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package normalize is a set of tools for cleaning up URL s and formatting nostr OK and CLOSED messages.

Index

Constants

This section is empty.

Variables

View Source
var (
	WS    = []byte("ws://")
	WSS   = []byte("wss://")
	HTTP  = []byte("http://")
	HTTPS = []byte("https://")
)
View Source
var (
	AuthRequired = Reason("auth-required")
	PoW          = Reason("pow")
	Duplicate    = Reason("duplicate")
	Blocked      = Reason("blocked")
	RateLimited  = Reason("rate-limited")
	Invalid      = Reason("invalid")
	Error        = Reason("error")
	Unsupported  = Reason("unsupported")
	Restricted   = Reason("restricted")
)

Functions

func Msg

func Msg(prefix Reason, format string, params ...any) []byte

Msg constructs a properly formatted message with a machine-readable prefix for OK and CLOSED envelopes.

func URL

func URL[V string | []byte](v V) (b []byte)

URL normalizes the URL

- Adds wss:// to addresses without a port, or with 443 that have no protocol prefix

- Adds ws:// to addresses with any other port

- Converts http/s to ws/s

Types

type Reason

type Reason []byte

Reason is the machine-readable prefix before the colon in an OK or CLOSED envelope message. Below are the most common kinds that are mentioned in NIP-01.

func (Reason) B

func (r Reason) B() []byte

B returns the Reason as a byte slice.

func (Reason) F

func (r Reason) F(format string, params ...any) []byte

F allows creation of a full Reason text with a printf style format.

func (Reason) IsPrefix

func (r Reason) IsPrefix(reason []byte) bool

IsPrefix returns whether a text contains the same Reason prefix.

func (Reason) S

func (r Reason) S() string

S returns the Reason as a string

Jump to

Keyboard shortcuts

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