forked from leancloud/satori
-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.go
32 lines (26 loc) · 944 Bytes
/
func.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
package utils
import (
"fmt"
)
func PK(endpoint, metric string, tags map[string]string) string {
if tags == nil || len(tags) == 0 {
return fmt.Sprintf("%s/%s", endpoint, metric)
}
return fmt.Sprintf("%s/%s/%s", endpoint, metric, SortedTags(tags))
}
func PK2(endpoint, counter string) string {
return fmt.Sprintf("%s/%s", endpoint, counter)
}
func UUID(endpoint, metric string, tags map[string]string, dstype string, step int) string {
if tags == nil || len(tags) == 0 {
return fmt.Sprintf("%s/%s/%s/%d", endpoint, metric, dstype, step)
}
return fmt.Sprintf("%s/%s/%s/%s/%d", endpoint, metric, SortedTags(tags), dstype, step)
}
func Checksum(endpoint string, metric string, tags map[string]string) string {
pk := PK(endpoint, metric, tags)
return Md5(pk)
}
func ChecksumOfUUID(endpoint, metric string, tags map[string]string, dstype string, step int64) string {
return Md5(UUID(endpoint, metric, tags, dstype, int(step)))
}