good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
9e1689df
Commit
9e1689df
authored
Dec 12, 2014
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Generic filter interface
parent
25cf0c44
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
filter/filter.go
+70
-0
70 additions, 0 deletions
filter/filter.go
filter/filter_test.go
+34
-0
34 additions, 0 deletions
filter/filter_test.go
filter/generic_filter.go
+22
-0
22 additions, 0 deletions
filter/generic_filter.go
with
126 additions
and
0 deletions
filter/filter.go
0 → 100644
+
70
−
0
View file @
9e1689df
package
filter
import
"reflect"
type
Filter
interface
{
Compare
(
Filter
)
bool
Trigger
(
data
interface
{})
}
type
FilterEvent
struct
{
filter
Filter
data
interface
{}
}
type
Filters
struct
{
id
int
watchers
map
[
int
]
Filter
ch
chan
FilterEvent
quit
chan
struct
{}
}
func
New
()
*
Filters
{
return
&
Filters
{
ch
:
make
(
chan
FilterEvent
),
watchers
:
make
(
map
[
int
]
Filter
),
quit
:
make
(
chan
struct
{}),
}
}
func
(
self
*
Filters
)
Start
()
{
go
self
.
loop
()
}
func
(
self
*
Filters
)
Stop
()
{
close
(
self
.
quit
)
}
func
(
self
*
Filters
)
Notify
(
filter
Filter
,
data
interface
{})
{
self
.
ch
<-
FilterEvent
{
filter
,
data
}
}
func
(
self
*
Filters
)
Install
(
watcher
Filter
)
int
{
self
.
watchers
[
self
.
id
]
=
watcher
self
.
id
++
return
self
.
id
-
1
}
func
(
self
*
Filters
)
Uninstall
(
id
int
)
{
delete
(
self
.
watchers
,
id
)
}
func
(
self
*
Filters
)
loop
()
{
out
:
for
{
select
{
case
<-
self
.
quit
:
break
out
case
event
:=
<-
self
.
ch
:
for
_
,
watcher
:=
range
self
.
watchers
{
if
reflect
.
TypeOf
(
watcher
)
==
reflect
.
TypeOf
(
event
.
filter
)
{
if
watcher
.
Compare
(
event
.
filter
)
{
watcher
.
Trigger
(
event
.
data
)
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
filter/filter_test.go
0 → 100644
+
34
−
0
View file @
9e1689df
package
filter
import
"testing"
func
TestFilters
(
t
*
testing
.
T
)
{
var
success
bool
var
failure
bool
fm
:=
New
()
fm
.
Start
()
fm
.
Install
(
Generic
{
Str1
:
"hello"
,
Fn
:
func
(
data
interface
{})
{
success
=
data
.
(
bool
)
},
})
fm
.
Install
(
Generic
{
Str1
:
"hello1"
,
Str2
:
"hello"
,
Fn
:
func
(
data
interface
{})
{
failure
=
true
},
})
fm
.
Notify
(
Generic
{
Str1
:
"hello"
},
true
)
fm
.
Stop
()
if
!
success
{
t
.
Error
(
"expected 'hello' to be posted"
)
}
if
failure
{
t
.
Error
(
"hello1 was triggered"
)
}
}
This diff is collapsed.
Click to expand it.
filter/generic_filter.go
0 → 100644
+
22
−
0
View file @
9e1689df
package
filter
type
Generic
struct
{
Str1
,
Str2
,
Str3
string
Fn
func
(
data
interface
{})
}
func
(
self
Generic
)
Compare
(
f
Filter
)
bool
{
filter
:=
f
.
(
Generic
)
if
(
len
(
self
.
Str1
)
==
0
||
filter
.
Str1
==
self
.
Str1
)
&&
(
len
(
self
.
Str2
)
==
0
||
filter
.
Str2
==
self
.
Str2
)
&&
(
len
(
self
.
Str3
)
==
0
||
filter
.
Str3
==
self
.
Str3
)
{
return
true
}
return
false
}
func
(
self
Generic
)
Trigger
(
data
interface
{})
{
self
.
Fn
(
data
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment