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 3fd2741cba changelog.ca -> reiver.link 2024-08-01 17:37:41 -07:00
LICENSE changelog.ca -> reiver.link 2024-08-01 17:37:41 -07:00
README.md github.com/reiver/go-pathmatch -> sourcecode.social/reiver/go-pathmatch 2023-10-01 13:49:20 +09:00
bad_request.go renamed patternmatch.Pattern.MatchAndLoad() to patternmatch.Pattern.FindAndLoad() 2019-06-20 21:57:03 -07:00
compile.go pathmatch.Pattern.String() 2019-06-24 14:06:00 -07:00
compile_test.go refactoring pathmatch.Compile() 2019-06-21 13:16:25 -07:00
doc.go docs 2019-06-24 14:33:23 -07:00
errors.go mutex 2019-06-21 13:37:53 -07:00
example_compile_test.go github.com/reiver/go-pathmatch -> sourcecode.social/reiver/go-pathmatch 2023-10-01 13:49:20 +09:00
example_pattern_string_test.go github.com/reiver/go-pathmatch -> sourcecode.social/reiver/go-pathmatch 2023-10-01 13:49:20 +09:00
go.mod github.com/reiver/go-pathmatch -> sourcecode.social/reiver/go-pathmatch 2023-10-01 13:49:20 +09:00
go.sum github.com/reiver/go-pathmatch -> sourcecode.social/reiver/go-pathmatch 2023-10-01 13:49:20 +09:00
internal_error.go renamed "InternalErrorComplainer" to "InternalError" 2019-06-20 21:35:52 -07:00
not_enough_arguments.go renamed "NotEnoughArgumentsComplainer" to "NotEnoughArgumentsComplainerNotEnoughArguments" 2019-06-20 21:38:36 -07:00
pattern.go pathmatch.Pattern.String() 2019-06-24 14:05:08 -07:00
pattern_find.go made is so things such as "/v1/users/" does not match "/v1/users/{user_id}" 2019-06-24 15:04:02 -07:00
pattern_find_test.go github.com/reiver/go-pathmatch -> sourcecode.social/reiver/go-pathmatch 2023-10-01 13:49:20 +09:00
pattern_glob.go mutex 2019-06-21 13:37:53 -07:00
pattern_glob_test.go refactoring pathmatch.Compile() 2019-06-21 13:16:25 -07:00
pattern_init.go mutex 2019-06-21 13:37:53 -07:00
pattern_load.go made it so .FindAndLoad() can load to a *[]string too. 2019-07-11 08:42:02 -07:00
pattern_load_test.go made it so .FindAndLoad() can load to a *[]string too. 2019-07-11 08:42:02 -07:00
pattern_match.go pathmatch.Pattern.Match() 2019-06-21 15:26:35 -07:00
pattern_match_test.go github.com/reiver/go-pathmatch -> sourcecode.social/reiver/go-pathmatch 2023-10-01 13:49:20 +09:00
pattern_string.go pathmatch.Pattern.String() 2019-06-24 14:05:08 -07:00
pattern_syntax_error.go renamed "PatternSyntaxErrorComplainer" to "PatternSyntaxError" 2019-06-20 21:40:30 -07:00
scan_error.go renamed "InternalErrorComplainer" to "InternalError" 2019-06-20 21:35:33 -07:00
set.go cosmetic 2019-06-21 14:26:16 -07:00
set_test.go renamed "NotEnoughArgumentsComplainer" to "NotEnoughArgumentsComplainerNotEnoughArguments" 2019-06-20 21:38:18 -07:00
struct_field_wrong_type.go renamed "BadRequestComplainer" to "BadRequest" 2019-06-20 21:31:53 -07:00
unsupported_argument_type.go renamed "BadRequestComplainer" to "BadRequest" 2019-06-20 21:31:53 -07: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/sourcecode.social/reiver/go-pathmatch

GoDoc

Example Usage

import (
	"sourcecode.social/reiver/go-pathmatch"
)

// ...

var pattern pathmatch.Pattern

err := pathmatch.CompileTo(&pattern, "/users/{user_id}/vehicles/{vehicle_id}")
if nil != err {
	fmt.Fprintf(os.Stdout, "ERROR: %s\n", err)
	return
}

var userId    string
var vehicleId string

matched, err := pattern.Find("/users/bMM_kJFMEV/vehicles/o_bcU.RZGK", &userId, &vehicleId)
if nil != err {
	fmt.Fprintf(os.Stdout, "ERROR: %s\n", err)
	return
}

if !matched {
	fmt.Println("The patch did not match.")
	return
}

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"

Alternatively:

import (
	"sourcecode.social/reiver/go-pathmatch"
)

// ...

var pattern patchmatch.Pattern

err := pathmatch.CompileTo(&pattern, "/users/{user_id}/vehicles/{vehicle_id}")
if nil != err {
	fmt.Fprintf(os.Stdout, "ERROR: %s\n", err)
	return
}

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

matched, err := pattern.FindAndLoad("/users/bMM_kJFMEV/vehicles/o_bcU.RZGK", &data)
if nil != err {
	fmt.Fprintf(os.Stdout, "ERROR: %s\n", err)
	return
}

if !matched {
	fmt.Println("The patch did not match.")
	return
}


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"