segment

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2022 License: MIT Imports: 5 Imported by: 4

Documentation

Overview

Package segment provide segment based routing

segment based routing is considered low level, use path/segment based routing for high level routing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EndOr

func EndOr(otherwise http.HandlerFunc) func(http.HandlerFunc) http.HandlerFunc

EndOr return middleware that only will execute h when its position is last segment of the path if otherwise is nil, defhandler.StatusNotFound is used.

func Get

func Get(r *http.Request, tag string) (string, bool)

Get return tagged segment

func Last added in v1.1.0

Last is synonym for MustEnd

func MustEnd

func MustEnd(h http.HandlerFunc) http.HandlerFunc

MustEnd same as EndOr with otherwise equal to nil.

func Param

func Param(r *http.Request, tag string) string

Param do the same thing as Get, but panic when tag is not found in the segment

func Rest

func Rest(r *http.Request) []string

Rest return rest of the segment

func Split

func Split(r *http.Request) ([]string, []string)

Split return processed and the rest of the segments

func Stripper

func Stripper(next http.HandlerFunc) http.HandlerFunc

Stripper is middleware for stripping processed segment from r.URL.Path

func Tag

func Tag(tag string, next http.HandlerFunc) http.HandlerFunc

Tag return helper that will tag current segment and process to next segment

The tagged segment can be retrieved later via Get function.

Types

type H

type H map[string]http.HandlerFunc

H is type for mapping segment and its handler

func (H) C

func (h H) C() http.HandlerFunc

C same as Compile with def equal to nil

func (H) Compile

func (h H) Compile(def http.HandlerFunc) http.HandlerFunc

Compile into single http.HandlerFunc. if def is nil, default handler is defhandler.StatusNotFound

Directories

Path Synopsis
Package shifter provide simple routing by dividing path into its segment
Package shifter provide simple routing by dividing path into its segment

Jump to

Keyboard shortcuts

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