本文整理匯總了Golang中code/google/com/p/go-uuid/uuid.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestCreateVolumeWithBaseImage
func (s *TestSuite) TestCreateVolumeWithBaseImage(c *C) {
var err error
driver := s.driver
imageID := uuid.New()
err = driver.ActivateImage(imageID, s.imageFile)
c.Assert(err, IsNil)
volumeID := uuid.New()
err = driver.CreateVolume(volumeID, imageID, volumeSize)
c.Assert(err, IsNil)
volumeDev, err := driver.GetVolumeDevice(volumeID)
c.Assert(err, IsNil)
err = exec.Command("mount", volumeDev, devMount).Run()
c.Assert(err, IsNil)
_, err = os.Stat(filepath.Join(devMount, imageTestFile))
c.Assert(err, IsNil)
err = exec.Command("umount", devMount).Run()
c.Assert(err, IsNil)
err = driver.DeleteVolume(volumeID)
c.Assert(err, IsNil)
err = driver.DeactivateImage(imageID)
c.Assert(err, IsNil)
}
示例2: TestSnapshot
func (s *TestSuite) TestSnapshot(c *C) {
var err error
driver := s.driver
volumeID := uuid.New()
err = driver.CreateVolume(volumeID, "", volumeSize)
c.Assert(err, IsNil)
snapshotID := uuid.New()
err = driver.CreateSnapshot(snapshotID, volumeID)
c.Assert(err, IsNil)
err = driver.CreateSnapshot(snapshotID, volumeID)
c.Assert(err, Not(IsNil))
c.Assert(err, ErrorMatches, "Already has snapshot with uuid.*")
snapshotID2 := uuid.New()
err = driver.CreateSnapshot(snapshotID2, volumeID)
c.Assert(err, IsNil)
err = driver.DeleteSnapshot(snapshotID, volumeID)
c.Assert(err, IsNil)
err = driver.DeleteSnapshot(snapshotID, volumeID)
c.Assert(err, Not(IsNil))
c.Assert(err, ErrorMatches, "cannot find snapshot.*")
err = driver.DeleteVolume(volumeID)
c.Assert(err, IsNil)
}
示例3: TestToolDoesNotExist
func TestToolDoesNotExist(t *testing.T) {
// Build the Queue with the SimpleTool timer
q := Queue{authToken: "ResourceTest"}
// Add the tool
st := new(SimpleTimerTooler)
st.SetUUID(uuid.New())
q.tools = append(q.tools, st)
// Create the RPC server and bind the Queue
listen := startRPCOnce("tcp", addr, &q)
defer listen.Close()
// Connect to the RPC server
client, err := rpc.Dial("tcp", addr)
if err != nil {
t.Fatal("Error dailing RPC server.", err)
}
defer client.Close()
// Setup the Job information to start the service
params := map[string]string{"timer": "1"}
j := common.NewJob(uuid.New(), "Testing Job", "GoTestSuite", params)
// Create RPC call for starting a job
startJob := common.RPCCall{Auth: "ResourceTest", Job: j}
// Make call and expect an error of bad job
err = client.Call("Queue.AddTask", startJob, &j)
if err == nil || err.Error() != ERROR_NO_TOOL {
t.Fatal("No tool error was not returned.", err)
}
}
示例4: extractID
func extractID(q string, keyword string) string {
st, err := stripQuery(q)
if err != nil || len(st) <= 0 {
return uuid.New()
}
for _, v := range st {
kve := strings.Split(v, ":")
if len(kve) <= 0 {
continue
}
ke, ve := strings.TrimSpace(kve[0]), strings.TrimSpace(kve[1])
if ke != keyword {
continue
}
return ve
}
return uuid.New()
}
示例5: load
func (r *raids) load(filename string) error {
r.lock.Lock()
defer r.lock.Unlock()
defer r.cache()
fp, err := os.Open(filename)
if err != nil {
if os.IsNotExist(err) {
r.filename = filename
return nil
}
return err
}
r.filename = filename
defer fp.Close()
dec := json.NewDecoder(fp)
if err := dec.Decode(&r.data); err != nil {
return err
}
if r.data == nil {
r.data = map[string][]*raid{}
}
for c := range r.data {
for i := range r.data[c] {
if r.data[c][i].UUID == "" {
r.data[c][i].UUID = uuid.New()
r.data[c][i].Secret = uuid.New()
}
if r.data[c][i].Type == "" {
r.data[c][i].Type = "event"
}
}
}
return nil
}
示例6: TestUpdateOne
func TestUpdateOne(t *testing.T) {
db := NewInMemDatabase()
instance := new(types.VirtualMachine)
instance.SetUuid(uuid.New())
instance.SetName("instance")
assert.NoError(t, db.Put(instance, nil, UIDList{}))
vmi1 := new(types.VirtualMachineInterface)
vmi1.SetUuid(uuid.New())
vmi1.SetName("port1")
assert.NoError(t, db.Put(vmi1, nil, GetReferenceList(vmi1)))
vmi1.AddVirtualMachine(instance)
assert.NoError(t, db.Update(vmi1, GetReferenceList(vmi1)))
result, err := db.GetBackReferences(parseUID(instance.GetUuid()), "virtual_machine_interface")
assert.NoError(t, err)
assert.Contains(t, result, parseUID(vmi1.GetUuid()))
vmi1.ClearVirtualMachine()
assert.NoError(t, db.Update(vmi1, GetReferenceList(vmi1)))
result, err = db.GetBackReferences(parseUID(instance.GetUuid()), "virtual_machine_interface")
assert.NoError(t, err)
assert.Len(t, result, 0)
}
示例7: TestDeleteRefs
// Create floating-ip with 2 vmi references, delete it and verify that
// the back_refs are updated as expected.
func TestDeleteRefs(t *testing.T) {
db := NewInMemDatabase()
vmi1 := new(types.VirtualMachineInterface)
vmi1.SetUuid(uuid.New())
vmi1.SetName("port1")
assert.NoError(t, db.Put(vmi1, nil, GetReferenceList(vmi1)))
vmi2 := new(types.VirtualMachineInterface)
vmi2.SetUuid(uuid.New())
vmi2.SetName("port2")
assert.NoError(t, db.Put(vmi2, nil, GetReferenceList(vmi2)))
fip := new(types.FloatingIp)
fip.SetUuid(uuid.New())
fip.SetName("fip")
fip.AddVirtualMachineInterface(vmi1)
fip.AddVirtualMachineInterface(vmi2)
assert.NoError(t, db.Put(fip, nil, GetReferenceList(fip)))
assert.Error(t, db.Delete(vmi1))
result, err := db.GetBackReferences(parseUID(vmi2.GetUuid()), "floating_ip")
assert.NoError(t, err)
assert.Len(t, result, 1)
assert.NoError(t, db.Delete(fip))
result, err = db.GetBackReferences(parseUID(vmi2.GetUuid()), "floating_ip")
assert.NoError(t, err)
assert.Len(t, result, 0)
assert.NoError(t, db.Delete(vmi1))
assert.NoError(t, db.Delete(vmi2))
}
示例8: doUpload
func (h uploadHandler) doUpload(fileheader *multipart.FileHeader) error {
file, err := fileheader.Open()
defer file.Close()
if err != nil {
return err
}
contentType := fileheader.Header["Content-Type"][0]
edition := &models.Edition{
Id: uuid.New(),
ContentType: contentType,
}
dstPath := path.Join(h.bookPath, edition.Path())
dst, err := os.Create(dstPath)
if err != nil {
return err
}
defer dst.Close()
if _, err := io.Copy(dst, file); err != nil {
return err
}
opened, err := fileheader.Open()
if err != nil {
return err
}
if contentType != models.MOBI && contentType != models.EPUB {
return errors.New("Format not supported: " + contentType)
}
metaFunc := metadata.Epub
if contentType == models.MOBI {
metaFunc = metadata.Mobi
}
meta, _ := metaFunc(opened)
newBook := models.Book{
Id: uuid.New(),
Added: time.Now(),
Title: meta.Title,
Author: meta.Author,
Editions: models.Editions{edition},
}
h.db.Save(newBook)
h.es.Add(newBook)
go h.convert(contentType, newBook)
return nil
}
示例9: GenerateAccessToken
func (c *TokenGenAccessDefault) GenerateAccessToken(data *AccessTokenData) error {
data.AccessToken = uuid.New()
data.AccessToken = base64.StdEncoding.EncodeToString([]byte(data.AccessToken))
data.RefreshToken = uuid.New()
data.RefreshToken = base64.StdEncoding.EncodeToString([]byte(data.RefreshToken))
return nil
}
示例10: GenerateAccessToken
func (a *AccessTokenGenDefault) GenerateAccessToken(generaterefresh bool) (accesstoken string, refreshtoken string, err *HttpError) {
accesstoken = uuid.New()
accesstoken = base64.StdEncoding.EncodeToString([]byte(accesstoken))
if generaterefresh {
refreshtoken = uuid.New()
refreshtoken = base64.StdEncoding.EncodeToString([]byte(refreshtoken))
}
return
}
示例11: TestVolume
func (s *TestSuite) TestVolume(c *C) {
var err error
driver := s.driver
drv := driver.(*Driver)
lastDevID := drv.LastDevID
volumeID := uuid.New()
volOps, err := driver.VolumeOps()
c.Assert(err, IsNil)
opts := map[string]string{
convoydriver.OPT_SIZE: strconv.FormatInt(volumeSize, 10),
}
err = volOps.CreateVolume(volumeID, opts)
c.Assert(err, IsNil)
c.Assert(drv.LastDevID, Equals, lastDevID+1)
err = volOps.CreateVolume(volumeID, opts)
c.Assert(err, Not(IsNil))
c.Assert(err, ErrorMatches, "Already has volume with specific uuid.*")
volumeID2 := uuid.New()
wrongOpts := map[string]string{
convoydriver.OPT_SIZE: "1333333",
}
err = volOps.CreateVolume(volumeID2, wrongOpts)
c.Assert(err, Not(IsNil))
c.Assert(err.Error(), Equals, "Size must be multiple of block size")
err = volOps.CreateVolume(volumeID2, opts)
c.Assert(err, IsNil)
listOpts := map[string]string{
convoydriver.OPT_VOLUME_UUID: volumeID,
}
_, err = volOps.ListVolume(map[string]string{})
c.Assert(err, IsNil)
_, err = volOps.ListVolume(listOpts)
c.Assert(err, IsNil)
err = volOps.DeleteVolume("123")
c.Assert(err, Not(IsNil))
c.Assert(err, ErrorMatches, "Cannot find object .*")
err = volOps.DeleteVolume(volumeID2)
c.Assert(err, IsNil)
err = volOps.DeleteVolume(volumeID)
c.Assert(err, IsNil)
}
示例12: TestLocalServiceManager
func TestLocalServiceManager(t *testing.T) {
assert := assert.New(t)
LocalServiceManagerTickerDuration = time.Millisecond * 500
writeFilePath := filepath.Join(os.TempDir(), uuid.New()+".txt")
defer os.Remove(writeFilePath)
batchFilePath := filepath.Join(os.TempDir(), uuid.New()+".bat")
defer os.Remove(batchFilePath)
ioutil.WriteFile(batchFilePath, []byte(`
echo %time% > `+writeFilePath+`
`), 0644)
stateFilePath := filepath.Join(os.TempDir(), uuid.New())
defer os.Remove(stateFilePath)
lsm := NewLocalServiceManager(stateFilePath)
err := lsm.Start()
assert.Nil(err)
svc := Service{
Name: "fake-service",
Directory: os.TempDir(),
Command: []string{"cmd.exe", "/q", "/c", batchFilePath},
}
err = lsm.Install(svc)
assert.Nil(err)
var foundFirst, foundLast string
fiveSecondsFromNow := time.Now().Add(5 * time.Second)
for time.Now().Before(fiveSecondsFromNow) {
bs, err := ioutil.ReadFile(writeFilePath)
if err == nil {
if foundFirst == "" {
foundFirst = string(bs)
}
foundLast = string(bs)
if foundLast != foundFirst {
break
}
}
time.Sleep(100 * time.Millisecond)
}
assert.NotEmpty(foundFirst, "expected service manager to run command and command to write file")
assert.NotEqual(foundLast, foundFirst, "expected service manager to restart commands when they stop")
err = lsm.Uninstall(svc.Name)
assert.Nil(err)
}
示例13: NewGroup
// NewGroup creates Group instance
func NewGroup(tasks ...*signatures.TaskSignature) *Group {
// Generate a group UUID
groupUUID := uuid.New()
// Auto generate task UUIDs
// Group tasks by common UUID
for _, task := range tasks {
task.UUID = uuid.New()
task.GroupUUID = groupUUID
}
return &Group{Tasks: tasks}
}
示例14: makeRing
func makeRing(config []string) *hashing.HashRing {
hr := hashing.NewHashRing()
for _, n := range config {
fields := strings.Split(n, ":")
if len(fields) < 2 {
fields = append(fields, uuid.New())
} else if fields[1] == "" {
fields[1] = uuid.New()
}
hr.AddNode(hashing.NewNode(fields[0], fields[1]))
}
return hr
}
示例15: GetListOfRecords
func GetListOfRecords() []DbRecord {
listOfRecords := make([]DbRecord, 10)
listOfRecords[0] = DbRecord{uuid.New(), "Shovel", 32.00}
listOfRecords[1] = DbRecord{uuid.New(), "Lamp", 12.97}
listOfRecords[2] = DbRecord{uuid.New(), "Food - Bread", 2.00}
listOfRecords[3] = DbRecord{uuid.New(), "Backback", 25.02}
listOfRecords[4] = DbRecord{uuid.New(), "Food - Water", 2.00}
listOfRecords[5] = DbRecord{uuid.New(), "Rope", 10.00}
listOfRecords[6] = DbRecord{uuid.New(), "Spoon", 1.00}
listOfRecords[7] = DbRecord{uuid.New(), "Food - Meat", 8.00}
listOfRecords[8] = DbRecord{uuid.New(), "Tent", 117.00}
listOfRecords[9] = DbRecord{uuid.New(), "Food - Apple", 1.50}
return listOfRecords
}