-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathutils.go
52 lines (39 loc) · 882 Bytes
/
utils.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
// Copyright 2015 Giulio Iotti. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package pingo
import (
"fmt"
"math/rand"
"strings"
)
type meta string
func (h meta) output(key, val string) {
fmt.Printf("%s: %s: %s\n", string(h), key, val)
}
func (h meta) parse(line string) (key, val string) {
if line == "" {
return
}
if len(line) < len(string(h)) {
return
}
if line[0:len(string(h))] != string(h) {
return
}
line = line[len(string(h))+2:]
end := strings.IndexByte(line, ':')
if end < 0 {
return
}
return line[0:end], line[end+2:]
}
var _letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-")
func randstr(n int) string {
b := make([]rune, n)
l := len(_letters)
for i := range b {
b[i] = _letters[rand.Intn(l)]
}
return string(b)
}