forked from moov-io/base
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathid.go
More file actions
23 lines (20 loc) · 624 Bytes
/
id.go
File metadata and controls
23 lines (20 loc) · 624 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package base
import (
"crypto/rand"
"encoding/hex"
"strings"
)
// ID creates a new random string for Moov systems.
// Do not assume anything about these ID's other than they are non-empty strings.
func ID() string {
// NOTE(adam): Moov's apps depend on the length and hex encoding of these ID's to cleanup HTTP Prometheus metrics.
bs := make([]byte, 20)
n, err := rand.Read(bs)
if err != nil || n == 0 {
return ""
}
return strings.ToLower(hex.EncodeToString(bs))
}