wildcard

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: Apache-2.0 Imports: 0 Imported by: 0

README

Go-wildcard

Go Report Card Go Reference Go coverage Apache V2 License

Go-wildcard is forked from Minio project
https://github.com/minio/minio/tree/master/pkg/wildcard

Why

This part of Minio project is a very cool, fast and light wildcard pattern matching.
But using it, need to import the full Minio project inside your own ... And this is a cool, but BIG project.

Two function are available MatchSimple and Match

  • MatchSimple only covert * usage (he is a bit faster)
  • Match support full wildcard matching, * and ?

I know Regex, but this is a big part, and it is slow (even prepared regex) ...
I know Glob, but most of the time, I only need simple wildcard matching.

How to

For using GitHub repo

go mod edit -replace git.iglou.eu/Imported/go-wildcard=github.com/IGLOU-EU/go-wildcard@latest
go get git.iglou.eu/Imported/go-wildcard@latest

From selfhosted (I can't warranty the availability)

go get git.iglou.eu/Imported/go-wildcard@latest

Quick Example

This example shows a Go file which pattern matching ...
You can use the Github repos to github.com/IGLOU-EU/go-wildcard

package main

import (
	"fmt"
	"log"

	wildcard "git.iglou.eu/Imported/go-wildcard"
)

func main() {
    str := "daaadabadmanda"
    
    pattern := "da*da*da*"
    result := wildcard.MatchSimple(pattern, str)
	fmt.Println(str, pattern, result)

    pattern = "?a*da*d?*"
    result = wildcard.Match(pattern, str)
	fmt.Println(str, pattern, result)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(pattern, name string) (matched bool)

Match - finds whether the text matches/satisfies the pattern string. supports '*' and '?' wildcards in the pattern string. unlike path.Match(), considers a path as a flat name space while matching the pattern. The difference is illustrated in the example here https://play.golang.org/p/Ega9qgD4Qz .

func MatchSimple

func MatchSimple(pattern, name string) bool

MatchSimple - finds whether the text matches/satisfies the pattern string. supports only '*' wildcard in the pattern. considers a file system path as a flat name space.

Types

This section is empty.

Jump to

Keyboard shortcuts

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