-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.go
62 lines (57 loc) · 1.19 KB
/
object.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 main
import (
"strings"
)
type object struct {
paths map[string]bool
cache map[string]string
}
func (o *object) add(in string) {
o.paths[in] = true
}
func (o *object) fullPathByShortPath(in string) string {
if result, ok := o.cache[in]; ok {
return result
}
if !strings.Contains(in, "/") {
return ""
}
if strings.HasPrefix(in, "k8s") ||
strings.HasPrefix(in, "a.yandex-team.ru/library") ||
strings.HasPrefix(in, "google.golang.org") ||
strings.HasPrefix(in, "golang.org") ||
in == "encoding/gob" ||
in == "crypto/tls" ||
in == "hash/fnv" ||
in == "database/sql" ||
strings.HasPrefix(in, "github.com") ||
in == "encoding/json" ||
in == "transfer_manager/go/proto/api" ||
in == "net/http" {
return ""
}
if strings.HasPrefix(in, "a.yandex-team.ru/") {
in = strings.TrimPrefix(in, "a.yandex-team.ru/")
}
count := 0
result := ""
for currPath := range o.paths {
if strings.HasSuffix(currPath, "/"+in) {
count++
result = currPath
}
}
if count != 1 {
//panic("!")
//fmt.Println(in)
return ""
}
o.cache[in] = result
return result
}
func newObject() *object {
return &object{
paths: make(map[string]bool),
cache: make(map[string]string),
}
}