normalize

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: Unlicense Imports: 8 Imported by: 0

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 MsgString

func MsgString(prefix Reason, format string, params ...any) string

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

func URL

func URL[V constraints.Bytes](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) Errorf

func (r Reason) Errorf(format string, params ...any) (err error)

Errorf allows creation of a full Reason text with a printf style as an error.

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

Source Files

  • normalize.go

Jump to

Keyboard shortcuts

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