parth

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2018 License: MIT Imports: 3 Imported by: 0

README

parth

go get github.com/codemodus/parth

Package parth provides functions for accessing path segments.

When returning an int/uint of any size, the first whole number within the specified segment will be returned. When returning a float of any size, the first decimal number within the specified segment will be returned.

Usage

func SegmentToBool(path string, i int) (bool, error)
func SegmentToFloat32(path string, i int) (float32, error)
func SegmentToFloat64(path string, i int) (float64, error)
func SegmentToInt(path string, i int) (int, error)
func SegmentToInt16(path string, i int) (int16, error)
func SegmentToInt32(path string, i int) (int32, error)
func SegmentToInt64(path string, i int) (int64, error)
func SegmentToInt8(path string, i int) (int8, error)
func SegmentToString(path string, i int) (string, error)
func SegmentToUint(path string, i int) (uint, error)
func SegmentToUint16(path string, i int) (uint16, error)
func SegmentToUint32(path string, i int) (uint32, error)
func SegmentToUint64(path string, i int) (uint64, error)
func SegmentToUint8(path string, i int) (uint8, error)
func SpanToString(path string, firstSeg, lastSeg int) (string, error)
func SubSegToBool(path, key string) (bool, error)
func SubSegToFloat32(path, key string) (float32, error)
func SubSegToFloat64(path, key string) (float64, error)
func SubSegToInt(path, key string) (int, error)
func SubSegToInt16(path, key string) (int16, error)
func SubSegToInt32(path, key string) (int32, error)
func SubSegToInt64(path, key string) (int64, error)
func SubSegToInt8(path, key string) (int8, error)
func SubSegToString(path, key string) (string, error)
func SubSegToUint(path, key string) (uint, error)
func SubSegToUint16(path, key string) (uint16, error)
func SubSegToUint32(path, key string) (uint32, error)
func SubSegToUint64(path, key string) (uint64, error)
func SubSegToUint8(path, key string) (uint8, error)
func SubSpanToString(path, key string, lastSeg int) (string, error)
type Parth
    func New(path string) *Parth
    func NewFromSpan(path string, firstSeg, lastSeg int) *Parth
    func NewFromSubSpan(path, key string, lastSeg int) *Parth
    func (p *Parth) Err() error
    func (p *Parth) SegmentToBool(i int) bool
    func (p *Parth) SegmentToFloat32(i int) float32
    func (p *Parth) SegmentToFloat64(i int) float64
    func (p *Parth) SegmentToInt(i int) int
    func (p *Parth) SegmentToInt16(i int) int16
    func (p *Parth) SegmentToInt32(i int) int32
    func (p *Parth) SegmentToInt64(i int) int64
    func (p *Parth) SegmentToInt8(i int) int8
    func (p *Parth) SegmentToString(i int) string
    func (p *Parth) SegmentToUint(i int) uint
    func (p *Parth) SegmentToUint16(i int) uint16
    func (p *Parth) SegmentToUint32(i int) uint32
    func (p *Parth) SegmentToUint64(i int) uint64
    func (p *Parth) SegmentToUint8(i int) uint8
    func (p *Parth) SpanToString(firstSeg, lastSeg int) string
    func (p *Parth) SubSegToBool(key string) bool
    func (p *Parth) SubSegToFloat32(key string) float32
    func (p *Parth) SubSegToFloat64(key string) float64
    func (p *Parth) SubSegToInt(key string) int
    func (p *Parth) SubSegToInt16(key string) int16
    func (p *Parth) SubSegToInt32(key string) int32
    func (p *Parth) SubSegToInt64(key string) int64
    func (p *Parth) SubSegToInt8(key string) int8
    func (p *Parth) SubSegToString(key string) string
    func (p *Parth) SubSegToUint(key string) uint
    func (p *Parth) SubSegToUint16(key string) uint16
    func (p *Parth) SubSegToUint32(key string) uint32
    func (p *Parth) SubSegToUint64(key string) uint64
    func (p *Parth) SubSegToUint8(key string) uint8
    func (p *Parth) SubSpanToString(key string, lastSeg int) string
Setup (Simple)
import (
	"fmt"

	"github.com/codemodus/parth"
)

func main() {
    r, err := http.NewRequest("GET", "/api/v1/user/3", nil)
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
    }

    if i, err := parth.SubSegToInt(r.URL.Path, "user"); err == nil {
        fmt.Printf("Type = %T, Value = %v\n", i, i) // Outputs: Type = int, Value = 3
    }
}
Setup (Detail)
import (
	"fmt"

	"github.com/codemodus/parth"
)

func main() {
    r, err := http.NewRequest("GET", "/zero/1/2/nn3.3nn/key/5.5", nil)
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
    }

    printFmt := "Type = %T, Value = %v\n"

    if s, err := parth.SegmentToString(r.URL.Path, 0); err == nil {
        fmt.Printf(printFmt, s, s) // Outputs: Type = string, Value = zero
    }

    if b, err := parth.SegmentToBool(r.URL.Path, 1); err == nil {
        fmt.Printf(printFmt, b, b) // Outputs: Type = bool, Value = true
    }

    if i, err := parth.SegmentToInt(r.URL.Path, -4); err == nil {
        fmt.Printf(printFmt, i, i) // Outputs: Type = int, Value = 2
    }

    if f, err := parth.SegmentToFloat32(r.URL.Path, 3); err == nil {
        fmt.Printf(printFmt, f, f) // Outputs: Type = float32, Value = 3.3
    }

    if s, err := parth.SpanToString(r.URL.Path, 0, -3); err == nil {
        fmt.Printf(printFmt, s, s) // Outputs: Type = string, Value = /zero/1/2
    }

    if i, err := parth.SubSegToInt(r.URL.Path, "key"); err == nil {
        fmt.Printf(printFmt, i, i) // Outputs: Type = int, Value = 5
    }

    if s, err := parth.SubSpanToString(r.URL.Path, "zero", 2); err == nil {
        fmt.Printf(printFmt, s, s) // Outputs: Type = string, Value = /1/2
    }
}
Setup (ParthType)
import (
	"fmt"

	"github.com/codemodus/parth"
)

func main() {
    r, err := http.NewRequest("GET", "/zero/1/2/nn3.3nn/key/5.5", nil)
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
    }

    printFmt := "Type = %T, Value = %v\n"

    p := parth.New(r.URL.Path)

    s := p.SegmentToString(0)
    f := p.SegmentToFloat32(3)
    ss := p.SubSpanToString("zero", 2)

    if p.Err() == nil {
        fmt.Printf(printFmt, s, s)   // Outputs: Type = string, Value = zero
        fmt.Printf(printFmt, f, f)   // Outputs: Type = float32, Value = 3.3
        fmt.Printf(printFmt, ss, ss) // Outputs: Type = string, Value = /1/2
    }
}

More Info

Path parameters via global, alternate HandlerFunc, or Context? Why?

The most obvious use case for parth is when working with http.Request.URL.Path within an http.Handler. parth is fast enough that it can be used 20+ times when compared to similar router-parameter/Context usage. Why pass data that is already being passed? The request type holds URL data and parth loves handling it! Additionally, parth takes care of parsing segments into the types actually needed. It's not only fast, it does more, and requires less code.

SpanToString

SpanToString receives two int values representing path segments, and returns the content between those segments, including the first segment, as a string and a nil error. If any error is encountered, a zero value string and error are returned. The segments can be of negative values, but the first segment must come before the last segment. Providing a 0 int for the second int is a special case which indicates the end of the path.

SubSpanToString

SubSpanToString receives a key which is used to search for the first matching path segment and an int value representing a second segment by it's distance from the matched segment, then returns the content between those segments as a string and a nil error. If any error is encountered, a zero value string and error are returned. The int representing a segment can be of negative values. Providing a 0 int is a special case which indicates the end of the path.

Caution (restated): First Whole, First Decimal

When returning an int/uint of any size, the first whole number within the specified segment will be returned. When returning a float of any size, the first decimal number within the specified segment will be returned.

Please review the test cases for working examples.

Documentation

View the GoDoc

Benchmarks

Go 1.6

benchmark                     iter      time/iter   bytes alloc        allocs
---------                     ----      ---------   -----------        ------
BenchmarkStandardInt-8     5000000   371.00 ns/op       64 B/op   2 allocs/op
BenchmarkParthInt-8       20000000    78.50 ns/op        0 B/op   0 allocs/op
BenchmarkParthIntNeg-8    30000000    52.70 ns/op        0 B/op   0 allocs/op
BenchmarkParthSubSeg-8    20000000    93.60 ns/op        0 B/op   0 allocs/op
BenchmarkStandardSpan-8    3000000   527.00 ns/op       88 B/op   4 allocs/op
BenchmarkParthSpan-8      50000000    29.70 ns/op        0 B/op   0 allocs/op
BenchmarkParthSubSpan-8   20000000    82.60 ns/op        0 B/op   0 allocs/op


Go 1.7

benchmark                                 iter       time/iter   bytes alloc        allocs
---------                                 ----       ---------   -----------        ------
BenchmarkVsCtxParthString2x-8         20000000     83.80 ns/op        0 B/op   0 allocs/op
BenchmarkVsCtxParthString3x-8         10000000    125.00 ns/op        0 B/op   0 allocs/op
BenchmarkVsCtxContextGetSetGet-8       1000000   1629.00 ns/op      336 B/op   5 allocs/op
BenchmarkVsCtxContextGetSetGetGet-8    1000000   2044.00 ns/op      352 B/op   6 allocs/op

Documentation

Overview

Package parth provides functions for accessing path segments.

When returning an int/uint of any size, the first whole number within the specified segment will be returned. When returning a float of any size, the first decimal number within the specified segment will be returned.

Example
package main

import (
	"fmt"
	"net/http"
	"os"

	"github.com/codemodus/parth"
)

func main() {
	r, err := http.NewRequest("GET", "/zero/1/2/nn3.3nn/key/5.5", nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	}

	printFmt := "Type = %T, Value = %v\n"

	if s, err := parth.SegmentToString(r.URL.Path, 0); err == nil {
		fmt.Printf(printFmt, s, s)
	}

	if b, err := parth.SegmentToBool(r.URL.Path, 1); err == nil {
		fmt.Printf(printFmt, b, b)
	}

	if i, err := parth.SegmentToInt(r.URL.Path, -4); err == nil {
		fmt.Printf(printFmt, i, i)
	}

	if f, err := parth.SegmentToFloat32(r.URL.Path, 3); err == nil {
		fmt.Printf(printFmt, f, f)
	}

	if s, err := parth.SpanToString(r.URL.Path, 0, -3); err == nil {
		fmt.Printf(printFmt, s, s)
	}

	if i, err := parth.SubSegToInt(r.URL.Path, "key"); err == nil {
		fmt.Printf(printFmt, i, i)
	}

	if s, err := parth.SubSpanToString(r.URL.Path, "zero", 2); err == nil {
		fmt.Printf(printFmt, s, s)
	}

}
Output:

Type = string, Value = zero
Type = bool, Value = true
Type = int, Value = 2
Type = float32, Value = 3.3
Type = string, Value = /zero/1/2
Type = int, Value = 5
Type = string, Value = /1/2
Example (ParthType)
package main

import (
	"fmt"
	"net/http"
	"os"

	"github.com/codemodus/parth"
)

func main() {
	r, err := http.NewRequest("GET", "/zero/1/2/nn3.3nn/key/5.5", nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	}

	printFmt := "Type = %T, Value = %v\n"

	p := parth.New(r.URL.Path)

	s := p.SegmentToString(0)
	f := p.SegmentToFloat32(3)
	ss := p.SubSpanToString("zero", 2)

	if p.Err() == nil {
		fmt.Printf(printFmt, s, s)
		fmt.Printf(printFmt, f, f)
		fmt.Printf(printFmt, ss, ss)
	}

}
Output:

Type = string, Value = zero
Type = float32, Value = 3.3
Type = string, Value = /1/2

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrFirstSegNotExist = errors.New("first segment index does not exist")
	ErrLastSegNotExist  = errors.New("last segment index does not exist")
	ErrSegOrderReversed = errors.New("first segment must precede last segment")
	ErrSegNotExist      = errors.New("segment index does not exist")
	ErrIntNotFound      = errors.New("segment does not contain int")
	ErrFloatNotFound    = errors.New("segment does not contain float")
	ErrUnparsable       = errors.New("unable to parse segment")

	ErrIndexBad      = errors.New("index cannot be found")
	ErrIndexNotFound = errors.New("no index found")
)

Err{Name} values are for error identification.

Functions

func SegmentToBool

func SegmentToBool(path string, i int) (bool, error)

SegmentToBool receives an int representing a path segment, then returns both the specified segment as a bool and a nil error. If any error is encountered, a zero value bool and error are returned.

func SegmentToFloat32

func SegmentToFloat32(path string, i int) (float32, error)

SegmentToFloat32 receives an int representing a path segment, then returns both the specified segment as a float32 and a nil error. If any error is encountered, a zero value float32 and error are returned.

func SegmentToFloat64

func SegmentToFloat64(path string, i int) (float64, error)

SegmentToFloat64 receives an int representing a path segment, then returns both the specified segment as a float64 and a nil error. If any error is encountered, a zero value float64 and error are returned.

func SegmentToInt

func SegmentToInt(path string, i int) (int, error)

SegmentToInt receives an int representing a path segment, then returns both the specified segment as an int and a nil error. If any error is encountered, a zero value int and error are returned.

func SegmentToInt16

func SegmentToInt16(path string, i int) (int16, error)

SegmentToInt16 receives an int representing a path segment, then returns both the specified segment as an int16 and a nil error. If any error is encountered, a zero value int16 and error are returned.

func SegmentToInt32

func SegmentToInt32(path string, i int) (int32, error)

SegmentToInt32 receives an int representing a path segment, then returns both the specified segment as an int32 and a nil error. If any error is encountered, a zero value int32 and error are returned.

func SegmentToInt64

func SegmentToInt64(path string, i int) (int64, error)

SegmentToInt64 receives an int representing a path segment, then returns both the specified segment as an int64 and a nil error. If any error is encountered, a zero value int64 and error are returned.

func SegmentToInt8

func SegmentToInt8(path string, i int) (int8, error)

SegmentToInt8 receives an int representing a path segment, then returns both the specified segment as an int8 and a nil error. If any error is encountered, a zero value int8 and error are returned.

func SegmentToString

func SegmentToString(path string, i int) (string, error)

SegmentToString receives an int representing a path segment, then returns both the specified segment as a string and a nil error. If any error is encountered, a zero value string and error are returned.

func SegmentToUint added in v1.1.2

func SegmentToUint(path string, i int) (uint, error)

SegmentToUint receives an int representing a path segment, then returns both the specified segment as a uint and a nil error. If any error is encountered, a zero value uint and error are returned.

func SegmentToUint16 added in v1.1.2

func SegmentToUint16(path string, i int) (uint16, error)

SegmentToUint16 receives an int representing a path segment, then returns both the specified segment as a uint16 and a nil error. If any error is encountered, a zero value uint16 and error are returned.

func SegmentToUint32 added in v1.1.2

func SegmentToUint32(path string, i int) (uint32, error)

SegmentToUint32 receives an int representing a path segment, then returns both the specified segment as a uint32 and a nil error. If any error is encountered, a zero value uint32 and error are returned.

func SegmentToUint64 added in v1.1.2

func SegmentToUint64(path string, i int) (uint64, error)

SegmentToUint64 receives an int representing a path segment, then returns both the specified segment as a uint64 and a nil error. If any error is encountered, a zero value uint64 and error are returned.

func SegmentToUint8 added in v1.1.2

func SegmentToUint8(path string, i int) (uint8, error)

SegmentToUint8 receives an int representing a path segment, then returns both the specified segment as a uint8 and a nil error. If any error is encountered, a zero value uint8 and error are returned.

func SpanToString

func SpanToString(path string, firstSeg, lastSeg int) (string, error)

SpanToString receives two int values representing path segments, and returns the content between those segments, including the first segment, as a string and a nil error. If any error is encountered, a zero value string and error are returned. The segments can be of negative values, but the first segment must come before the last segment. Providing a 0 int for the second int is a special case which indicates the end of the path.

func SubSegToBool

func SubSegToBool(path, key string) (bool, error)

SubSegToBool receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as a bool and a nil error. If any error is encountered, a zero value bool and error are returned.

func SubSegToFloat32

func SubSegToFloat32(path, key string) (float32, error)

SubSegToFloat32 receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as a float32 and a nil error. If any error is encountered, a zero value float32 and error are returned.

func SubSegToFloat64

func SubSegToFloat64(path, key string) (float64, error)

SubSegToFloat64 receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as a float64 and a nil error. If any error is encountered, a zero value float64 and error are returned.

func SubSegToInt

func SubSegToInt(path, key string) (int, error)

SubSegToInt receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as an int and a nil error. If any error is encountered, a zero value int and error are returned.

func SubSegToInt16

func SubSegToInt16(path, key string) (int16, error)

SubSegToInt16 receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as an int16 and a nil error. If any error is encountered, a zero value int16 and error are returned.

func SubSegToInt32

func SubSegToInt32(path, key string) (int32, error)

SubSegToInt32 receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as an int32 and a nil error. If any error is encountered, a zero value int32 and error are returned.

func SubSegToInt64

func SubSegToInt64(path, key string) (int64, error)

SubSegToInt64 receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as an int64 and a nil error. If any error is encountered, a zero value int64 and error are returned.

func SubSegToInt8

func SubSegToInt8(path, key string) (int8, error)

SubSegToInt8 receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as an int8 and a nil error. If any error is encountered, a zero value int8 and error are returned.

func SubSegToString

func SubSegToString(path, key string) (string, error)

SubSegToString receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as a string and a nil error. If any error is encountered, a zero value string and error are returned.

func SubSegToUint added in v1.1.2

func SubSegToUint(path, key string) (uint, error)

SubSegToUint receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as a uint and a nil error. If any error is encountered, a zero value uint and error are returned.

func SubSegToUint16 added in v1.1.2

func SubSegToUint16(path, key string) (uint16, error)

SubSegToUint16 receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as a uint16 and a nil error. If any error is encountered, a zero value uint16 and error are returned.

func SubSegToUint32 added in v1.1.2

func SubSegToUint32(path, key string) (uint32, error)

SubSegToUint32 receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as a uint32 and a nil error. If any error is encountered, a zero value uint32 and error are returned.

func SubSegToUint64 added in v1.1.2

func SubSegToUint64(path, key string) (uint64, error)

SubSegToUint64 receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as a uint64 and a nil error. If any error is encountered, a zero value uint64 and error are returned.

func SubSegToUint8 added in v1.1.2

func SubSegToUint8(path, key string) (uint8, error)

SubSegToUint8 receives a key which is used to search for the first matching path segment, then returns both the subsequent segment as a uint8 and a nil error. If any error is encountered, a zero value uint8 and error are returned.

func SubSpanToString

func SubSpanToString(path, key string, lastSeg int) (string, error)

SubSpanToString receives a key which is used to search for the first matching path segment and an int value representing a second segment by it's distance from the matched segment, then returns the content between those segments as a string and a nil error. If any error is encountered, a zero value string and error are returned. The int representing a segment can be of negative values. Providing a 0 int is a special case which indicates the end of the path.

Types

type Parth added in v1.1.0

type Parth struct {
	// contains filtered or unexported fields
}

Parth holds path and error data for processing paths multiple times, and then checking for errors only once. Only the first encountered error will be returned.

func New added in v1.1.0

func New(path string) *Parth

New receives a path as a string, then returns a new Parth set with the provided path.

func NewFromSpan added in v1.1.0

func NewFromSpan(path string, firstSeg, lastSeg int) *Parth

NewFromSpan receives a path as a string, and two int values representing path segments, then returns a new Parth set with the content between those segments, and any error encountered. See SpanToString for more info.

func NewFromSubSpan added in v1.1.0

func NewFromSubSpan(path, key string, lastSeg int) *Parth

NewFromSubSpan receives a path as a string, a key which is used to search for the first matching path segment, and an int value representing a second segment by it's distance from the matched segment, then returns a new Parth set with the content between those segments, and any error encountered. See SubSpanToString for more info.

func (*Parth) Err added in v1.1.0

func (p *Parth) Err() error

Err returns the first error encountered by the Parth instance.

func (*Parth) SegmentToBool added in v1.1.0

func (p *Parth) SegmentToBool(i int) bool

SegmentToBool receives an int representing a path segment, then returns the specified segment as a bool. If any error is encountered, a zero value bool is returned, and the Parth instance's err value is set. If an error has already been set, a zero value bool is returned.

func (*Parth) SegmentToFloat32 added in v1.1.0

func (p *Parth) SegmentToFloat32(i int) float32

SegmentToFloat32 receives an int representing a path segment, then returns the specified segment as a float32. If any error is encountered, a zero value float32 is returned, and the Parth instance's err value is set. If an error has already been set, a zero value float32 is returned.

func (*Parth) SegmentToFloat64 added in v1.1.0

func (p *Parth) SegmentToFloat64(i int) float64

SegmentToFloat64 receives an int representing a path segment, then returns the specified segment as a float64. If any error is encountered, a zero value float64 is returned, and the Parth instance's err value is set. If an error has already been set, a zero value float64 is returned.

func (*Parth) SegmentToInt added in v1.1.0

func (p *Parth) SegmentToInt(i int) int

SegmentToInt receives an int representing a path segment, then returns the specified segment as an int. If any error is encountered, a zero value int is returned, and the Parth instance's err value is set. If an error has already been set, a zero value int is returned.

func (*Parth) SegmentToInt16 added in v1.1.0

func (p *Parth) SegmentToInt16(i int) int16

SegmentToInt16 receives an int representing a path segment, then returns the specified segment as an int16. If any error is encountered, a zero value int16 is returned, and the Parth instance's err value is set. If an error has already been set, a zero value int16 is returned.

func (*Parth) SegmentToInt32 added in v1.1.0

func (p *Parth) SegmentToInt32(i int) int32

SegmentToInt32 receives an int representing a path segment, then returns the specified segment as an int32. If any error is encountered, a zero value int32 is returned, and the Parth instance's err value is set. If an error has already been set, a zero value int32 is returned.

func (*Parth) SegmentToInt64 added in v1.1.0

func (p *Parth) SegmentToInt64(i int) int64

SegmentToInt64 receives an int representing a path segment, then returns the specified segment as an int64. If any error is encountered, a zero value int64 is returned, and the Parth instance's err value is set. If an error has already been set, a zero value int64 is returned.

func (*Parth) SegmentToInt8 added in v1.1.0

func (p *Parth) SegmentToInt8(i int) int8

SegmentToInt8 receives an int representing a path segment, then returns the specified segment as an int8. If any error is encountered, a zero value int8 is returned, and the Parth instance's err value is set. If an error has already been set, a zero value int8 is returned.

func (*Parth) SegmentToString added in v1.1.0

func (p *Parth) SegmentToString(i int) string

SegmentToString receives an int representing a path segment, then returns the specified segment as a string. If any error is encountered, a zero value string is returned, and the Parth instance's err value is set. If an error has already been set, a zero value string is returned.

func (*Parth) SegmentToUint added in v1.1.2

func (p *Parth) SegmentToUint(i int) uint

SegmentToUint receives an int representing a path segment, then returns the specified segment as a uint. If any error is encountered, a zero value uint is returned, and the Parth instance's err value is set. If an error has already been set, a zero value uint is returned.

func (*Parth) SegmentToUint16 added in v1.1.2

func (p *Parth) SegmentToUint16(i int) uint16

SegmentToUint16 receives an int representing a path segment, then returns the specified segment as a uint16. If any error is encountered, a zero value uint16 is returned, and the Parth instance's err value is set. If an error has already been set, a zero value uint16 is returned.

func (*Parth) SegmentToUint32 added in v1.1.2

func (p *Parth) SegmentToUint32(i int) uint32

SegmentToUint32 receives an int representing a path segment, then returns the specified segment as a uint32. If any error is encountered, a zero value uint32 is returned, and the Parth instance's err value is set. If an error has already been set, a zero value uint32 is returned.

func (*Parth) SegmentToUint64 added in v1.1.2

func (p *Parth) SegmentToUint64(i int) uint64

SegmentToUint64 receives an int representing a path segment, then returns the specified segment as a uint64. If any error is encountered, a zero value uint64 is returned, and the Parth instance's err value is set. If an error has already been set, a zero value uint64 is returned.

func (*Parth) SegmentToUint8 added in v1.1.2

func (p *Parth) SegmentToUint8(i int) uint8

SegmentToUint8 receives an int representing a path segment, then returns the specified segment as a uint8. If any error is encountered, a zero value uint8 is returned, and the Parth instance's err value is set. If an error has already been set, a zero value uint8 is returned.

func (*Parth) SpanToString added in v1.1.0

func (p *Parth) SpanToString(firstSeg, lastSeg int) string

SpanToString receives two int values representing path segments, then returns the content between those segments, including the first segment, as a string. If any error is encountered, a zero value string is returned, and the Parth instance's err value is set. If an error has already been set, a zero value string is returned. See SpanToString for more info.

func (*Parth) SubSegToBool added in v1.1.0

func (p *Parth) SubSegToBool(key string) bool

SubSegToBool receives a key which is used to search for the first matching path segment, then returns the subsequent segment as an bool. If any error is encountered, a zero value bool is returned, and the Parth instances err value is set. If an error has already been set, a zero value bool is returned.

func (*Parth) SubSegToFloat32 added in v1.1.0

func (p *Parth) SubSegToFloat32(key string) float32

SubSegToFloat32 receives a key which is used to search for the first matching path segment, then returns the subsequent segment as an float32. If any error is encountered, a zero value float32 is returned, and the Parth instance's err value is set. If an error has already been set, a zero value float32 is returned.

func (*Parth) SubSegToFloat64 added in v1.1.0

func (p *Parth) SubSegToFloat64(key string) float64

SubSegToFloat64 receives a key which is used to search for the first matching path segment, then returns the subsequent segment as an float64. If any error is encountered, a zero value float64 is returned, and the Parth instance's err value is set. If an error has already been set, a zero value float64 is returned.

func (*Parth) SubSegToInt added in v1.1.0

func (p *Parth) SubSegToInt(key string) int

SubSegToInt receives a key which is used to search for the first matching path segment, then returns the subsequent segment as an int. If any error is encountered, a zero value int8 is returned, and the Parth instances err value is set. If an error has already been set, a zero value int8 is returned.

func (*Parth) SubSegToInt16 added in v1.1.0

func (p *Parth) SubSegToInt16(key string) int16

SubSegToInt16 receives a key which is used to search for the first matching path segment, then returns the subsequent segment as an int16. If any error is encountered, a zero value int16 is returned, and the Parth instances err value is set. If an error has already been set, a zero value int16 is returned.

func (*Parth) SubSegToInt32 added in v1.1.0

func (p *Parth) SubSegToInt32(key string) int32

SubSegToInt32 receives a key which is used to search for the first matching path segment, then returns the subsequent segment as an int32. If any error is encountered, a zero value int32 is returned, and the Parth instances err value is set. If an error has already been set, a zero value int32 is returned.

func (*Parth) SubSegToInt64 added in v1.1.0

func (p *Parth) SubSegToInt64(key string) int64

SubSegToInt64 receives a key which is used to search for the first matching path segment, then returns the subsequent segment as an int64. If any error is encountered, a zero value int64 is returned, and the Parth instances err value is set. If an error has already been set, a zero value int64 is returned.

func (*Parth) SubSegToInt8 added in v1.1.0

func (p *Parth) SubSegToInt8(key string) int8

SubSegToInt8 receives a key which is used to search for the first matching path segment, then returns the subsequent segment as an int8. If any error is encountered, a zero value int8 is returned, and the Parth instances err value is set. If an error has already been set, a zero value int8 is returned.

func (*Parth) SubSegToString added in v1.1.0

func (p *Parth) SubSegToString(key string) string

SubSegToString receives a key which is used to search for the first matching path segment, then returns the subsequent segment as a string. If any error is encountered, a zero value string is returned, and the Parth instances err value is set. If an error has already been set, a zero value string is returned.

func (*Parth) SubSegToUint added in v1.1.2

func (p *Parth) SubSegToUint(key string) uint

SubSegToUint receives a key which is used to search for the first matching path segment, then returns the subsequent segment as a uint. If any error is encountered, a zero value uint is returned, and the Parth instances err value is set. If an error has already been set, a zero value uint is returned.

func (*Parth) SubSegToUint16 added in v1.1.2

func (p *Parth) SubSegToUint16(key string) uint16

SubSegToUint16 receives a key which is used to search for the first matching path segment, then returns the subsequent segment as a uint16. If any error is encountered, a zero value uint16 is returned, and the Parth instances err value is set. If an error has already been set, a zero value uint16 is returned.

func (*Parth) SubSegToUint32 added in v1.1.2

func (p *Parth) SubSegToUint32(key string) uint32

SubSegToUint32 receives a key which is used to search for the first matching path segment, then returns the subsequent segment as a uint32. If any error is encountered, a zero value uint32 is returned, and the Parth instances err value is set. If an error has already been set, a zero value uint32 is returned.

func (*Parth) SubSegToUint64 added in v1.1.2

func (p *Parth) SubSegToUint64(key string) uint64

SubSegToUint64 receives a key which is used to search for the first matching path segment, then returns the subsequent segment as a uint64. If any error is encountered, a zero value uint64 is returned, and the Parth instances err value is set. If an error has already been set, a zero value uint64 is returned.

func (*Parth) SubSegToUint8 added in v1.1.2

func (p *Parth) SubSegToUint8(key string) uint8

SubSegToUint8 receives a key which is used to search for the first matching path segment, then returns the subsequent segment as a uint8. If any error is encountered, a zero value uint8 is returned, and the Parth instances err value is set. If an error has already been set, a zero value uint8 is returned.

func (*Parth) SubSpanToString added in v1.1.0

func (p *Parth) SubSpanToString(key string, lastSeg int) string

SubSpanToString receives a key which is used to search for the first matching path segment, and an int value representing a second segment by it's distance from the matched segment, then returns the content between those segments as a string. If an error has already been set, a zero value string is returned. See SubSpanToString for more info.

Jump to

Keyboard shortcuts

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