-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmisc.go
43 lines (39 loc) · 1002 Bytes
/
misc.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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Contributor:
// - Aaron Meihm [email protected]
package main
import (
"crypto/sha256"
"fmt"
"time"
)
// Given an identifier for an object in the state index, produce the id
// value that will be used for the object.
func getObjectID(n string) (ret string, err error) {
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf("getObjectID() -> %v", e)
}
}()
if n == "" {
panic("zero length object id")
}
h := sha256.New()
idstr := fmt.Sprintf("id-%v-%v", cfg.General.Context, n)
h.Write([]byte(idstr))
return fmt.Sprintf("%x", h.Sum(nil)), nil
}
func timeWithOffset() time.Time {
ret := time.Now().UTC()
if cfg.Timer.Offset != "" {
dur, err := time.ParseDuration(cfg.Timer.Offset)
if err != nil {
panic(err)
}
ret = ret.Add(-1 * dur)
}
return ret
}