mirror of
https://github.com/harness/drone.git
synced 2025-05-12 23:20:10 +08:00
26 lines
612 B
Go
26 lines
612 B
Go
// Copyright 2022 Harness Inc. All rights reserved.
|
|
// Use of this source code is governed by the Polyform Free Trial License
|
|
// that can be found in the LICENSE.md file for this repository.
|
|
|
|
package job
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/base32"
|
|
)
|
|
|
|
// UID returns unique random string with length equal to 16.
|
|
func UID() (string, error) {
|
|
const uidSizeBytes = 10 // must be divisible by 5, the resulting string length will be uidSizeBytes/5*8
|
|
|
|
var buf [uidSizeBytes]byte
|
|
_, err := rand.Read(buf[:])
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
uid := base32.StdEncoding.EncodeToString(buf[:])
|
|
|
|
return uid, nil
|
|
}
|