• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang uuid.UUID类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/pborman/uuid.UUID的典型用法代码示例。如果您正苦于以下问题:Golang UUID类的具体用法?Golang UUID怎么用?Golang UUID使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了UUID类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: new_peer

func new_peer(uuid uuid.UUID) (peer *peer_t) {
	peer = &peer_t{
		uuid_bytes:  []byte(uuid),
		uuid_string: uuid.String(),
	}
	return
}
开发者ID:yangzhao28,项目名称:zmq3,代码行数:7,代码来源:intface.go


示例17: getUniqueID

/* Always make sure a new ID is unique...
 * the probability of a UUID collision is somewhere around 1% in 100 million
 * UUIDs but we'll be overly cautious and check anyway. */
func getUniqueID() (uuid.UUID, error) {
	var id uuid.UUID
	for {
		id = uuid.NewRandom()
		exists, err := dbClient.UserExists(id.String())
		if err != nil {
			return nil, errors.Wrap(err, "dbClient.UserExists")
		}
		if exists {
			continue
		}
		break
	}

	return id, nil
}
开发者ID:JustAnotherOrganization,项目名称:tiberious,代码行数:19,代码来源:clienthandler.go


示例18: GetArchive

func (db *DB) GetArchive(id uuid.UUID) (*Archive, error) {
	r, err := db.Query(`
		SELECT a.uuid, a.store_key,
		       a.taken_at, a.expires_at, a.notes,
		       t.uuid, t.plugin, t.endpoint,
		       s.uuid, s.plugin, s.endpoint, a.status, a.purge_reason

		FROM archives a
			INNER JOIN targets t   ON t.uuid = a.target_uuid
			INNER JOIN stores  s   ON s.uuid = a.store_uuid

		WHERE a.uuid = ?`, id.String())
	if err != nil {
		return nil, err
	}
	defer r.Close()

	if !r.Next() {
		return nil, nil
	}
	ann := &Archive{}

	var takenAt, expiresAt *int64
	var this, target, store NullUUID
	if err = r.Scan(
		&this, &ann.StoreKey, &takenAt, &expiresAt, &ann.Notes,
		&target, &ann.TargetPlugin, &ann.TargetEndpoint,
		&store, &ann.StorePlugin, &ann.StoreEndpoint,
		&ann.Status, &ann.PurgeReason); err != nil {

		return nil, err
	}
	ann.UUID = this.UUID
	ann.TargetUUID = target.UUID
	ann.StoreUUID = store.UUID
	if takenAt != nil {
		ann.TakenAt = parseEpochTime(*takenAt)
	}
	if expiresAt != nil {
		ann.ExpiresAt = parseEpochTime(*expiresAt)
	}

	return ann, nil
}
开发者ID:yacloud-io,项目名称:shield,代码行数:44,代码来源:archives.go


示例19: MinionSubmitTask

// MinionSubmitTask submits a new task to a given minion uuid
func (c *etcdMinionClient) MinionSubmitTask(m uuid.UUID, t *task.Task) error {
	rootDir := filepath.Join(minion.EtcdMinionSpace, m.String())
	queueDir := filepath.Join(rootDir, "queue")

	// Check if minion exists first
	_, err := c.kapi.Get(context.Background(), rootDir, nil)
	if err != nil {
		return err
	}

	// Serialize task and submit it to the minion
	data, err := json.Marshal(t)
	if err != nil {
		return err
	}

	_, err = c.kapi.CreateInOrder(context.Background(), queueDir, string(data), nil)

	return err
}
开发者ID:ycaille,项目名称:gru,代码行数:21,代码来源:etcd.go


示例20: GetRetentionPolicy

func (db *DB) GetRetentionPolicy(id uuid.UUID) (*RetentionPolicy, error) {
	r, err := db.Query(`
		SELECT uuid, name, summary, expiry
			FROM retention WHERE uuid = ?`, id.String())
	if err != nil {
		return nil, err
	}
	defer r.Close()

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

	return ann, nil
}
开发者ID:starkandwayne,项目名称:shield,代码行数:21,代码来源:retention.go



注:本文中的github.com/pborman/uuid.UUID类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang common.Light类代码示例发布时间:2022-05-28
下一篇:
Golang uuid.Parse函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap