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


Golang uuid.UUID類代碼示例

本文整理匯總了Golang中github.com/pborman/uuid.UUID的典型用法代碼示例。如果您正苦於以下問題:Golang UUID類的具體用法?Golang UUID怎麽用?Golang UUID使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了UUID類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: MinionClassifierKeys

// MinionClassifierKeys returns all classifier keys that a minion has
func (c *etcdMinionClient) MinionClassifierKeys(m uuid.UUID) ([]string, error) {
	// Classifier directory in etcd
	classifierDir := filepath.Join(minion.EtcdMinionSpace, m.String(), "classifier")
	opts := &etcdclient.GetOptions{
		Recursive: true,
	}

	resp, err := c.kapi.Get(context.Background(), classifierDir, opts)
	if err != nil {
		return nil, err
	}

	var classifierKeys []string
	for _, node := range resp.Node.Nodes {
		klassifier := new(classifier.Classifier)
		err := json.Unmarshal([]byte(node.Value), &klassifier)
		if err != nil {
			return nil, err
		}

		classifierKeys = append(classifierKeys, klassifier.Key)
	}

	return classifierKeys, nil
}
開發者ID:ycaille,項目名稱:gru,代碼行數:26,代碼來源:etcd.go

示例2: StartTask

func (db *DB) StartTask(id uuid.UUID, effective time.Time) error {
	validtime := ValidateEffectiveUnix(effective)
	return db.Exec(
		`UPDATE tasks SET status = ?, started_at = ? WHERE uuid = ?`,
		RunningStatus, validtime, id.String(),
	)
}
開發者ID:starkandwayne,項目名稱:shield,代碼行數:7,代碼來源:tasks.go

示例3: GetTarget

func (db *DB) GetTarget(id uuid.UUID) (*Target, error) {
	r, err := db.Query(`
		SELECT t.uuid, t.name, t.summary, t.plugin, t.endpoint, t.agent
			FROM targets t
				LEFT JOIN jobs j
					ON j.target_uuid = t.uuid
			WHERE t.uuid = ?`, id.String())
	if err != nil {
		return nil, err
	}
	defer r.Close()

	if !r.Next() {
		return nil, nil
	}

	ann := &Target{}
	var this NullUUID
	if err = r.Scan(&this, &ann.Name, &ann.Summary, &ann.Plugin, &ann.Endpoint, &ann.Agent); err != nil {
		return nil, err
	}
	ann.UUID = this.UUID

	return ann, nil
}
開發者ID:starkandwayne,項目名稱:shield,代碼行數:25,代碼來源:targets.go

示例4: GetStore

func (db *DB) GetStore(id uuid.UUID) (*Store, error) {
	r, err := db.Query(`
		SELECT s.uuid, s.name, s.summary, s.plugin, s.endpoint
			FROM stores s
				LEFT JOIN jobs j
					ON j.store_uuid = s.uuid
			WHERE s.uuid = ?`, id.String())
	if err != nil {
		return nil, err
	}
	defer r.Close()

	if !r.Next() {
		return nil, nil
	}

	ann := &Store{}
	var this NullUUID
	if err = r.Scan(&this, &ann.Name, &ann.Summary, &ann.Plugin, &ann.Endpoint); err != nil {
		return nil, err
	}
	ann.UUID = this.UUID

	return ann, nil
}
開發者ID:starkandwayne,項目名稱:shield,代碼行數:25,代碼來源:stores.go

示例5: GetByUuid

func (db *InMemDatabase) GetByUuid(id uuid.UUID) (contrail.IObject, error) {
	uid := makeUID(id)
	obj, ok := db.objByIdMap[uid]
	if !ok {
		return nil, fmt.Errorf("%s: Not found", id.String())
	}
	return obj, nil
}
開發者ID:hkumarmk,項目名稱:contrail-go-api,代碼行數:8,代碼來源:database.go

示例6: newPod

func newPod(h *Host, id uuid.UUID) *Pod {
	if id == nil {
		id = uuid.NewRandom()
	}
	return &Pod{
		Host: h,
		UUID: id,
		ui:   ui.NewUI("yellow", "pod", id.String()),
	}
}
開發者ID:saper,項目名稱:jetpack,代碼行數:10,代碼來源:pod.go

示例7: MinionName

// MinionName returns the name of a minion identified by its uuid
func (c *etcdMinionClient) MinionName(m uuid.UUID) (string, error) {
	nameKey := filepath.Join(minion.EtcdMinionSpace, m.String(), "name")
	resp, err := c.kapi.Get(context.Background(), nameKey, nil)

	if err != nil {
		return "", err
	}

	return resp.Node.Value, nil
}
開發者ID:ycaille,項目名稱:gru,代碼行數:11,代碼來源:etcd.go

示例8: UpdateSchedule

func (db *DB) UpdateSchedule(id uuid.UUID, ts string) error {
	_, err := timespec.Parse(ts)
	if err != nil {
		return err
	}
	return db.Exec(
		`UPDATE schedules SET timespec = ? WHERE uuid = ?`,
		ts, id.String(),
	)
}
開發者ID:starkandwayne,項目名稱:shield,代碼行數:10,代碼來源:schedules.go

示例9: NewImage

func NewImage(h *Host, id uuid.UUID) *Image {
	if id == nil {
		id = uuid.NewRandom()
	}
	return &Image{
		Host:     h,
		UUID:     id,
		Manifest: *schema.BlankImageManifest(),
		ui:       ui.NewUI("blue", "image", id.String()),
	}
}
開發者ID:saper,項目名稱:jetpack,代碼行數:11,代碼來源:image.go

示例10: GetTask

func (db *DB) GetTask(id uuid.UUID) (*Task, error) {
	filter := TaskFilter{UUID: id.String()}
	r, err := db.GetAllTasks(&filter)
	if err != nil {
		return nil, err
	}
	if len(r) == 0 {
		return nil, nil
	}
	return r[0], nil
}
開發者ID:starkandwayne,項目名稱:shield,代碼行數:11,代碼來源:tasks.go

示例11: CreateTaskArchive

func (db *DB) CreateTaskArchive(id uuid.UUID, key string, effective time.Time) (uuid.UUID, error) {
	// fail on empty store_key, as '' seems to satisfy the NOT NULL constraint in postgres
	if key == "" {
		return nil, fmt.Errorf("cannot create an archive without a store_key")
	}
	// determine how long we need to keep this specific archive for
	r, err := db.Query(
		`SELECT r.expiry
			FROM retention r
				INNER JOIN jobs  j    ON r.uuid = j.retention_uuid
				INNER JOIN tasks t    ON j.uuid = t.job_uuid
			WHERE t.uuid = ?`,
		id.String(),
	)
	if err != nil {
		return nil, err
	}
	defer r.Close()

	if !r.Next() {
		return nil, fmt.Errorf("failed to determine expiration for task %s", id)
	}

	var expiry int
	if err := r.Scan(&expiry); err != nil {
		return nil, err
	}
	r.Close()

	// insert an archive with all proper references, expiration, etc.
	archive_id := uuid.NewRandom()
	validtime := ValidateEffectiveUnix(effective)
	err = db.Exec(
		`INSERT INTO archives
			(uuid, target_uuid, store_uuid, store_key, taken_at, expires_at, notes, status, purge_reason)
			SELECT ?, t.uuid, s.uuid, ?, ?, ?, '', ?, ''
				FROM tasks
					INNER JOIN jobs    j     ON j.uuid = tasks.job_uuid
					INNER JOIN targets t     ON t.uuid = j.target_uuid
					INNER JOIN stores  s     ON s.uuid = j.store_uuid
				WHERE tasks.uuid = ?`,
		archive_id.String(), key, validtime, effective.Add(time.Duration(expiry)*time.Second).Unix(), "valid", id.String(),
	)
	if err != nil {
		return nil, err
	}

	// and finally, associate task -> archive
	return archive_id, db.Exec(
		`UPDATE tasks SET archive_uuid = ? WHERE uuid = ?`,
		archive_id.String(), id.String(),
	)
}
開發者ID:starkandwayne,項目名稱:shield,代碼行數:53,代碼來源:tasks.go

示例12: MinionLastseen

// MinionLastSeen retrieves the time a minion was last seen
func (c *etcdMinionClient) MinionLastseen(m uuid.UUID) (int64, error) {
	lastseenKey := filepath.Join(minion.EtcdMinionSpace, m.String(), "lastseen")
	resp, err := c.kapi.Get(context.Background(), lastseenKey, nil)

	if err != nil {
		return 0, err
	}

	lastseen, err := strconv.ParseInt(resp.Node.Value, 10, 64)

	return lastseen, err
}
開發者ID:ycaille,項目名稱:gru,代碼行數:13,代碼來源:etcd.go

示例13: MinionClassifier

// MinionClassifier retrieves a classifier with the given key
func (c *etcdMinionClient) MinionClassifier(m uuid.UUID, key string) (*classifier.Classifier, error) {
	// Classifier key in etcd
	classifierKey := filepath.Join(minion.EtcdMinionSpace, m.String(), "classifier", key)
	resp, err := c.kapi.Get(context.Background(), classifierKey, nil)

	if err != nil {
		return nil, err
	}

	klassifier := new(classifier.Classifier)
	err = json.Unmarshal([]byte(resp.Node.Value), &klassifier)

	return klassifier, err
}
開發者ID:ycaille,項目名稱:gru,代碼行數:15,代碼來源:etcd.go

示例14: MinionTaskResult

// MinionTaskResult retrieves the result of a task for a given minion
func (c *etcdMinionClient) MinionTaskResult(m uuid.UUID, t uuid.UUID) (*task.Task, error) {
	// Task key in etcd
	taskKey := filepath.Join(minion.EtcdMinionSpace, m.String(), "log", t.String())

	// Get the task from etcd
	resp, err := c.kapi.Get(context.Background(), taskKey, nil)
	if err != nil {
		return nil, err
	}

	result := new(task.Task)
	err = json.Unmarshal([]byte(resp.Node.Value), &result)

	return result, err
}
開發者ID:ycaille,項目名稱:gru,代碼行數:16,代碼來源:etcd.go

示例15: hasPermission

func hasPermission(session *LoginSession, uuidBytes uuid.UUID) bool {
	var tags []string
	if session == nil {
		tags = defaulttags
	} else {
		tags = session.tags
	}
	uuidString := uuidBytes.String()
	for _, tag := range tags {
		if tagHasPermission(tag, uuidBytes, uuidString) {
			return true
		}
	}

	return false
}
開發者ID:SoftwareDefinedBuildings,項目名稱:mr-plotter,代碼行數:16,代碼來源:permcache.go


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