本文整理匯總了Golang中github.com/satori/go/uuid.NewV4函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewV4函數的具體用法?Golang NewV4怎麽用?Golang NewV4使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewV4函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestListIterationBySpace
func (test *TestIterationRepository) TestListIterationBySpace() {
t := test.T()
resource.Require(t, resource.Database)
repo := iteration.NewIterationRepository(test.DB)
spaceID := uuid.NewV4()
for i := 0; i < 3; i++ {
start := time.Now()
end := start.Add(time.Hour * (24 * 8 * 3))
name := "Sprint #2" + strconv.Itoa(i)
i := iteration.Iteration{
Name: name,
SpaceID: spaceID,
StartAt: &start,
EndAt: &end,
}
repo.Create(context.Background(), &i)
}
repo.Create(context.Background(), &iteration.Iteration{
Name: "Other Spring #2",
SpaceID: uuid.NewV4(),
})
its, err := repo.List(context.Background(), spaceID)
assert.Nil(t, err)
assert.Len(t, its, 3)
}
示例2: TestCreateChildArea
func (test *TestAreaRepository) TestCreateChildArea() {
t := test.T()
resource.Require(t, resource.Database)
repo := area.NewAreaRepository(test.DB)
name := "Area #24"
name2 := "Area #24.1"
i := area.Area{
Name: name,
SpaceID: uuid.NewV4(),
}
err := repo.Create(context.Background(), &i)
assert.Nil(t, err)
// ltree field doesnt accept "-" , so we will save them as "_"
expectedPath := strings.Replace((i.ID).String(), "-", "_", -1)
area2 := area.Area{
Name: name2,
SpaceID: uuid.NewV4(),
Path: expectedPath,
}
err = repo.Create(context.Background(), &area2)
assert.Nil(t, err)
actualArea, err := repo.Load(context.Background(), area2.ID)
actualPath := actualArea.Path
require.Nil(t, err)
require.NotNil(t, actualArea)
assert.Equal(t, expectedPath, actualPath)
}
示例3: TestDeleteComment
func (test *TestCommentRepository) TestDeleteComment() {
t := test.T()
resource.Require(t, resource.Database)
defer cleaner.DeleteCreatedEntities(test.DB)()
repo := comment.NewCommentRepository(test.DB)
parentID := "AA"
c := &comment.Comment{
ParentID: parentID,
Body: "Test AA",
CreatedBy: uuid.NewV4(),
ID: uuid.NewV4(),
}
repo.Create(context.Background(), c)
if c.ID == uuid.Nil {
t.Errorf("Comment was not created, ID nil")
}
c.Body = "Test AB"
err := repo.Delete(context.Background(), c.ID)
if err != nil {
t.Error("Failed to Delete", err.Error())
}
}
示例4: TestCreateChildIteration
func (test *TestIterationRepository) TestCreateChildIteration() {
t := test.T()
resource.Require(t, resource.Database)
repo := iteration.NewIterationRepository(test.DB)
start := time.Now()
end := start.Add(time.Hour * (24 * 8 * 3))
name := "Sprint #24"
name2 := "Sprint #24.1"
i := iteration.Iteration{
Name: name,
SpaceID: uuid.NewV4(),
StartAt: &start,
EndAt: &end,
}
repo.Create(context.Background(), &i)
i2 := iteration.Iteration{
Name: name2,
SpaceID: uuid.NewV4(),
StartAt: &start,
EndAt: &end,
ParentID: i.ID,
}
repo.Create(context.Background(), &i2)
i2L, err := repo.Load(context.Background(), i2.ID)
require.Nil(t, err)
assert.NotEqual(t, uuid.Nil, i2.ParentID)
assert.Equal(t, i2.ParentID, i2L.ParentID)
}
示例5: TestListImmediateChildrenOfGrandParents
func (test *TestAreaRepository) TestListImmediateChildrenOfGrandParents() {
t := test.T()
resource.Require(t, resource.Database)
repo := area.NewAreaRepository(test.DB)
name := "Area #240"
name2 := "Area #240.1"
name3 := "Area #240.1.3"
// *** Create Parent Area ***
i := area.Area{
Name: name,
SpaceID: uuid.NewV4(),
}
err := repo.Create(context.Background(), &i)
assert.Nil(t, err)
// *** Create 'son' area ***
expectedPath := strings.Replace((i.ID).String(), "-", "_", -1)
area2 := area.Area{
Name: name2,
SpaceID: uuid.NewV4(),
Path: expectedPath,
}
err = repo.Create(context.Background(), &area2)
require.Nil(t, err)
childAreaList, err := repo.ListChildren(context.Background(), &i)
assert.Equal(t, 1, len(childAreaList))
require.Nil(t, err)
// *** Create 'grandson' area ***
expectedPath = strings.Replace((i.ID).String()+"."+(area2.ID.String()), "-", "_", -1)
area4 := area.Area{
Name: name3,
SpaceID: uuid.NewV4(),
Path: expectedPath,
}
err = repo.Create(context.Background(), &area4)
require.Nil(t, err)
childAreaList, err = repo.ListChildren(context.Background(), &i)
// But , There is only 1 'son' .
require.Nil(t, err)
assert.Equal(t, 1, len(childAreaList))
assert.Equal(t, area2.ID, childAreaList[0].ID)
// *** Confirm the grandson has no son
childAreaList, err = repo.ListChildren(context.Background(), &area4)
assert.Equal(t, 0, len(childAreaList))
}
示例6: TestListAreas
func (rest *TestSpaceAreaREST) TestListAreas() {
t := rest.T()
resource.Require(t, resource.Database)
// Create a new space where we'll create 3 areas
var s *space.Space
// Create another space where we'll create 1 area.
var anotherSpace *space.Space
application.Transactional(rest.db, func(app application.Application) error {
var err error
repo := app.Spaces()
newSpace := &space.Space{
Name: "Test Space 1" + uuid.NewV4().String(),
}
s, err = repo.Create(context.Background(), newSpace)
require.Nil(t, err)
newSpace = &space.Space{
Name: "Another space" + uuid.NewV4().String(),
}
anotherSpace, err = repo.Create(context.Background(), newSpace)
require.Nil(t, err)
return nil
})
svc, ctrl := rest.SecuredController()
spaceId := s.ID
anotherSpaceId := anotherSpace.ID
var createdAreaUuids1 []uuid.UUID
for i := 0; i < 3; i++ {
name := "Test Area #20" + strconv.Itoa(i)
spaceAreaContext := createSpaceArea(name, &name)
_, c := test.CreateSpaceAreasCreated(t, svc.Context, svc, ctrl, spaceId.String(), spaceAreaContext)
require.NotNil(t, c.Data.ID)
require.NotNil(t, c.Data.Relationships.Space)
createdAreaUuids1 = append(createdAreaUuids1, *c.Data.ID)
}
name := "area in a different space"
anotherSpaceAreaContext := createSpaceArea(name, &name)
_, createdArea := test.CreateSpaceAreasCreated(t, svc.Context, svc, ctrl, anotherSpaceId.String(), anotherSpaceAreaContext)
require.NotNil(t, createdArea)
_, areaList := test.ListSpaceAreasOK(t, svc.Context, svc, ctrl, spaceId.String())
assert.Len(t, areaList.Data, 3)
for i := 0; i < len(createdAreaUuids1); i++ {
assert.NotNil(t, searchInAreaSlice(createdAreaUuids1[i], areaList))
}
_, anotherAreaList := test.ListSpaceAreasOK(t, svc.Context, svc, ctrl, anotherSpaceId.String())
assert.Len(t, anotherAreaList.Data, 1)
assert.Equal(t, anotherAreaList.Data[0].ID, createdArea.Data.ID)
}
示例7: TestListIdentities
func TestListIdentities(t *testing.T) {
resource.Require(t, resource.Database)
defer cleaner.DeleteCreatedEntities(DB)()
service := goa.New("Test-Identities")
app := gormapplication.NewGormDB(DB)
identityController := NewIdentityController(service, app)
_, ic := test.ListIdentityOK(t, service.Context, service, identityController)
require.NotNil(t, ic)
numberOfCurrentIdent := len(ic.Data)
ctx := context.Background()
identityRepo := app.Identities()
identity := account.Identity{
Username: "TestUser",
Provider: "test-idp",
ID: uuid.NewV4(),
}
err := identityRepo.Create(ctx, &identity)
if err != nil {
t.Fatal(err)
}
_, ic2 := test.ListIdentityOK(t, service.Context, service, identityController)
require.NotNil(t, ic2)
assert.Equal(t, numberOfCurrentIdent+1, len(ic2.Data))
assertIdent(t, identity, findIdent(identity.ID, ic2.Data))
identity2 := account.Identity{
Username: "TestUser2",
Provider: "test-idp",
ID: uuid.NewV4(),
}
err = identityRepo.Create(ctx, &identity2)
if err != nil {
t.Fatal(err)
}
_, ic3 := test.ListIdentityOK(t, service.Context, service, identityController)
require.NotNil(t, ic3)
assert.Equal(t, numberOfCurrentIdent+2, len(ic3.Data))
assertIdent(t, identity, findIdent(identity.ID, ic3.Data))
assertIdent(t, identity2, findIdent(identity2.ID, ic3.Data))
}
示例8: createAndRegisterUser
func createAndRegisterUser(
passwordHasher security.PasswordHasher,
repository lib.UserRepository,
request *request.RegistrationRequest,
) (*model.User, error) {
confirmationToken := uuid.NewV4().String()
hashedPassword, err := passwordHasher.Hash(request.Password)
if err != nil {
return nil, err
}
user := model.NewUser(
request.Email,
hashedPassword,
request.FirstName,
request.LastName,
confirmationToken,
)
err = repository.Insert(user)
if err != nil {
return nil, err
}
return user, nil
}
示例9: BenchmarkEncoding
func BenchmarkEncoding(b *testing.B) {
u := uuid.NewV4()
su := New()
for i := 0; i < b.N; i++ {
su.Encode(u)
}
}
示例10: Handler
// Handler makes it possible to use a RouteHandler where a http.Handler is required
func Handler(e *Endpoint) http.Handler {
HTTPHandler := func(resWriter http.ResponseWriter, req *http.Request) {
request := &Request{
ID: uuid.NewV4().String()[:8],
Request: req,
Response: resWriter,
}
request.Response.Header().Set("X-Request-Id", request.ID)
if e.Params != nil {
// We give request.Params the same type as e.Params
request.Params = reflect.New(reflect.TypeOf(e.Params).Elem()).Interface()
if err := request.ParseParams(); err != nil {
request.Error(err)
return
}
}
defer request.handlePanic()
accessGranted := e.Auth == nil || e.Auth(request)
if accessGranted {
e.Handler(request)
}
}
return http.HandlerFunc(HTTPHandler)
}
示例11: DuplicateSlide
func DuplicateSlide(pptRootPath, slideName string) (newSlideName string, err error) {
newSlideName = uuid.NewV4().String() + ".xml"
newSlideName = "slilde2.xml"
slidePath := filepath.Join(pptRootPath, c.PPTFolder, c.SlideFolder, slideName)
newSlidePath := filepath.Join(pptRootPath, c.PPTFolder, c.SlideFolder, newSlideName)
err = fo.CopyFile(slidePath, newSlidePath)
if err != nil {
return "", err
}
sourceSlideRelsPath := filepath.Join(pptRootPath, c.PPTFolder, c.SlideFolder, c.RelsFolder, slideName+relsExtension)
newSlideRelsPath := filepath.Join(pptRootPath, c.PPTFolder, c.SlideFolder, c.RelsFolder, newSlideName+relsExtension)
err = fo.CopyFile(sourceSlideRelsPath, newSlideRelsPath)
if err != nil {
return "", err
}
rid, err := createRelations(pptRootPath, newSlideName)
if err != nil {
return "", err
}
err = addSlideInPresentation(pptRootPath, rid)
if err != nil {
return "", err
}
return newSlideName, addSlideContentTypeInContentTypes(pptRootPath, newSlideName)
}
示例12: wrapRouterWithLogrus
func wrapRouterWithLogrus(h http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
defer func() {
if err := recover(); err != nil {
log.Printf("recovered from panic: %+v / %+v", err, req)
// http.Error(w, http.StatusText(500), 500)
}
}()
start := time.Now()
h.ServeHTTP(w, req)
took := time.Since(start)
ip, err := getIP(req)
if err != nil {
log.Warnf("getIP error: %v", err)
}
log.WithFields(log.Fields{
"event_type": "router",
"referrer": req.Referer(),
"ua": req.UserAgent(),
"method": req.Method,
"path": req.URL.Path,
"ip": ip,
"uuid": uuid.NewV4(),
}).Debugf("took %s", took)
}
}
示例13: TestCreateIteration
func (test *TestIterationRepository) TestCreateIteration() {
t := test.T()
resource.Require(t, resource.Database)
repo := iteration.NewIterationRepository(test.DB)
start := time.Now()
end := start.Add(time.Hour * (24 * 8 * 3))
name := "Sprint #24"
i := iteration.Iteration{
Name: name,
SpaceID: uuid.NewV4(),
StartAt: &start,
EndAt: &end,
}
repo.Create(context.Background(), &i)
if i.ID == uuid.Nil {
t.Errorf("Iteration was not created, ID nil")
}
if i.CreatedAt.After(time.Now()) {
t.Errorf("Iteration was not created, CreatedAt after Now()?")
}
assert.Equal(t, start, *i.StartAt)
assert.Equal(t, end, *i.EndAt)
assert.Equal(t, name, i.Name)
}
示例14: WithLogrus
func WithLogrus(h http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
defer func() {
if err := recover(); err != nil {
log.WithFields(log.Fields{
"event_type": "panic_recover",
"referrer": req.Referer(),
"ua": req.UserAgent(),
"method": req.Method,
"path": req.URL.Path,
"ip": req.RemoteAddr,
"real_ip": getRealIP(req),
"error": err,
}).Errorln("WithLogrus error")
}
}()
start := nowPacific()
h.ServeHTTP(w, req)
took := time.Since(start)
log.WithFields(log.Fields{
"event_type": "web_server",
"referrer": req.Referer(),
"ua": req.UserAgent(),
"method": req.Method,
"path": req.URL.Path,
"ip": req.RemoteAddr,
"real_ip": getRealIP(req),
"uuid": uuid.NewV4(),
}).Debugf("took %s", took)
}
}
示例15: NewAttachment
// NewAttachment creates a new attachment object.
func NewAttachment(name string, buf []byte, file multipart.File) (_ *Attachment, err error) {
attach := &Attachment{
UUID: gouuid.NewV4().String(),
Name: name,
}
if err = os.MkdirAll(path.Dir(attach.LocalPath()), os.ModePerm); err != nil {
return nil, fmt.Errorf("MkdirAll: %v", err)
}
fw, err := os.Create(attach.LocalPath())
if err != nil {
return nil, fmt.Errorf("Create: %v", err)
}
defer fw.Close()
if _, err = fw.Write(buf); err != nil {
return nil, fmt.Errorf("Write: %v", err)
} else if _, err = io.Copy(fw, file); err != nil {
return nil, fmt.Errorf("Copy: %v", err)
}
sess := x.NewSession()
defer sessionRelease(sess)
if err := sess.Begin(); err != nil {
return nil, err
}
if _, err := sess.Insert(attach); err != nil {
return nil, err
}
return attach, sess.Commit()
}