Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Allowed ¶
type Allowed []AllowedModule
Allowed is a list of modules that are allowed to be used.
type AllowedModule ¶ added in v2.1.0
type AllowedModule struct {
Module string `yaml:"module"`
MatchType MatchType `yaml:"match-type"`
Version *semver.Constraints `yaml:"version"`
Matcher Matcher `yaml:"-"`
}
AllowedModule is a single entry in the allowed list.
func (*AllowedModule) CheckVersion ¶ added in v2.1.0
func (r *AllowedModule) CheckVersion(moduleVersion string) (bool, error)
CheckVersion returns true if the module version matches the allowed constraint, or if no version constraint is specified.
func (*AllowedModule) NotAllowedReason ¶ added in v2.1.0
func (r *AllowedModule) NotAllowedReason(moduleVersion string) string
NotAllowedReason returns the reason why the module version is not allowed.
type Blocked ¶
type Blocked []BlockedModule
Blocked is a list of modules that are blocked and not to be used.
type BlockedModule ¶ added in v2.1.0
type BlockedModule struct {
Module string `yaml:"module"`
MatchType MatchType `yaml:"match-type"`
Recommendations []string `yaml:"recommendations"`
Reason string `yaml:"reason"`
Version *semver.Constraints `yaml:"version"`
Matcher Matcher `yaml:"-"`
}
BlockedModule is a single entry in the blocked list.
func (*BlockedModule) BlockReason ¶ added in v2.1.0
func (r *BlockedModule) BlockReason(currentModuleVersion string) string
BlockReason returns the reason why the module or version is blocked.
func (*BlockedModule) CheckVersion ¶ added in v2.1.0
func (r *BlockedModule) CheckVersion(moduleVersion string) (bool, error)
CheckVersion returns true if the module version matches the blocked constraint. If no version constraint is specified, all versions are considered blocked.
func (*BlockedModule) HasRecommendations ¶ added in v2.1.0
func (r *BlockedModule) HasRecommendations() bool
HasRecommendations returns true if the blocked package has recommended modules.
func (*BlockedModule) IsCurrentModuleARecommendation ¶ added in v2.1.0
func (r *BlockedModule) IsCurrentModuleARecommendation(currentModuleName string) bool
IsCurrentModuleARecommendation returns true if the current module is in the Recommendations list.
type Configuration ¶
type Configuration struct {
Allowed Allowed `yaml:"allowed"`
Blocked Blocked `yaml:"blocked"`
LocalReplaceDirectives bool `yaml:"local_replace_directives"`
}
Configuration of gomodguard allow and block lists.
func (*Configuration) InitMatchers ¶
func (c *Configuration) InitMatchers() error
InitMatchers initializes matchers for the configuration rules.
type ExactMatcher ¶
type ExactMatcher struct {
Target string
}
ExactMatcher matches a module name exactly.
func (ExactMatcher) Match ¶
func (m ExactMatcher) Match(moduleName string) bool
type MatchType ¶
type MatchType string
MatchType represents the type of matching to be performed for a module name.
type PrefixMatcher ¶
type PrefixMatcher struct {
Prefix string
}
PrefixMatcher matches a module name by prefix.
func (PrefixMatcher) Match ¶
func (m PrefixMatcher) Match(moduleName string) bool
Match returns true if the moduleName starts with the Prefix, ignoring leading/trailing whitespace and case.
type Processor ¶
type Processor struct {
Config *Configuration
Modfile *modfile.File
// contains filtered or unexported fields
}
Processor processes Go files.
func NewProcessor ¶
func NewProcessor(config *Configuration) (*Processor, error)
NewProcessor will create a Processor to lint blocked packages.
func (*Processor) ProcessFiles ¶
ProcessFiles takes a string slice with file names (full paths) and lints them.
func (*Processor) SetBlockedModules ¶
func (p *Processor) SetBlockedModules()
SetBlockedModules determines and sets which modules are blocked by reading the go.mod file of the current module.
It works by iterating over the required modules specified in the require directive, checking if the module prefix or full name is in the allowed list.
Rules are evaluated using a layered strategy for deterministic results:
- Exact match — O(1) lookup; wins immediately.
- Prefix match — longest matching prefix wins.
- Regex match — evaluated in alphabetical key order; first match wins.
type RegexMatcher ¶
RegexMatcher matches a module name by regex.
func (RegexMatcher) Match ¶
func (m RegexMatcher) Match(moduleName string) bool