From 3bd45dc49a35b82dcc4ae93796c3e152d799bc0b Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sun, 19 Feb 2023 09:27:55 +0000 Subject: Move JSON serialising, deserialising and walking code into a separate package --- main/pathfilter.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'main/pathfilter.go') 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 } -- cgit v1.2.3