Skip to content
Snippets Groups Projects
Commit dc4cb05a authored by vito.he's avatar vito.he
Browse files

Fix:url.Values is not safe map, so add the lock to avoid concurrent map read and map write error

parent 23b95a0f
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ import (
"net/url"
"strconv"
"strings"
"sync"
)
import (
......@@ -64,11 +65,13 @@ func (t RoleType) Role() string {
}
type baseUrl struct {
Protocol string
Location string // ip+port
Ip string
Port string
Params url.Values
Protocol string
Location string // ip+port
Ip string
Port string
Params url.Values
//url.Values is not safe map, add to avoid concurrent map read and map write error
paramsLock sync.Mutex
PrimitiveURL string
ctx context.Context
}
......@@ -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
c.paramsLock.Lock()
if r = c.Params.Get(s); r == "" {
r = d
}
c.paramsLock.Unlock()
return r
}
func (c URL) GetParamAndDecoded(key string) (string, error) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment