-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.go
62 lines (54 loc) · 1.27 KB
/
tools.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 template
import (
"bytes"
"html"
"strings"
)
func htmlSize(buff *bytes.Buffer, size int64) {
thousand := int64(1)
for j := size; j > 1000; j /= 1000 {
thousand *= 1000
}
if true {
i := (size / thousand) % 1000
thousand /= 1000
if 100 < i {
buff.WriteByte(byte(i/100) + '0')
}
if 10 < i {
buff.WriteByte(byte(i/10%10) + '0')
}
buff.WriteByte(byte(i%10) + '0')
}
for ; thousand > 0; thousand /= 1000 {
i := (size / thousand) % 1000
buff.WriteByte(' ')
buff.WriteByte(byte(i/100) + '0')
buff.WriteByte(byte(i/10%10) + '0')
buff.WriteByte(byte(i%10) + '0')
}
buff.WriteString(" B")
}
func htmlPath(buff *bytes.Buffer, path string) {
buff.WriteString(`<div id=p><a href="/">/</a>`)
defer buff.WriteString(`</div>`)
splits := strings.Split(strings.TrimPrefix(path, "/"), "/")
end := splits[len(splits)-1]
splits = splits[:len(splits)-1]
all := bytes.NewBufferString("/")
for _, p := range splits {
h := html.EscapeString(p)
all.WriteString(h)
all.WriteByte('/')
buff.WriteString(`<a href="`)
buff.WriteString(all.String())
buff.WriteString(`">`)
buff.WriteString(h)
buff.WriteString(`/</a>`)
}
if end != "" {
buff.WriteString(`<a href="">`)
buff.WriteString(html.EscapeString(end))
buff.WriteString(`</a>`)
}
}