• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cshum / imagor / 4142091150

10 Feb 2023 08:24AM UTC coverage: 90.999% (-0.2%) from 91.179%
4142091150

Pull #282

github

Adrian Shum
refactor interfaces
Pull Request #282: feat(server): Add optional Prometheus metrics server

67 of 67 new or added lines in 4 files covered. (100.0%)

5530 of 6077 relevant lines covered (91.0%)

1.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.74
/imagorpath/hasher.go
1
package imagorpath
2

3
import (
4
        "crypto/sha1"
5
        "encoding/hex"
6
        "strings"
7
)
8

9
// StorageHasher define image key for storage
10
type StorageHasher interface {
11
        Hash(image string) string
12
}
13

14
// ResultStorageHasher define key for result storage
15
type ResultStorageHasher interface {
16
        HashResult(p Params) string
17
}
18

19
// StorageHasherFunc StorageHasher handler func
20
type StorageHasherFunc func(image string) string
21

22
// Hash implements StorageHasher interface
23
func (h StorageHasherFunc) Hash(image string) string {
24
        return h(image)
×
25
}
×
26

×
27
// ResultStorageHasherFunc ResultStorageHasher handler func
28
type ResultStorageHasherFunc func(p Params) string
29

30
// HashResult implements ResultStorageHasher interface
31
func (h ResultStorageHasherFunc) HashResult(p Params) string {
32
        return h(p)
1✔
33
}
1✔
34

1✔
35
func hexDigestPath(path string) string {
36
        var digest = sha1.Sum([]byte(path))
1✔
37
        var hash = hex.EncodeToString(digest[:])
1✔
38
        return hash[:2] + "/" + hash[2:4] + "/" + hash[4:]
1✔
39
}
1✔
40

1✔
41
// DigestStorageHasher StorageHasher using SHA digest
42
var DigestStorageHasher = StorageHasherFunc(hexDigestPath)
43

44
// DigestResultStorageHasher  ResultStorageHasher using SHA digest
45
var DigestResultStorageHasher = ResultStorageHasherFunc(func(p Params) string {
46
        if p.Path == "" {
1✔
47
                p.Path = GeneratePath(p)
2✔
48
        }
1✔
49
        return hexDigestPath(p.Path)
1✔
50
})
1✔
51

52
// SuffixResultStorageHasher  ResultStorageHasher using storage path with digest suffix
53
var SuffixResultStorageHasher = ResultStorageHasherFunc(func(p Params) string {
54
        if p.Path == "" {
1✔
55
                p.Path = GeneratePath(p)
2✔
56
        }
1✔
57
        var digest = sha1.Sum([]byte(p.Path))
1✔
58
        var hash = "." + hex.EncodeToString(digest[:])[:20]
1✔
59
        var dotIdx = strings.LastIndex(p.Image, ".")
1✔
60
        var slashIdx = strings.LastIndex(p.Image, "/")
1✔
61
        if dotIdx > -1 && slashIdx < dotIdx {
1✔
62
                ext := p.Image[dotIdx:]
2✔
63
                if p.Meta {
1✔
64
                        ext = ".json"
2✔
65
                } else {
1✔
66
                        for _, filter := range p.Filters {
2✔
67
                                if filter.Name == "format" {
2✔
68
                                        ext = "." + filter.Args
2✔
69
                                }
1✔
70
                        }
1✔
71
                }
72
                return p.Image[:dotIdx] + hash + ext // /abc/def.{digest}.jpg
73
        }
1✔
74
        return p.Image + hash // /abc/def.{digest}
75
})
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc