@@ -21,30 +21,51 @@ type Server struct {
2121 JSON model.Serverless
2222}
2323
24- func checkPath (event model.HttpEvent , reqPath string , method string ) bool {
24+ var strReg = "{[a-z0-9A-Z-]+}"
25+
26+ const varsKey int = iota
27+
28+ func checkPath (event model.HttpEvent , reqPath string , method string ) (bool , map [string ]string ) {
29+ parameters := map [string ]string {}
2530 emethod := strings .ToUpper (event .Method )
2631
2732 event .Path = strings .ReplaceAll ("/" + event .Path , "//" , "/" )
2833
2934 if emethod != method {
30- return false
35+ return false , parameters
3136 }
3237
3338 if event .Path == reqPath {
34- return true
39+ return true , parameters
3540 }
3641
37- match , _ := regexp .MatchString ("{[a-z0-9A-Z-]+}" , event .Path )
42+ match , _ := regexp .MatchString (strReg , event .Path )
3843 if match == true {
39- reg , _ := regexp .Compile ("{[a-z0-9A-Z-]+}" )
44+ reg , _ := regexp .Compile (strReg )
45+
4046 ep := reg .ReplaceAllString (event .Path , "[a-z0-9A-Z-]+" )
47+ p := strings .ReplaceAll (ep , "[a-z0-9A-Z-]+" , "" )
48+
4149 match , _ = regexp .MatchString (ep , reqPath )
4250 if match == true {
43- return true
51+ reg2 , _ := regexp .Compile ("[a-z0-9A-Z-]+" )
52+ params := reg .FindStringSubmatch (event .Path )
53+ m := strings .ReplaceAll (reqPath , p , "" )
54+ values := reg2 .FindStringSubmatch (m )
55+ var value string
56+
57+ for i , param := range params {
58+ value = values [i ]
59+ param = strings .ReplaceAll (param , "{" , "" )
60+ param = strings .ReplaceAll (param , "}" , "" )
61+ parameters [param ] = value
62+ }
63+
64+ return true , parameters
4465 }
4566 }
4667
47- return false
68+ return false , parameters
4869}
4970
5071func (se * Server ) ContentYaml () {
@@ -62,8 +83,9 @@ func (se *Server) StartConfig() {
6283 http .Handle ("/" , http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
6384 se .ContentYaml ()
6485 for _ , functions := range se .JSON .Functions {
65- if checkPath (functions .Events [0 ].HttpEvent , r .URL .RequestURI (), r .Method ) {
66- result , off := lambda .ExecuteDockerLambda (se .Volume , se .Network , functions .Handler , se .JSON .Provider ["runtime" ], r .Body )
86+ check , parameters := checkPath (functions .Events [0 ].HttpEvent , r .URL .RequestURI (), r .Method )
87+ if check {
88+ result , off := lambda .ExecuteDockerLambda (se .Volume , se .Network , functions .Handler , se .JSON .Provider ["runtime" ], r .Body , parameters )
6789 if result .StatusCode == 0 {
6890 w .WriteHeader (400 )
6991 fmt .Println (off )
0 commit comments