Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
96f5554a
Commit
96f5554a
authored
5 years ago
by
pantianying
Browse files
Options
Downloads
Patches
Plain Diff
add generic filter
parent
81b8c35b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
common/constant/default.go
+2
-0
2 additions, 0 deletions
common/constant/default.go
config/reference_config.go
+1
-1
1 addition, 1 deletion
config/reference_config.go
filter/impl/generic_filter.go
+75
-0
75 additions, 0 deletions
filter/impl/generic_filter.go
with
78 additions
and
1 deletion
common/constant/default.go
+
2
−
0
View file @
96f5554a
...
...
@@ -38,6 +38,8 @@ const (
PREFIX_DEFAULT_KEY
=
"default."
DEFAULT_SERVICE_FILTERS
=
"echo"
DEFAULT_REFERENCE_FILTERS
=
""
GENERIC_REFERENCE_FILTERS
=
"generic"
GENERIC
=
"$invoke"
ECHO
=
"$echo"
)
...
...
This diff is collapsed.
Click to expand it.
config/reference_config.go
+
1
−
1
View file @
96f5554a
...
...
@@ -170,7 +170,7 @@ func (refconfig *ReferenceConfig) getUrlMap() url.Values {
//filter
urlMap
.
Set
(
constant
.
REFERENCE_FILTER_KEY
,
mergeValue
(
consumerConfig
.
Filter
,
refconfig
.
Filter
,
constant
.
DEFAULT_REFERENCE_FILTERS
))
urlMap
.
Set
(
constant
.
REFERENCE_FILTER_KEY
,
mergeValue
(
consumerConfig
.
Filter
,
refconfig
.
Filter
,
constant
.
GENERIC_REFERENCE_FILTERS
))
for
_
,
v
:=
range
refconfig
.
Methods
{
urlMap
.
Set
(
"methods."
+
v
.
Name
+
"."
+
constant
.
LOADBALANCE_KEY
,
v
.
Loadbalance
)
urlMap
.
Set
(
"methods."
+
v
.
Name
+
"."
+
constant
.
RETRIES_KEY
,
strconv
.
FormatInt
(
v
.
Retries
,
10
))
...
...
This diff is collapsed.
Click to expand it.
filter/impl/generic_filter.go
0 → 100644
+
75
−
0
View file @
96f5554a
package
impl
import
(
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/filter"
"github.com/apache/dubbo-go/protocol"
invocation2
"github.com/apache/dubbo-go/protocol/invocation"
"reflect"
"strings"
)
const
(
GENERIC
=
"generic"
)
func
init
()
{
extension
.
SetFilter
(
GENERIC
,
GetGenericFilter
)
}
// when do a generic invoke, struct need to be map
type
GenericFilter
struct
{}
func
(
ef
*
GenericFilter
)
Invoke
(
invoker
protocol
.
Invoker
,
invocation
protocol
.
Invocation
)
protocol
.
Result
{
if
invocation
.
MethodName
()
==
constant
.
GENERIC
{
var
newArguments
=
invocation
.
Arguments
()
for
i
:=
range
newArguments
{
newArguments
[
i
]
=
Struct2MapAll
(
newArguments
[
i
])
}
newInvocation
:=
invocation2
.
NewRPCInvocation
(
invocation
.
MethodName
(),
newArguments
,
invocation
.
Attachments
())
return
invoker
.
Invoke
(
newInvocation
)
}
return
invoker
.
Invoke
(
invocation
)
}
func
(
ef
*
GenericFilter
)
OnResponse
(
result
protocol
.
Result
,
invoker
protocol
.
Invoker
,
invocation
protocol
.
Invocation
)
protocol
.
Result
{
return
result
}
func
GetGenericFilter
()
filter
.
Filter
{
return
&
GenericFilter
{}
}
func
Struct2MapAll
(
obj
interface
{})
map
[
string
]
interface
{}
{
t
:=
reflect
.
TypeOf
(
obj
)
v
:=
reflect
.
ValueOf
(
obj
)
result
:=
make
(
map
[
string
]
interface
{})
if
reflect
.
TypeOf
(
obj
)
.
Kind
()
==
reflect
.
Struct
{
for
i
:=
0
;
i
<
t
.
NumField
();
i
++
{
if
v
.
Field
(
i
)
.
Kind
()
==
reflect
.
Struct
{
if
v
.
Field
(
i
)
.
CanInterface
()
{
result
[
headerAtoa
(
t
.
Field
(
i
)
.
Name
)]
=
Struct2MapAll
(
v
.
Field
(
i
)
.
Interface
())
}
else
{
println
(
"not in to map,field:"
+
t
.
Field
(
i
)
.
Name
)
}
}
else
{
if
v
.
Field
(
i
)
.
CanInterface
()
{
if
tagName
:=
t
.
Field
(
i
)
.
Tag
.
Get
(
"m"
);
tagName
==
""
{
result
[
headerAtoa
(
t
.
Field
(
i
)
.
Name
)]
=
v
.
Field
(
i
)
.
Interface
()
}
else
{
result
[
tagName
]
=
v
.
Field
(
i
)
.
Interface
()
}
}
else
{
println
(
"not in to map,field:"
+
t
.
Field
(
i
)
.
Name
)
}
}
}
}
return
result
}
func
headerAtoa
(
a
string
)
(
b
string
)
{
b
=
strings
.
ToLower
(
a
[
:
1
])
+
a
[
1
:
]
return
}
This diff is collapsed.
Click to expand it.
Preview
0%
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