Skip to content

Commit ceb6e76

Browse files
committed
update
1 parent 0dad941 commit ceb6e76

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

host.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Hoster interface {
1212
FormatMap(params H) string
1313
RegExp() *regexp.Regexp
1414
Match(host string) (r []string, hasExpr bool)
15+
HasParam(name string) bool
1516
}
1617

1718
type host struct {
@@ -20,12 +21,18 @@ type host struct {
2021
format string
2122
regExp *regexp.Regexp
2223
names []string
24+
namek map[string]struct{}
2325
}
2426

2527
func (h *host) Name() string {
2628
return h.name
2729
}
2830

31+
func (h *host) HasParam(name string) bool {
32+
_, ok := h.namek[name]
33+
return ok
34+
}
35+
2936
func (h *host) Alias() string {
3037
return h.alias
3138
}
@@ -69,7 +76,7 @@ func (h *host) Match(host string) (r []string, hasExpr bool) {
6976
}
7077

7178
func NewHost(name string) *host {
72-
return &host{name: name}
79+
return &host{name: name, namek: map[string]struct{}{}}
7380
}
7481

7582
var hostRegExp = regexp.MustCompile(`<([^:]+)(?:\:(.+?))?>`)
@@ -113,5 +120,8 @@ func ParseURIRegExp(uriRegexp string, dflRegexp string) (names []string, format
113120

114121
func (h *host) Parse() *host {
115122
h.names, h.format, h.regExp = ParseURIRegExp(h.name, ``)
123+
for _, name := range h.names {
124+
h.namek[name] = struct{}{}
125+
}
116126
return h
117127
}

0 commit comments

Comments
 (0)