glob

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 7 Imported by: 1

README

glob

Go Reference

Glob utilities built on top of the well-tested gobwas/glob.

Features

  • Supports wildcard globs like **
  • Faster matching and walking by pulling out the non-wildcard parts of a glob (e.g. /posts/ in /posts/**)
  • Supports globs like {posts/**,tags/**} by pre-expanding globs.

Install

go get github.com/matthewmueller/glob

Example

package main

import (
	"github.com/matthewmueller/glob"
)

func main() {
	files, _ := glob.Match("[A-Z]*.md")
	for _, file := range files {
		fmt.Println(file)
	}
	// Output:
	// Changelog.md
	// License.md
	// Readme.md
}

Contributors

License

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(glob string) (matches []string, err error)

Match is conceptually similar to filepath.Glob, but it uses the glob package from github.com/gobwas/glob, which supports more advanced globbing patterns.

Example
package main

import (
	"fmt"

	"github.com/matthewmueller/glob"
)

func main() {
	files, err := glob.Match("[A-Z]*.md")
	if err != nil {
		fmt.Println(err)
	}

	for _, file := range files {
		fmt.Println(file)
	}

}
Output:

Changelog.md
License.md
Readme.md

func MatchFS added in v0.0.2

func MatchFS(fsys fs.FS, glob string) (matches []string, err error)

MatchFS matches a pattern against an abstract filesystem

func Walk

func Walk(pattern string, fn fs.WalkDirFunc) error

Walk the files

func WalkFS added in v0.0.2

func WalkFS(fsys fs.FS, pattern string, fn fs.WalkDirFunc) error

WalkFS walks an abstract abstract filesystem, matching on the pattern

Types

type Matcher

type Matcher = glob.Glob

func Compile

func Compile(pattern string) (Matcher, error)

Comple a glob pattern into a matcher

Jump to

Keyboard shortcuts

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