本文整理汇总了Golang中github.com/satori/go/uuid.NewV4函数的典型用法代码示例。如果您正苦于以下问题:Golang NewV4函数的具体用法?Golang NewV4怎么用?Golang NewV4使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewV4函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:30,代码来源:iteration_test.go
示例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)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:34,代码来源:area_test.go
示例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())
}
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:29,代码来源:comment_test.go
示例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)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:33,代码来源:iteration_test.go
示例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))
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:58,代码来源:area_test.go
示例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)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:57,代码来源:space-areas_test.go
示例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))
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:52,代码来源:identity_blackbox_test.go
示例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
}
开发者ID:escribano,项目名称:charon,代码行数:26,代码来源:registration.go
示例9: BenchmarkEncoding
func BenchmarkEncoding(b *testing.B) {
u := uuid.NewV4()
su := New()
for i := 0; i < b.N; i++ {
su.Encode(u)
}
}
开发者ID:Catorpilor,项目名称:shortuuid,代码行数:7,代码来源:shortuuid_test.go
示例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)
}
开发者ID:Nivl,项目名称:api.melvin.la,代码行数:30,代码来源:enpoints.go
示例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)
}
开发者ID:manuviswam,项目名称:GoPPT,代码行数:32,代码来源:openxml.go
示例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)
}
}
开发者ID:niukey,项目名称:learn,代码行数:26,代码来源:main.go
示例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)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:29,代码来源:iteration_test.go
示例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)
}
}
开发者ID:xqbumu,项目名称:learn,代码行数:34,代码来源:wrap_interface.go
示例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()
}
开发者ID:yweber,项目名称:gogs,代码行数:35,代码来源:issue.go
示例16: AuthPasswordLogin
func (k *Kloud) AuthPasswordLogin(r *kite.Request) (interface{}, error) {
var req PasswordLoginRequest
if err := getReq(r, &req); err != nil {
return nil, err
}
if _, err := modelhelper.CheckAndGetUser(req.Username, req.Password); err != nil {
return nil, errors.New("username and/or password does not match")
}
resp, err := k.authLogin(req.Username, &req.LoginRequest)
if err != nil {
return nil, err
}
kiteKey, err := k.Userdata.Keycreator.Create(req.Username, uuid.NewV4().String())
if err != nil {
return nil, err
}
return &PasswordLoginResponse{
LoginResponse: *resp,
KiteKey: kiteKey,
}, nil
}
开发者ID:koding,项目名称:koding,代码行数:26,代码来源:auth.go
示例17: TestCreateArea
func (test *TestAreaRepository) TestCreateArea() {
t := test.T()
resource.Require(t, resource.Database)
repo := area.NewAreaRepository(test.DB)
name := "Area 21"
i := area.Area{
Name: name,
SpaceID: uuid.NewV4(),
}
repo.Create(context.Background(), &i)
if i.ID == uuid.Nil {
t.Errorf("Area was not created, ID nil")
}
if i.CreatedAt.After(time.Now()) {
t.Errorf("Area was not created, CreatedAt after Now()?")
}
assert.Equal(t, name, i.Name)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:25,代码来源:area_test.go
示例18: Create
// Create runs the create action.
func (c *UserspaceController) Create(ctx *app.CreateUserspaceContext) error {
return models.Transactional(c.db, func(db *gorm.DB) error {
path := ctx.RequestURI
data := Data{}
err := c.db.Where("path = ?", path).First(&data).Error
fmt.Println(err)
if err != nil {
data = Data{
ID: uuid.NewV4(),
Path: ctx.RequestURI,
Data: workitem.Fields(ctx.Payload),
}
err := c.db.Create(&data).Error
if err != nil {
goa.LogError(ctx, "error adding data", "error", err.Error())
return ctx.InternalServerError()
}
} else {
err := c.db.Model(&data).Update("data", workitem.Fields(ctx.Payload)).Error
if err != nil {
goa.LogError(ctx, "error updating data", "error", err.Error())
return ctx.InternalServerError()
}
}
return ctx.NoContent()
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:30,代码来源:userspace.go
示例19: Create
func (v *vm) Create(attr vms.MachineAttributes) (vms.Machine, error) {
if waitNextCall {
time.Sleep(time.Duration(waitDelay) * time.Millisecond)
waitNextCall = false
waitDelay = 0
}
if failNextCall {
failNextCall = false
return nil, failError
}
if nilNextCall {
nilNextCall = false
return nil, nil
}
if attr.Type == nil {
attr.Type = &defaultMachineType
}
t, ok := attr.Type.(*machineType)
if !ok {
return nil, errors.New("VM Type not supported")
}
new_machine := machine{
id: uuid.NewV4().String(),
name: attr.Name,
machineType: *t,
status: vms.StatusUp,
}
allMachines = append(allMachines, &new_machine)
return &new_machine, nil
}
开发者ID:corentindrouet,项目名称:community,代码行数:33,代码来源:test.go
示例20: Start
// StartRecovery ...
func (pr *passwordRecoverer) Start(email string) error {
user, err := pr.userRepository.FindOneByUsername(email)
if err != nil {
return err
}
if !user.IsActive {
return ErrPasswordRecovererUserIsNotActive
}
if !user.IsConfirmed {
return ErrPasswordRecovererUserIsNotConfirmed
}
passwordRecovery, err := pr.passwordRecoveryRepository.Create(user.ID, uuid.NewV4().String())
if err != nil {
return err
}
err = pr.mailer.Send(user.Username, map[string]interface{}{
"user_id": passwordRecovery.UserID,
"confirmation_token": passwordRecovery.ConfirmationToken,
})
if err != nil {
return err
}
return nil
}
开发者ID:escribano,项目名称:charon,代码行数:30,代码来源:password_recoverer.go
注:本文中的github.com/satori/go/uuid.NewV4函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论