MCPcopy Index your code
hub / github.com/IGLOU-EU/go-wildcard

github.com/IGLOU-EU/go-wildcard @v2.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.1.1 ↗ · + Follow
23 symbols 40 edges 7 files 8 documented · 35% 5 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Go-wildcard

Go Report Card Go Reference BSD 3 Clause

💡 Why

The purpose of this library is to provide a simple and fast wildcard pattern matching. Regex are much more complex and slower (even prepared regex)... and the filepath.Match is file-name-centric.

So, this library is a very fast and very simple alternative to regex and not tied to filename semantics unlike filepath.Match. There are no dependencies and is allocation-free. 🥳

🧰 Features

These are the supported pattern operators: - * match zero or more characters - ? match zero or one character - . match exactly one character

🧐 How to

⚠️ WARNING: Unlike the GNU "libc", this library have no equivalent to "FNM_FILE_NAME". To do this you can use "path/filepath" https://pkg.go.dev/path/filepath#Match

It is very simple to use this library: import it and call the Match function — or one of its variants, as shown below.

package main

import (
    "fmt"

    "github.com/IGLOU-EU/go-wildcard/v2"
)

func main() {
    str := "daaadabadmanda"
    pattern := "?a*da*d.?*"

    resultM := wildcard.Match(pattern, str) // Fastest, compares byte by byte
    resultMFB := wildcard.MatchFromByte([]byte(pattern), []byte(str)) // Like Match, for byte slices. Skips the string conversion
    resultMBR := wildcard.MatchByRune(pattern, str) // Compares rune by rune. Slower and the []rune conversion allocates

    fmt.Println(str, pattern, resultM, resultMFB, resultMBR)
}

🛸 Benchmark

The benchmark is done with the following command:

go test -benchmem -bench . github.com/IGLOU-EU/go-wildcard/v2/benchmark
goos: linux
goarch: amd64
pkg: github.com/IGLOU-EU/go-wildcard/v2
cpu: AMD Ryzen 7 PRO 6850U with Radeon Graphics  

The tested functions are: - regexp.MatchString - regexp.MatchPreparedString - filepath.Match - oldMatchSimple From the commit a899be92514ed08aa5271bc3b93320b719ce2114 - oldMatch From the commit a899be92514ed08aa5271bc3b93320b719ce2114 - Match From string with byte comparison - MatchByRune From string with rune comparison - MatchFromByte From byte slice with byte comparison

Rank Benchmark Average ns/op Samples
1 BenchmarkMatch 10.83 6
2 BenchmarkMatchFromByte 12.14 6
3 BenchmarkMatchByRune 60.78 6
4 BenchmarkRegexPrepared 86.48 4
5 BenchmarkFilepath 87.90 6
6 BenchmarkOldMatch 97.04 6
7 BenchmarkOldMatchSimple 98.24 6
8 BenchmarkRegex 2261.77 6

time bench allocs bench

🕰 History

Originally, this library was a fork from the Minio project. The purpose was to give access to this "lib" under Apache license, without importing the entire Minio project. And to keep it usable under the Apache License Version 2.0 after MinIO project is migrated to GNU Affero General Public License 3.0 or later from update license change for MinIO

The actual Minio wildcard matching code can be found in wildcard.go

Core symbols most depended-on inside this repo

Shape

Function 21
TypeAlias 2

Languages

Go100%

Modules by API surface

benchmark/wildcard_bench_test.go8 symbols
wildcard_match.go3 symbols
wildcard.go3 symbols
source/wildcard_match.go3 symbols
benchmark/old_wildcard_test.go3 symbols
source/wildcard_match_test.go2 symbols
wildcard_test.go1 symbols

For agents

$ claude mcp add go-wildcard \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page