Standard library / path
path.Match()
Matches the entire name against a shell-style pattern; star does not cross a slash. Malformed patterns return ErrBadPattern. Example uses a disposable temporary workspace. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func Match(pattern, name string) (matched bool, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| pattern | string | Shell-style matching pattern. |
| name | string | Name or pathname of the target. |
Return Value
(matched bool, err error)
Matches the entire name against a shell-style pattern; star does not cross a slash.
Working Example
Example Snippetgo
package main
import ( "fmt" "os" "path")
func check(e error) { if e != nil { panic(e) }}func workspace() func() { root, e := os.MkdirTemp("", "bytemind-go-") check(e) old, e := os.Getwd() check(e) check(os.Chdir(root)) return func() { check(os.Chdir(old)); check(os.RemoveAll(root)) }}func main() { defer workspace()(); m, e := path.Match("*.txt", "go.txt"); check(e); fmt.Println(m) }