pathexp

package
v0.0.0-...-ada05ea Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2013 License: Apache-2.0 Imports: 4 Imported by: 0

README

pathexp

pathexp is a library to match url path

Installation

go get github.com/sdming/pathexp

Usage

import "github.com/sdming/pathexp"

Example

pattern := "/query/hoho/{type}/{year}-{month}-{day}/"
input := "/query/hoho/type/year-month-day/"

re, err := pathexp.Compile(pattern)
if err != nil {
    fmt.Println("pattern compile fail: %s; pattern=%s \n", err, pattern)
    return
}

args := re.FindAllStringSubmatch(input)
for i, arg := range args {
    fmt.Println(i, arg[0], "=", arg[1])
}

For more example usage, please see pathexp_test.go

profiler

(pprof) top10         
Total: 206 samples
      82  39.8%  39.8%      187  90.8% github.com/sdming/pathexp.(*Pathex).execute
      19   9.2%  49.0%       92  44.7% runtime.mallocgc
      14   6.8%  55.8%       14   6.8% scanblock
      12   5.8%  61.7%       12   5.8% runtime.markallocated
      10   4.9%  66.5%       43  20.9% runtime.makeslice
      10   4.9%  71.4%       20   9.7% sweep
       8   3.9%  75.2%        8   3.9% MCentral_Alloc
       7   3.4%  78.6%       23  11.2% runtime.MCache_Alloc
       7   3.4%  82.0%       10   4.9% runtime.MCache_Free
       5   2.4%  84.5%        5   2.4% runtime.memmove

maybe can run more faster

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchString

func MatchString(pattern string, s string) (matched bool, error error)

MatchString returns whether the pattern matches the string s

Types

type Matcher

type Matcher interface {
	Match(expr string) (matched bool, submatch [][2]string)
}

type Pathex

type Pathex struct {
	Pattern  string
	SubNames []SubName
	// contains filtered or unexported fields
}

Pathex is a parttern to match url path

func Compile

func Compile(s string) (exp *Pathex, err error)

Compile parses a expression

func (*Pathex) Match

func (re *Pathex) Match(chars string) (matched bool, data [][2]string)

func (*Pathex) MatchString

func (re *Pathex) MatchString(expr string) bool

MatchString returns whether the Pathex matches the string expr

func (Pathex) String

func (re Pathex) String() string

string

type RegexpMatch

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

func RegexpCompile

func RegexpCompile(pattern string) (*RegexpMatch, error)

func (*RegexpMatch) Match

func (re *RegexpMatch) Match(expr string) (matched bool, submatch [][2]string)

type SubName

type SubName struct {
	Name string
	// contains filtered or unexported fields
}

subName

func (SubName) String

func (self SubName) String() string

string

Jump to

Keyboard shortcuts

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