/
Service.FetchEndpointHandler.go
56 lines (48 loc) · 1.84 KB
/
Service.FetchEndpointHandler.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package stonelizard
import (
"fmt"
"strings"
"net/http"
)
func (svc *Service) FetchEndpointHandler(proto, method, path string) (*UrlNode, []interface{}, map[string]interface{}, int) {
var i, j int
var pathId string
var match []string
var parms []interface{}
var authparms map[string]interface{}
var endpoint UrlNode
pathId = fmt.Sprintf("%s+%s:%s", strings.Split(proto,"/")[0], method, path)
Goose.Serve.Logf(6,"Matcher will look on %#v", svc.Matcher)
Goose.Serve.Logf(6,"Matcher will look for [%s]", pathId)
match = svc.Matcher.FindStringSubmatch(pathId)
Goose.Serve.Logf(6,"Matcher found this %#v\n", match) //6
if len(match) == 0 {
Goose.Serve.Logf(1,"Invalid service handler : %s", pathId)
return nil, nil, nil, http.StatusBadRequest
}
parms = []interface{}{}
authparms = map[string]interface{}{}
// for _, endpoint = range svc.Svc {
for i=1; i<len(match); i++ {
Goose.Serve.Logf(6,"trying %s with endpoint: %s",pathId,svc.Svc[svc.MatchedOps[i-1]].Path)
if len(match[i]) > 0 {
Goose.Serve.Logf(6,"Found endpoint %s for: %s",svc.Svc[svc.MatchedOps[i-1]].Path,pathId)//4
Goose.Serve.Logf(6,"Endpoint %#v",svc.Svc[svc.MatchedOps[i-1]])//7
Goose.Serve.Logf(5,"method: %s",method)
endpoint = svc.Svc[svc.MatchedOps[i-1]]
if method == "OPTIONS" {
break
}
for j=i+1; (j<len(match)) && (len(match[j])>0); j++ {
Goose.Serve.Logf(7,"j=%d, i=%d, endpoint.ParmNames: %#v, authparms: %#v", j, i, endpoint.ParmNames, authparms)
authparms[endpoint.ParmNames[j-i-1]] = match[j]
}
for k := i+1; k<j; k++ { // parms = []interface{}(match[i+1:j])
parms = append(parms,match[k])
}
j -= i + 1
break
}
}
return &endpoint, parms, authparms, 0
}