-
Notifications
You must be signed in to change notification settings - Fork 56
/
pathContext.go
44 lines (36 loc) · 1.02 KB
/
pathContext.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
package serverHandler
type pathContext struct {
download bool
downloadfile bool
sort *string // keep different for param is not specified or is empty
defaultSort string
}
func (ctx pathContext) QueryString() string {
// ?downloadfile&sort=x/&
buffer := make([]byte, 1, 22)
buffer[0] = '?'
switch {
case ctx.downloadfile:
buffer = append(buffer, []byte("downloadfile&")...) // 13 bytes
case ctx.download:
buffer = append(buffer, []byte("download&")...) // 9 bytes
}
if ctx.sort != nil && *(ctx.sort) != ctx.defaultSort {
buffer = append(buffer, []byte("sort=")...) // 5 bytes
buffer = append(buffer, []byte(*ctx.sort)...) // 2 bytes
buffer = append(buffer, '&') // 1 byte
}
buffer = buffer[:len(buffer)-1]
return string(buffer)
}
func (ctx pathContext) FileQueryString() string {
if ctx.downloadfile {
return "?downloadfile"
}
return ""
}
func (ctx pathContext) QueryStringOfSort(sort string) string {
copiedCtx := ctx
copiedCtx.sort = &sort
return copiedCtx.QueryString()
}