@@ -219,6 +219,45 @@ func Load(path string) (*List, error) {
219
219
return list , nil
220
220
}
221
221
222
+ func isMatchAttr (Attrs []* router.Domain_Attribute , includeKey string ) bool {
223
+ isMatch := false
224
+ mustMatch := true
225
+ matchName := includeKey
226
+ if strings .HasPrefix (includeKey , "!" ) {
227
+ isMatch = true
228
+ mustMatch = false
229
+ matchName = strings .TrimLeft (includeKey , "!" )
230
+ }
231
+
232
+ for _ , Attr := range Attrs {
233
+ attrName := Attr .Key
234
+ if mustMatch {
235
+ if matchName == attrName {
236
+ isMatch = true
237
+ break
238
+ }
239
+ } else {
240
+ if matchName == attrName {
241
+ isMatch = false
242
+ break
243
+ }
244
+ }
245
+ }
246
+ return isMatch
247
+ }
248
+
249
+ func createIncludeAttrEntrys (list * List , matchAttr * router.Domain_Attribute ) []Entry {
250
+ newEntryList := make ([]Entry , 0 , len (list .Entry ))
251
+ matchName := matchAttr .Key
252
+ for _ , entry := range list .Entry {
253
+ matched := isMatchAttr (entry .Attrs , matchName )
254
+ if matched {
255
+ newEntryList = append (newEntryList , entry )
256
+ }
257
+ }
258
+ return newEntryList
259
+ }
260
+
222
261
func ParseList (list * List , ref map [string ]* List ) (* ParsedList , error ) {
223
262
pl := & ParsedList {
224
263
Name : list .Name ,
@@ -231,15 +270,35 @@ func ParseList(list *List, ref map[string]*List) (*ParsedList, error) {
231
270
for _ , entry := range entryList {
232
271
if entry .Type == "include" {
233
272
refName := strings .ToUpper (entry .Value )
234
- if pl .Inclusion [refName ] {
235
- continue
236
- }
237
- pl .Inclusion [refName ] = true
238
- r := ref [refName ]
239
- if r == nil {
240
- return nil , errors .New (entry .Value + " not found." )
273
+ if entry .Attrs != nil {
274
+ for _ , attr := range entry .Attrs {
275
+ InclusionName := strings .ToUpper (refName + "@" + attr .Key )
276
+ if pl .Inclusion [InclusionName ] {
277
+ continue
278
+ }
279
+ pl .Inclusion [InclusionName ] = true
280
+
281
+ refList := ref [refName ]
282
+ if refList == nil {
283
+ return nil , errors .New (entry .Value + " not found." )
284
+ }
285
+ attrEntrys := createIncludeAttrEntrys (refList , attr )
286
+ if len (attrEntrys ) != 0 {
287
+ newEntryList = append (newEntryList , attrEntrys ... )
288
+ }
289
+ }
290
+ } else {
291
+ InclusionName := refName
292
+ if pl .Inclusion [InclusionName ] {
293
+ continue
294
+ }
295
+ pl .Inclusion [InclusionName ] = true
296
+ refList := ref [refName ]
297
+ if refList == nil {
298
+ return nil , errors .New (entry .Value + " not found." )
299
+ }
300
+ newEntryList = append (newEntryList , refList .Entry ... )
241
301
}
242
- newEntryList = append (newEntryList , r .Entry ... )
243
302
hasInclude = true
244
303
} else {
245
304
newEntryList = append (newEntryList , entry )
0 commit comments