host

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(host ...string) *block.Block

New creates new host block

Example

Route by virtual host: host.New returns a block that only runs its own inner chain when the request's Host matches. Names are matched case-insensitively and ignore any :port; a leading "*." matches all subdomains and a lone "*" matches every host.

package main

import (
	"github.com/moonrhythm/parapet"
	"github.com/moonrhythm/parapet/pkg/host"
)

func main() {
	s := parapet.New()

	// app.example.com and all of its subdomains go to one upstream...
	app := host.New("app.example.com", "*.app.example.com")
	// app.Use(upstream.SingleHost("10.0.0.1:8080", nil))
	s.Use(app)

	// ...while the bare apex domain goes somewhere else.
	web := host.New("example.com")
	// web.Use(upstream.SingleHost("10.0.0.2:8080", nil))
	s.Use(web)
}

func NewCIDR

func NewCIDR(pattern ...string) *block.Block

NewCIDR creates new CIDR host matcher block.

Panics on any unparsable CIDR so a configuration typo cannot silently collapse the matcher to an empty (always-false) set.

Example

Route by client IP instead of name: host.NewCIDR matches when the request's Host is an IP literal inside one of the given CIDR ranges. It panics on an unparsable CIDR, so a config typo fails loudly at startup.

package main

import (
	"github.com/moonrhythm/parapet"
	"github.com/moonrhythm/parapet/pkg/host"
)

func main() {
	s := parapet.New()

	internal := host.NewCIDR("10.0.0.0/8", "192.168.0.0/16")
	// internal.Use(...) — handlers reachable only from the private network.
	s.Use(internal)
}

func StripPort added in v0.11.2

func StripPort() parapet.Middleware

StripPort strips port from request's host

Example

Normalize the request host before any host-based routing runs: lowercase it and drop the :port. host.New already normalizes internally, but installing these first means every downstream middleware sees a clean Host too.

package main

import (
	"github.com/moonrhythm/parapet"
	"github.com/moonrhythm/parapet/pkg/host"
)

func main() {
	s := parapet.New()
	s.Use(host.ToLower())
	s.Use(host.StripPort())

	s.Use(host.New("example.com"))
}

func ToLower added in v0.11.2

func ToLower() parapet.Middleware

ToLower converts request's host to lowercase

Types

This section is empty.

Jump to

Keyboard shortcuts

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