Skip to content

Instantly share code, notes, and snippets.

@gmarcial
Created May 10, 2022 04:07
Show Gist options
  • Save gmarcial/65bdc21a42d5cdbc97ae48f4703240f6 to your computer and use it in GitHub Desktop.
Save gmarcial/65bdc21a42d5cdbc97ae48f4703240f6 to your computer and use it in GitHub Desktop.
package uuid
import (
googleUUID "github.com/google/uuid"
)
// Generator ...
type Generator interface {
NewUUID() (string, error)
}
// uuidGenerator ...
type uuidGenerator struct{}
// NewUUIDGenerator ...
func NewUUIDGenerator() Generator {
googleUUID.EnableRandPool()
return uuidGenerator{}
}
// NewUUID ...
func (generator uuidGenerator) NewUUID() (string, error) {
uuidGenerated, err := googleUUID.NewRandom()
if err != nil {
return "", err
}
return uuidGenerated.String(), err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment