MCPcopy
hub / github.com/kopia/kopia / functions

Function functions

notification/notifytemplate/embeddedtemplate.go:39–103  ·  view source on GitHub ↗

functions is a map of functions that can be used in templates.

(opt Options)

Source from the content-addressed store, hash-verified

37
38// functions is a map of functions that can be used in templates.
39func functions(opt Options) template.FuncMap {
40 if opt.Timezone == nil {
41 opt.Timezone = time.Local
42 }
43
44 if opt.TimeFormat == "" {
45 opt.TimeFormat = time.RFC1123Z
46 }
47
48 return template.FuncMap{
49 "bytes": units.BytesString[int64],
50 "formatCount": formatCount,
51 "bytesDelta": func(v int64) string {
52 switch {
53 case v == 0:
54 return ""
55 case v > 0:
56 return " (+" + units.BytesString(v) + ")"
57 default:
58 return " (-" + units.BytesString(-v) + ")"
59 }
60 },
61 "bytesDeltaHTML": func(v int64) string {
62 switch {
63 case v == 0:
64 return ""
65 case v > 0:
66 return " <span class='increase'>(&#x2191; " + units.BytesString(v) + ")</span>"
67 default:
68 return " <span class='decrease'>(&#x2193; " + units.BytesString(-v) + ")</span>"
69 }
70 },
71 "countDelta": func(v int64) string {
72 switch {
73 case v == 0:
74 return ""
75 case v > 0:
76 return fmt.Sprintf(" (+%v)", formatCount(v))
77 default:
78 return fmt.Sprintf(" (-%v)", formatCount(-v))
79 }
80 },
81 "countDeltaHTML": func(v int64) string {
82 switch {
83 case v == 0:
84 return ""
85 case v > 0:
86 return fmt.Sprintf(" <span class='increase'>(&#x2191; %v)</span>", formatCount(v))
87 default:
88 return fmt.Sprintf(" <span class='decrease'>(&#x2193; %v)</span>", formatCount(-v))
89 }
90 },
91 "sortSnapshotManifestsByName": func(man []*notifydata.ManifestWithError) []*notifydata.ManifestWithError {
92 res := slices.Clone(man)
93 sort.Slice(res, func(i, j int) bool {
94 return res[i].Manifest.Source.String() < res[j].Manifest.Source.String()
95 })
96

Callers 1

ParseTemplateFunction · 0.85

Calls 5

BytesStringFunction · 0.92
formatCountFunction · 0.85
FormatMethod · 0.65
CloneMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected