mirror of
https://github.com/nadoo/glider.git
synced 2025-04-22 04:02:07 +08:00
30 lines
499 B
Go
30 lines
499 B
Go
package matcher
|
|
|
|
import (
|
|
"github.com/nadoo/glider/log"
|
|
"strconv"
|
|
)
|
|
|
|
type IntegerMatcher map[int]struct{}
|
|
|
|
func NewIntegerMatcher(ports []string) *IntegerMatcher {
|
|
m := make(map[int]struct{})
|
|
for _, port := range ports {
|
|
p, err := strconv.Atoi(port)
|
|
if err != nil {
|
|
log.F("invalid port: ", port)
|
|
continue
|
|
}
|
|
m[p] = struct{}{}
|
|
}
|
|
if len(m) == 0 {
|
|
return nil
|
|
}
|
|
return (*IntegerMatcher)(&m)
|
|
}
|
|
|
|
func (m IntegerMatcher) Match(t interface{}) bool {
|
|
_, ok := m[t.(int)]
|
|
return ok
|
|
}
|