本文整理匯總了Golang中github.com/nu7hatch/gouuid.NewV4函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewV4函數的具體用法?Golang NewV4怎麽用?Golang NewV4使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewV4函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createNewEntity
// Create a new entity to persist into the database - start HTML extraction.
func createNewEntity(url string, entity *Entity) error {
err := NewEntityDir()
if err != nil {
log.Println("Error creating entity dir: ", err)
}
go ExtractData(entity, url)
id, err := uuid.NewV4()
if err != nil {
log.Println("Error creating UUID: ", err)
}
// Set new entities' initial data from the request.
entity.Status = ParsingStatus
entity.Url = url
entity.UUID = id.String()
entity.CreatedAt = time.Now()
// Persist new entity into the database.
err = Create(entity)
if err != nil {
return err
}
err = Find(entity, bson.M{"uuid": entity.UUID}).One(&entity)
if err != nil {
return err
}
return err
}
示例2: findGame
// findGame finds a game in the list of open games. If one doesn't exist, creates a new gameid
// returns a new Game and if it's a new game or not.
func findGame(ctx context.Context, con redis.Conn) (*Game, bool, error) {
lc := "FindGame"
// do we have an open game?
gameID, err := redis.String(con.Do("RPOP", openGames))
// ignore nil errors, since that is expected
if err != nil && err != redis.ErrNil {
logger.Error(ctx, lc, "Error finding open game: %v", err)
return new(Game), false, err
}
// is this a brand new game?
isNew := (gameID == "")
if isNew {
logger.Info(ctx, lc, "Could not find open game, creating one... ")
u, err := uuid.NewV4()
if err != nil {
return nil, false, err
}
gameID = u.String()
}
return NewGame(gameID), isNew, nil
}
示例3: ServeHTTP
func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer context.Clear(r)
u4, err := gouuid.NewV4()
if err != nil {
log.Panic(err)
}
uuidToken := u4.String()
context.Set(r, uuidKey, uuidToken)
defer bugsnag.OnCapturePanic(r, func(event bugsnag.EventDescriber) {
event.WithMetaData("request", "uuid", uuidToken)
})
log.Println(uuidToken, "Start", r.Method, r.URL, "for", parseRemoteAddr(r))
w.Header().Set("Cache-Control", "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0")
if origin, ok := isWhiteListedCorsOrigin(r); ok {
w.Header().Set("Access-Control-Allow-Origin", origin)
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Authorization, Accept, Accept-Encoding, Accept-Language, Access-Control-Request-Headers, Access-Control-Request-Method, Connection, Host, Origin, User-Agent")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS, PUT, POST, DELETE")
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Max-Age", "1728000")
}
if r.Method == "OPTIONS" {
w.Header().Set("Content-Length", "0")
w.WriteHeader(http.StatusOK)
return
}
router.Routes.ServeHTTP(w, r)
}
示例4: GenerateToken
func (t *tokengenerator) GenerateToken() (string, error) {
id, err := uuid.NewV4()
if err != nil {
return "", err
}
return id.String(), nil
}
示例5: TempDir
func (fs *FakeFileSystem) TempDir(prefix string) (string, error) {
fs.filesLock.Lock()
defer fs.filesLock.Unlock()
if fs.TempDirError != nil {
return "", fs.TempDirError
}
var path string
if len(fs.TempDirDir) > 0 {
path = fs.TempDirDir
} else {
uuid, err := gouuid.NewV4()
if err != nil {
return "", err
}
path = uuid.String()
}
// Make sure to record a reference for FileExist, etc. to work
stats := fs.getOrCreateFile(path)
stats.FileType = FakeFileTypeDir
return path, nil
}
示例6: GenerateUUID
func GenerateUUID() (uuidStr string) {
uuid, err := gouuid.NewV4()
if err != nil {
return
}
return uuid.String()
}
示例7: jwtId
func (t *JwtToken) jwtId() (string, error) {
if jti, err := uuid.NewV4(); err != nil {
return "", err
} else {
return jti.String(), nil
}
}
示例8: nextUUID
func nextUUID() (string, error) {
u, err := gouuid.NewV4()
if err != nil {
return "", err
}
return u.String(), nil
}
示例9: newUuid
func newUuid() string {
id, err := uuid.NewV4()
if err != nil {
panic(err)
}
return id.String()
}
示例10: createContainerWithoutConsume
func createContainerWithoutConsume() garden.Container {
handle, err := uuid.NewV4()
Expect(err).ShouldNot(HaveOccurred())
container, err := client.Create(garden.ContainerSpec{Handle: handle.String()})
Expect(err).ShouldNot(HaveOccurred())
return container
}
示例11: newItemId
func newItemId() string {
id, err := uuid.NewV4()
if err != nil {
panic("Failed to generate UUID")
}
return strings.ToUpper(hex.EncodeToString(id[:]))
}
示例12: GenerateUuid
func GenerateUuid() string {
Uuid, err := uuid.NewV4()
if err != nil {
log.Fatal("Failed to generate UUID")
return ""
}
return Uuid.String()
}
示例13: NewEntity
func NewEntity() (*Entity, error) {
var id *uuid.UUID
var err error
if id, err = uuid.NewV4(); err != nil {
return nil, err
}
return &Entity{UUID: id}, nil
}
示例14: generateRunId
func generateRunId(user models.User) string {
u, err := gouuid.NewV4()
if err != nil {
stats.ERROR.Println("Cannot generate UUID")
return "CannotGenerateRunId"
}
return fmt.Sprint(user.UserName, "-", user.Id, "-", u.String())
}
示例15: RandomName
func RandomName() string {
guid, err := uuid.NewV4()
if err != nil {
panic(err)
}
return guid.String()
}