Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8a940bd

Browse files
committedJul 3, 2020
Remove unnecessary export. Clarify comments.
Closes grafana#972
1 parent 9b59100 commit 8a940bd

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed
 

‎lib/options.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,14 @@ type HostnameTrie struct {
198198
terminal bool // end of a valid match
199199
}
200200

201-
// describes a valid hostname pattern to block by. Global var to avoid
202-
// compilation penalty each call to ValidHostname.
203-
var validHostnamePattern *regexp.Regexp = regexp.MustCompile("^\\*?(\\pL|[0-9\\.])*")
204-
205-
// ValidHostname returns whether the provided hostname pattern
206-
// has an optional wildcard at the start, and is composed entirely
207-
// of letters, numbers, or '.'s.
208-
func ValidHostname(s string) error {
209-
if len(validHostnamePattern.FindString(s)) != len(s) {
201+
// Regex description of hostname pattern to enforce blocks by. Global var
202+
// to avoid compilation penalty at runtime.
203+
// Matches against strings composed entirely of letters, numbers, or '.'s
204+
// with an optional wildcard at the start.
205+
var legalHostnamePattern *regexp.Regexp = regexp.MustCompile("^\\*?(\\pL|[0-9\\.])*")
206+
207+
func legalHostname(s string) error {
208+
if len(legalHostnamePattern.FindString(s)) != len(s) {
210209
return fmt.Errorf("invalid hostname pattern %s", s)
211210
}
212211
return nil
@@ -238,13 +237,14 @@ func (t *HostnameTrie) UnmarshalText(b []byte) error {
238237
return nil
239238
}
240239

241-
// Insert a string into the given HostnameTrie.
240+
// Insert a hostname pattern into the given HostnameTrie. Returns an error
241+
// if hostname pattern is illegal.
242242
func (t *HostnameTrie) Insert(s string) error {
243243
if len(s) == 0 {
244244
return nil
245245
}
246246

247-
if err := ValidHostname(s); err != nil {
247+
if err := legalHostname(s); err != nil {
248248
return err
249249
}
250250

@@ -272,6 +272,7 @@ func (t *HostnameTrie) Contains(s string) (bool, string) {
272272
return false, ""
273273
}
274274

275+
// recursively traverse HostnameTrie children searching for a match.
275276
func (t *HostnameTrie) childContains(s string, match string) (bool, string) {
276277
if len(s) == 0 {
277278
return false, ""

0 commit comments

Comments
 (0)
Please sign in to comment.