Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix:url.Values is not safe map #172

Merged
merged 3 commits into from
Aug 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"net/url"
"strconv"
"strings"
"sync"
)

import (
Expand Down Expand Up @@ -64,10 +65,12 @@ func (t RoleType) Role() string {
}

type baseUrl struct {
Protocol string
Location string // ip+port
Ip string
Port string
Protocol string
Location string // ip+port
Ip string
Port string
//url.Values is not safe map, add to avoid concurrent map read and map write error
paramsLock sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls place the paramsLock before Params

Params url.Values
PrimitiveURL string
ctx context.Context
Expand Down Expand Up @@ -283,14 +286,18 @@ func (c URL) Service() string {
}

func (c *URL) AddParam(key string, value string) {
c.paramsLock.Lock()
c.Params.Add(key, value)
c.paramsLock.Unlock()
}

func (c URL) GetParam(s string, d string) string {
var r string
if r = c.Params.Get(s); r == "" {
c.paramsLock.RLock()
if r = c.Params.Get(s); len(r) == 0 {
r = d
}
c.paramsLock.RUnlock()
return r
}
func (c URL) GetParamAndDecoded(key string) (string, error) {
Expand Down