Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
ed153824
Commit
ed153824
authored
Dec 12, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved filter to events
parent
9e1689df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
0 deletions
+126
-0
filter.go
event/filter/filter.go
+70
-0
filter_test.go
event/filter/filter_test.go
+34
-0
generic_filter.go
event/filter/generic_filter.go
+22
-0
No files found.
event/filter/filter.go
0 → 100644
View file @
ed153824
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
)
}
}
}
}
}
}
event/filter/filter_test.go
0 → 100644
View file @
ed153824
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"
)
}
}
event/filter/generic_filter.go
0 → 100644
View file @
ed153824
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
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment