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
e7418dcc
Commit
e7418dcc
authored
4 years ago
by
cvictory
Browse files
Options
Downloads
Patches
Plain Diff
add unit test and keep origin SetParams method
parent
0c5e318a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/url.go
+11
-11
11 additions, 11 deletions
common/url.go
common/url_test.go
+10
-0
10 additions, 0 deletions
common/url_test.go
with
21 additions
and
11 deletions
common/url.go
+
11
−
11
View file @
e7418dcc
...
...
@@ -432,7 +432,7 @@ func (c *URL) SetParam(key string, value string) {
// 1. if there already has same key, the value will be override
// 2. it's not thread safe
// usually it should only be invoked when you want to modify an url, such as MergeURL
func
(
c
*
URL
)
Set
Params
(
param
url
.
Values
)
{
func
(
c
*
URL
)
Replace
Params
(
param
url
.
Values
)
{
c
.
paramsLock
.
Lock
()
defer
c
.
paramsLock
.
Unlock
()
c
.
params
=
param
...
...
@@ -570,15 +570,15 @@ func (c *URL) GetMethodParamBool(method string, key string, d bool) bool {
return
r
}
//
SetParams will put all key-value pair into url.
//
1. if there already has same key, the value will be override
//
2. it's not thread safe
//
3. think twice when you want to invoke this method
//
func (c *URL) SetParams(m url.Values) {
//
for k := range m {
//
c.SetParam(k, m.Get(k))
//
}
//
}
//SetParams will put all key-value pair into url.
//1. if there already has same key, the value will be override
//2. it's not thread safe
//3. think twice when you want to invoke this method
func
(
c
*
URL
)
SetParams
(
m
url
.
Values
)
{
for
k
:=
range
m
{
c
.
SetParam
(
k
,
m
.
Get
(
k
))
}
}
// ToMap transfer URL to Map
func
(
c
*
URL
)
ToMap
()
map
[
string
]
string
{
...
...
@@ -659,7 +659,7 @@ func MergeUrl(serviceUrl *URL, referenceUrl *URL) *URL {
}
}
// In this way, we will raise some performance.
mergedUrl
.
Set
Params
(
params
)
mergedUrl
.
Replace
Params
(
params
)
return
mergedUrl
}
...
...
This diff is collapsed.
Click to expand it.
common/url_test.go
+
10
−
0
View file @
e7418dcc
...
...
@@ -307,6 +307,16 @@ func TestURLSetParams(t *testing.T) {
assert
.
Equal
(
t
,
"2.6.0"
,
u1
.
GetParam
(
"version"
,
""
))
}
func
TestURLReplaceParams
(
t
*
testing
.
T
)
{
u1
,
err
:=
NewURL
(
"dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0&configVersion=1.0"
)
assert
.
NoError
(
t
,
err
)
params
:=
url
.
Values
{}
params
.
Set
(
"key"
,
"3"
)
u1
.
ReplaceParams
(
params
)
assert
.
Equal
(
t
,
"3"
,
u1
.
GetParam
(
"key"
,
""
))
assert
.
Equal
(
t
,
""
,
u1
.
GetParam
(
"version"
,
""
))
}
func
TestClone
(
t
*
testing
.
T
)
{
u1
,
err
:=
NewURL
(
"dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0&configVersion=1.0"
)
assert
.
NoError
(
t
,
err
)
...
...
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