Created
August 8, 2018 17:58
-
-
Save pgilad/71eebd59acd803e113afdd488798f333 to your computer and use it in GitHub Desktop.
Generate stable random name from string (used to generate docker tag from git branch)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"hash/fnv" | |
"math/rand" | |
"os" | |
"github.com/docker/docker/pkg/namesgenerator" | |
) | |
func hash(s string) uint64 { | |
alg := fnv.New64a() | |
alg.Write([]byte(s)) | |
return alg.Sum64() | |
} | |
func main() { | |
branch := os.Args[1] | |
seed := int64(hash(branch)) | |
rand.Seed(seed) | |
fmt.Println(namesgenerator.GetRandomName(0)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment