Skip to content

Instantly share code, notes, and snippets.

@pgilad
Created August 8, 2018 17:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgilad/71eebd59acd803e113afdd488798f333 to your computer and use it in GitHub Desktop.
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)
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