urlpath

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(r *http.Request, schema Schema) error

Parse will parse the URL path vars from r given the element names and parsers defined in schema.

This method only works with requests being processed by handlers of a gorilla/mux.

func ParseValues

func ParseValues(values map[string]string, schema Schema) error

ParseValues will parse the parameters in vars given the element names and parsers defined in schema.

Most use cases will be parsing values coming from an *http.Request, which can be done conveniently with Parse.

Types

type Parameter

type Parameter string

A Parameter is a named element of a URL route, encoded such that a gorilla router interprets it as a path parameter.

func (Parameter) Name

func (p Parameter) Name() string

Name returns the name of the parameter.

func (Parameter) String

func (p Parameter) String() string

type Parser

type Parser interface {
	Parse(string) error
}

A Parser parses raw input into a destination variable.

func Int

func Int(i *int) Parser

Int creates a Parser that will parse a path element into i.

func String

func String(s *string) Parser

String creates a parser that will parse a path element into s.

func UInt64

func UInt64(i *uint64) Parser

type Schema

type Schema map[Parameter]Parser

A Schema describes how path variables should be parsed. Currently only int and string types are supported.

Jump to

Keyboard shortcuts

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