A library that provides pattern-matching for paths, for the Go programming language. For example, a path could be a file system path, or a path could be a path from a URL (such as an HTTP or HTTPS based URL).
Go to file
Charles Iliya Krempeaux 59a54f4c9e example 2019-06-20 17:29:47 -07:00
LICENSE initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
README.md docs 2019-06-20 17:11:35 -07:00
bad_request_complainer.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
compile.go corrected minor typo in docs. 2016-11-08 13:25:33 -08:00
compile_test.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
doc.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
example_compile_test.go example 2019-06-20 17:29:47 -07:00
internal_error_complainer.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
not_enough_arguments_complainer.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
pattern.go added pathmatch.Pattern.Glob() 2016-02-25 17:18:58 -08:00
pattern_glob_test.go added pathmatch.Pattern.Glob() 2016-02-25 17:18:58 -08:00
pattern_load.go correction, for newer version of compiler 2019-06-20 17:10:46 -07:00
pattern_load_test.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
pattern_match.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
pattern_match_test.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
pattern_syntax_error_complainer.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
scan_error_complainer.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
set.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
set_test.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
struct_field_wrong_type_complainer.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00
unsupported_argument_type_complainer.go initial commit. still need to create more tests. 2016-02-25 14:59:38 -08:00

README.md

go-pathmatch

A library that provides pattern matching for paths, for the Go programming language.

For example, a path could be a file system path, or a path could be a path from a URL (such as an HTTP or HTTPS based URL).

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-pathmatch

GoDoc

Example Usage

import (
	"github.com/reiver/go-pathmatch"
)

// ...

pattern, err := pathmatch.Compile("/users/{user_id}/vehicles/{vehicle_id}}")
if nil != err {
    //@TODO
}

var userId    string
var vehicleId string

didMatch, err := pattern.Match("/users/bMM_kJFMEV/vehicles/o_bcU.RZGK", &userId, &vehicleId)

if nil != err {
    //@TODO
}

if didMatch {
    fmt.Println("The path matched!")

    fmt.Printf("user_id     = %q \n", userId)     // user_id     = "bMM_kJFMEV"
    fmt.Printf("vehicle_id  = %q \n", vehicleId)  // vehicle_id  = "o_bcU.RZGK"
} else {
    fmt.Println("The patch did not match.")
}

Alternatively:

import (
	"github.com/reiver/go-pathmatch"
)

// ...

pattern, err := pathmatch.Compile("/users/{user_id}/vehicles/{vehicle_id}}")
if nil != err {
    //@TODO
}

data := struct{
	UserId    string `match:"user_id"`
	VehicleId string `match:"vehicle_id"`
}{}

didMatch, err := pattern.MatchAndLoad("/users/bMM_kJFMEV/vehicles/o_bcU.RZGK", &data)

if nil != err {
    //@TODO
}

if didMatch {
    fmt.Println("The path matched!")

    fmt.Printf("user_id     = %q \n", data.UserId)     // user_id     = "bMM_kJFMEV"
    fmt.Printf("vehicle_id  = %q \n", data.VehicleId)  // vehicle_id  = "o_bcU.RZGK"
} else {
    fmt.Println("The patch did not match.")
}