當前位置: 首頁>>代碼示例>>Golang>>正文


Golang gouuid.NewV4函數代碼示例

本文整理匯總了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
}
開發者ID:yeah-right,項目名稱:webhog,代碼行數:33,代碼來源:parse.go

示例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
}
開發者ID:yugui,項目名稱:grpc-simon-says,代碼行數:28,代碼來源:join.go

示例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)
}
開發者ID:refiito,項目名稱:pipes-api,代碼行數:33,代碼來源:request.go

示例4: GenerateToken

func (t *tokengenerator) GenerateToken() (string, error) {
	id, err := uuid.NewV4()
	if err != nil {
		return "", err
	}
	return id.String(), nil
}
開發者ID:bborbe,項目名稱:booking,代碼行數:7,代碼來源:tokengenerator.go

示例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
}
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:26,代碼來源:fake_file_system.go

示例6: GenerateUUID

func GenerateUUID() (uuidStr string) {
	uuid, err := gouuid.NewV4()
	if err != nil {
		return
	}
	return uuid.String()
}
開發者ID:alex8023,項目名稱:citycloud.cf-deploy-ui,代碼行數:7,代碼來源:natsutils.go

示例7: jwtId

func (t *JwtToken) jwtId() (string, error) {
	if jti, err := uuid.NewV4(); err != nil {
		return "", err
	} else {
		return jti.String(), nil
	}
}
開發者ID:mtanlee,項目名稱:garita,代碼行數:7,代碼來源:jwt_token.go

示例8: nextUUID

func nextUUID() (string, error) {
	u, err := gouuid.NewV4()
	if err != nil {
		return "", err
	}
	return u.String(), nil
}
開發者ID:rafecolton,項目名稱:kamino,代碼行數:7,代碼來源:uuid.go

示例9: newUuid

func newUuid() string {
	id, err := uuid.NewV4()
	if err != nil {
		panic(err)
	}
	return id.String()
}
開發者ID:resc,項目名稱:gotransd,代碼行數:7,代碼來源:server.go

示例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
}
開發者ID:khassib,項目名稱:garden-windows,代碼行數:7,代碼來源:breakout_test.go

示例11: newItemId

func newItemId() string {
	id, err := uuid.NewV4()
	if err != nil {
		panic("Failed to generate UUID")
	}
	return strings.ToUpper(hex.EncodeToString(id[:]))
}
開發者ID:gaku,項目名稱:1pass,代碼行數:7,代碼來源:vault.go

示例12: GenerateUuid

func GenerateUuid() string {
	Uuid, err := uuid.NewV4()
	if err != nil {
		log.Fatal("Failed to generate UUID")
		return ""
	}
	return Uuid.String()
}
開發者ID:joernweissenborn,項目名稱:aursirrt,代碼行數:8,代碼來源:storagecore.go

示例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
}
開發者ID:robskillington,項目名稱:gokit-gorilla-mux-starter,代碼行數:8,代碼來源:entity.go

示例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())
}
開發者ID:thnguyn2,項目名稱:WebGPU,代碼行數:8,代碼來源:secured_app.go

示例15: RandomName

func RandomName() string {
	guid, err := uuid.NewV4()
	if err != nil {
		panic(err)
	}

	return guid.String()
}
開發者ID:naohiko,項目名稱:cf-acceptance-tests,代碼行數:8,代碼來源:random_name.go


注:本文中的github.com/nu7hatch/gouuid.NewV4函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。