diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2023-02-19 09:27:55 +0000 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-02-19 09:27:55 +0000 |
commit | 3bd45dc49a35b82dcc4ae93796c3e152d799bc0b (patch) | |
tree | 3a681ac5dbd777d2b6b116429cfbd934815661ce /main/pathfilter.go | |
parent | a5a4db8283fda88c5bd42272de0258e5d134c5bd (diff) | |
download | stred-go-3bd45dc49a35b82dcc4ae93796c3e152d799bc0b.tar |
Move JSON serialising, deserialising and walking code into a separate package
Diffstat (limited to 'main/pathfilter.go')
-rw-r--r-- | main/pathfilter.go | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/main/pathfilter.go b/main/pathfilter.go index 7e21efe..1af3b6d 100644 --- a/main/pathfilter.go +++ b/main/pathfilter.go @@ -1,9 +1,13 @@ package main +import ( + "main/walk" +) + type AnySegmentPathFilter struct { next PathFilterState } -func (filter AnySegmentPathFilter) eat(segment PathSegment) map[PathFilterState]struct{} { +func (filter AnySegmentPathFilter) eat(segment walk.PathSegment) map[PathFilterState]struct{} { res := make(map[PathFilterState]struct{}) res[filter.next] = struct{}{} return res @@ -15,7 +19,7 @@ func (filter AnySegmentPathFilter) accept() bool { type OrPathFilter struct { filters [2]PathFilterState } -func (filter OrPathFilter) eat(segment PathSegment) map[PathFilterState]struct{} { +func (filter OrPathFilter) eat(segment walk.PathSegment) map[PathFilterState]struct{} { res := make(map[PathFilterState]struct{}) for _, f := range filter.filters { for r := range f.eat(segment) { @@ -34,7 +38,7 @@ func (filter OrPathFilter) accept() bool { } type NonePathFilter struct {} -func (filter NonePathFilter) eat(segment PathSegment) map[PathFilterState]struct{} { +func (filter NonePathFilter) eat(segment walk.PathSegment) map[PathFilterState]struct{} { return make(map[PathFilterState]struct{}) } func (filter NonePathFilter) accept() bool { @@ -45,7 +49,7 @@ type StringSegmentPathFilter struct { index string next PathFilterState } -func (filter StringSegmentPathFilter) eat(segment PathSegment) map[PathFilterState]struct{} { +func (filter StringSegmentPathFilter) eat(segment walk.PathSegment) map[PathFilterState]struct{} { s, isString := segment.(string) res := make(map[PathFilterState]struct{}) if isString && s == filter.index { @@ -61,7 +65,7 @@ type IntegerSegmentPathFilter struct { index int next PathFilterState } -func (filter IntegerSegmentPathFilter) eat(segment PathSegment) map[PathFilterState]struct{} { +func (filter IntegerSegmentPathFilter) eat(segment walk.PathSegment) map[PathFilterState]struct{} { i, isInteger := segment.(int) res := make(map[PathFilterState]struct{}) if isInteger && i == filter.index { @@ -74,6 +78,6 @@ func (filter IntegerSegmentPathFilter) accept() bool { } type PathFilterState interface { - eat(PathSegment) map[PathFilterState]struct{} + eat(walk.PathSegment) map[PathFilterState]struct{} accept() bool } |