@@ -7,11 +7,13 @@ import (
77 "strings"
88
99 "github.com/adityals/go-ngx-config/internal/ast"
10+ "github.com/adityals/go-ngx-config/internal/statement"
1011)
1112
1213type LocationMatcher struct {
1314 MatchPath string
1415 MatchModifer string
16+ Directives []statement.IDirective
1517}
1618
1719const (
@@ -50,7 +52,8 @@ func NewLocationMatcher(conf *ast.Config, targetPath string) (*LocationMatcher,
5052 Name : name ,
5153 Modifier : modifier ,
5254 Match : match ,
53- Directives : directives })
55+ Directives : directives ,
56+ })
5457 }
5558
5659 match , err := locationTester (locations , parsedUrl .Path )
@@ -65,7 +68,9 @@ func NewLocationMatcher(conf *ast.Config, targetPath string) (*LocationMatcher,
6568
6669 return & LocationMatcher {
6770 MatchModifer : match .MatchModifer ,
68- MatchPath : match .MatchPath }, nil
71+ MatchPath : match .MatchPath ,
72+ Directives : match .Directives ,
73+ }, nil
6974}
7075
7176func locationTester (locationsTarget []ast.Location , targetPath string ) (* LocationMatcher , error ) {
@@ -75,7 +80,11 @@ func locationTester(locationsTarget []ast.Location, targetPath string) (*Locatio
7580 }
7681
7782 if location .Match == targetPath {
78- return & LocationMatcher {MatchPath : location .Match , MatchModifer : location .Modifier }, nil
83+ return & LocationMatcher {
84+ MatchPath : location .Match ,
85+ MatchModifer : location .Modifier ,
86+ Directives : location .Directives ,
87+ }, nil
7988 }
8089 }
8190
@@ -110,13 +119,21 @@ func locationTester(locationsTarget []ast.Location, targetPath string) (*Locatio
110119
111120 match := reg .FindString (targetPath )
112121 if match != "" {
113- return & LocationMatcher {MatchPath : location .Match , MatchModifer : location .Modifier }, nil
122+ return & LocationMatcher {
123+ MatchPath : location .Match ,
124+ MatchModifer : location .Modifier ,
125+ Directives : location .Directives ,
126+ }, nil
114127 }
115128 }
116129 }
117130
118131 if bestMatch != nil {
119- return & LocationMatcher {MatchPath : bestMatch .Match , MatchModifer : bestMatch .Modifier }, nil
132+ return & LocationMatcher {
133+ MatchPath : bestMatch .Match ,
134+ MatchModifer : bestMatch .Modifier ,
135+ Directives : bestMatch .Directives ,
136+ }, nil
120137 }
121138
122139 return nil , nil
0 commit comments