-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
static.go
71 lines (61 loc) · 1.65 KB
/
static.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
63
64
65
66
67
68
69
70
71
package static
import (
"fmt"
"net/url"
"time"
"github.com/google/uuid"
)
// Version and Sha are set at compile time via build arguments.
var (
// Version is the semantic version of the build or Unset.
Version = Unset
// Sha is the commit hash of the build or Unset.
Sha = Unset
)
// InitTime holds the initial start timestamp.
var InitTime = time.Now()
const (
// Unset is a sentinel value.
Unset = "unset"
// ExternalInitiatorAccessKeyHeader is the header name for the access key
// used by external initiators to authenticate
ExternalInitiatorAccessKeyHeader = "X-Chainlink-EA-AccessKey"
// ExternalInitiatorSecretHeader is the header name for the secret used by
// external initiators to authenticate
ExternalInitiatorSecretHeader = "X-Chainlink-EA-Secret"
)
func buildPrettyVersion() string {
if Version == Unset {
return " "
}
return fmt.Sprintf(" %s ", Version)
}
// SetConsumerName sets a nicely formatted application_name on the
// database uri
func SetConsumerName(uri *url.URL, name string, id *uuid.UUID) {
q := uri.Query()
applicationName := fmt.Sprintf("Chainlink%s|%s", buildPrettyVersion(), name)
if id != nil {
applicationName += fmt.Sprintf("|%s", id.String())
}
if len(applicationName) > 63 {
applicationName = applicationName[:63]
}
q.Set("application_name", applicationName)
uri.RawQuery = q.Encode()
}
// Short returns a 7-character sha prefix and version, or Unset if blank.
func Short() (shaPre string, ver string) {
return short(Sha, Version)
}
func short(sha, ver string) (string, string) {
if sha == "" {
sha = Unset
} else if len(sha) > 7 {
sha = sha[:7]
}
if ver == "" {
ver = Unset
}
return sha, ver
}