hub.fastgit.org/hashicorp/consul.git@v1.4.5/agent/blacklist.go (about) 1 package agent 2 3 import ( 4 "github.com/armon/go-radix" 5 ) 6 7 // Blacklist implements an HTTP endpoint blacklist based on a list of endpoint 8 // prefixes which should be blocked. 9 type Blacklist struct { 10 tree *radix.Tree 11 } 12 13 // NewBlacklist returns a blacklist for the given list of prefixes. 14 func NewBlacklist(prefixes []string) *Blacklist { 15 tree := radix.New() 16 for _, prefix := range prefixes { 17 tree.Insert(prefix, nil) 18 } 19 return &Blacklist{tree} 20 } 21 22 // Block will return true if the given path is included among any of the 23 // blocked prefixes. 24 func (b *Blacklist) Block(path string) bool { 25 _, _, blocked := b.tree.LongestPrefix(path) 26 return blocked 27 }