code.gitea.io/gitea@v1.22.3/modules/setting/glob.go (about)

     1  // Copyright 2024 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package setting
     5  
     6  import "github.com/gobwas/glob"
     7  
     8  type GlobMatcher struct {
     9  	compiledGlob  glob.Glob
    10  	patternString string
    11  }
    12  
    13  var _ glob.Glob = (*GlobMatcher)(nil)
    14  
    15  func (g *GlobMatcher) Match(s string) bool {
    16  	return g.compiledGlob.Match(s)
    17  }
    18  
    19  func (g *GlobMatcher) PatternString() string {
    20  	return g.patternString
    21  }
    22  
    23  func GlobMatcherCompile(pattern string, separators ...rune) (*GlobMatcher, error) {
    24  	g, err := glob.Compile(pattern, separators...)
    25  	if err != nil {
    26  		return nil, err
    27  	}
    28  	return &GlobMatcher{
    29  		compiledGlob:  g,
    30  		patternString: pattern,
    31  	}, nil
    32  }