forked from gominima/minima
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmux.go
More file actions
38 lines (33 loc) · 808 Bytes
/
Copy pathmux.go
File metadata and controls
38 lines (33 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package minima
import (
"regexp"
)
/**
@info The mux structure
@property {string} [Path] The path to match
@property {[]string} [Params] The params to use
@property {regexp.Regexp} [Regex] The regex to use
@property {[]Handler} [Handlers] The handlers to use
*/
type mux struct {
Path string
Params []string
Regex *regexp.Regexp
Handlers []Handler
}
/**
@info Match a path
@param {string} [path] The path to match
@returns {bool, map[]string[]string}
*/
func (m *mux) matchingPath(path string) (bool, map[string]string) {
routeParams := make(map[string]string)
matchingRegex := m.Regex.FindAllStringSubmatch(path, -1)
isMatch := len(matchingRegex) != 0
if isMatch {
for i, param := range m.Params {
routeParams[param] = matchingRegex[0][i+1]
}
}
return isMatch, routeParams
}