当前位置: 首页>>代码示例>>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;未经允许,请勿转载。