-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvar.go
62 lines (50 loc) · 1.22 KB
/
var.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package xmux
import (
"errors"
"net/http"
"sync"
)
const (
zero = byte('0')
one = byte('1')
lsb = byte('[') // left square brackets
rsb = byte(']') // right square brackets
space = byte(' ')
)
var uint8arr [8]uint8
// ErrBadStringFormat represents a error of input string's format is illegal .
var ErrBadStringFormat = errors.New("bad string format")
// ErrEmptyString represents a error of empty input string.
var ErrEmptyString = errors.New("empty string")
var ErrTypeUnsupport = errors.New("data type is unsupported")
func init() {
uint8arr[0] = 128
uint8arr[1] = 64
uint8arr[2] = 32
uint8arr[3] = 16
uint8arr[4] = 8
uint8arr[5] = 4
uint8arr[6] = 2
uint8arr[7] = 1
}
// 保存url里面的参数
type params map[string]string // url 参数对应的值
var allparams map[string]params // 保存的url 参数
var paramsLocker sync.RWMutex
func init() {
allparams = make(map[string]params)
paramsLocker = sync.RWMutex{}
}
func Var(r *http.Request) params {
return getParams(r.URL.Path)
}
func getParams(key string) params {
paramsLocker.Lock()
defer paramsLocker.Unlock()
return allparams[key]
}
func setParams(key string, params params) {
paramsLocker.Lock()
allparams[key] = params
paramsLocker.Unlock()
}