当前位置: 首页>>代码示例>>Golang>>正文


Golang uuid.NewRandom函数代码示例

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


在下文中一共展示了NewRandom函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getSessionSecrets

func getSessionSecrets(filename string) ([]string, error) {
	// Build secrets list
	secrets := []string{}

	if len(filename) != 0 {
		sessionSecrets, err := latest.ReadSessionSecrets(filename)
		if err != nil {
			return nil, fmt.Errorf("error reading sessionSecretsFile %s: %v", filename, err)
		}

		if len(sessionSecrets.Secrets) == 0 {
			return nil, fmt.Errorf("sessionSecretsFile %s contained no secrets", filename)
		}

		for _, s := range sessionSecrets.Secrets {
			secrets = append(secrets, s.Authentication)
			secrets = append(secrets, s.Encryption)
		}
	} else {
		// Generate random signing and encryption secrets if none are specified in config
		secrets = append(secrets, fmt.Sprintf("%x", md5.Sum([]byte(uuid.NewRandom().String()))))
		secrets = append(secrets, fmt.Sprintf("%x", md5.Sum([]byte(uuid.NewRandom().String()))))
	}

	return secrets, nil
}
开发者ID:pweil-,项目名称:origin,代码行数:26,代码来源:auth_config.go

示例2: TestValidateXattrSupport

func TestValidateXattrSupport(t *testing.T) {
	defer heketitests.Patch(&Setxattr, tests.MockSetxattr).Restore()
	defer heketitests.Patch(&Getxattr, tests.MockGetxattr).Restore()
	defer heketitests.Patch(&Removexattr, tests.MockRemovexattr).Restore()
	tests.Assert(t, ValidateXattrSupport("/tmp/b1", "localhost", uuid.NewRandom(), true) == nil)

	// Some negative tests
	var xattr_err error
	baderror := errors.New("Bad")
	xattr_err = baderror

	// Now check what happens when setxattr fails
	defer heketitests.Patch(&Setxattr, func(path string, attr string, data []byte, flags int) (err error) {
		return xattr_err
	}).Restore()
	tests.Assert(t, ValidateXattrSupport("/tmp/b1", "localhost", uuid.NewRandom(), true) == baderror)

	// Now check what happens when getxattr fails
	defer heketitests.Patch(&Getxattr, func(path string, attr string, dest []byte) (sz int, err error) {
		return 0, xattr_err
	}).Restore()
	tests.Assert(t, ValidateXattrSupport("/tmp/b1", "localhost", uuid.NewRandom(), true) == baderror)

	// Now check what happens when removexattr fails
	defer heketitests.Patch(&Removexattr, func(path string, attr string) (err error) {
		return xattr_err
	}).Restore()
	tests.Assert(t, ValidateXattrSupport("/tmp/b1", "localhost", uuid.NewRandom(), true) == baderror)

}
开发者ID:anekkunt,项目名称:glusterd2,代码行数:30,代码来源:utils_test.go

示例3: GenerateAccessToken

// GenerateAccessToken generates base64-encoded UUID access and refresh tokens
func (a *AccessTokenGenDefault) GenerateAccessToken(c context.Context, data *AccessData, generaterefresh bool) (accesstoken string, refreshtoken string, err error) {
	token := uuid.NewRandom()
	accesstoken = removePadding(base64.URLEncoding.EncodeToString([]byte(token)))

	if generaterefresh {
		rtoken := uuid.NewRandom()
		refreshtoken = removePadding(base64.URLEncoding.EncodeToString([]byte(rtoken)))
	}
	return
}
开发者ID:credli,项目名称:osin,代码行数:11,代码来源:tokengen.go

示例4: SendWhileRunning

func (s *btrfsMigrationSourceDriver) SendWhileRunning(conn *websocket.Conn, op *operation) error {
	if s.container.IsSnapshot() {
		tmpPath := containerPath(fmt.Sprintf("%s/.migration-send-%s", s.container.Name(), uuid.NewRandom().String()), true)
		err := os.MkdirAll(tmpPath, 0700)
		if err != nil {
			return err
		}

		btrfsPath := fmt.Sprintf("%s/.root", tmpPath)
		if err := s.btrfs.subvolSnapshot(s.container.Path(), btrfsPath, true); err != nil {
			return err
		}

		defer s.btrfs.subvolDelete(btrfsPath)

		wrapper := StorageProgressReader(op, "fs_progress", s.container.Name())
		return s.send(conn, btrfsPath, "", wrapper)
	}

	for i, snap := range s.snapshots {
		prev := ""
		if i > 0 {
			prev = s.snapshots[i-1].Path()
		}

		wrapper := StorageProgressReader(op, "fs_progress", snap.Name())
		if err := s.send(conn, snap.Path(), prev, wrapper); err != nil {
			return err
		}
	}

	/* We can't send running fses, so let's snapshot the fs and send
	 * the snapshot.
	 */
	tmpPath := containerPath(fmt.Sprintf("%s/.migration-send-%s", s.container.Name(), uuid.NewRandom().String()), true)
	err := os.MkdirAll(tmpPath, 0700)
	if err != nil {
		return err
	}

	s.runningSnapName = fmt.Sprintf("%s/.root", tmpPath)
	if err := s.btrfs.subvolSnapshot(s.container.Path(), s.runningSnapName, true); err != nil {
		return err
	}

	btrfsParent := ""
	if len(s.btrfsSnapshotNames) > 0 {
		btrfsParent = s.btrfsSnapshotNames[len(s.btrfsSnapshotNames)-1]
	}

	wrapper := StorageProgressReader(op, "fs_progress", s.container.Name())
	return s.send(conn, s.runningSnapName, btrfsParent, wrapper)
}
开发者ID:akshaykarle,项目名称:lxd,代码行数:53,代码来源:storage_btrfs.go

示例5: WithAudit

// WithAudit decorates a http.Handler with audit logging information for all the
// requests coming to the server. Each audit log contains two entries:
// 1. the request line containing:
//    - unique id allowing to match the response line (see 2)
//    - source ip of the request
//    - HTTP method being invoked
//    - original user invoking the operation
//    - impersonated user for the operation
//    - namespace of the request or <none>
//    - uri is the full URI as requested
// 2. the response line containing:
//    - the unique id from 1
//    - response code
func WithAudit(handler http.Handler, attributeGetter apiserver.RequestAttributeGetter, out io.Writer) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		attribs := attributeGetter.GetAttribs(req)
		asuser := req.Header.Get(authenticationapi.ImpersonateUserHeader)
		if len(asuser) == 0 {
			asuser = "<self>"
		}
		asgroups := "<lookup>"
		requestedGroups := req.Header[authenticationapi.ImpersonateGroupHeader]
		if len(requestedGroups) > 0 {
			quotedGroups := make([]string, len(requestedGroups))
			for i, group := range requestedGroups {
				quotedGroups[i] = fmt.Sprintf("%q", group)
			}
			asgroups = strings.Join(quotedGroups, ", ")
		}
		namespace := attribs.GetNamespace()
		if len(namespace) == 0 {
			namespace = "<none>"
		}
		id := uuid.NewRandom().String()

		line := fmt.Sprintf("%s AUDIT: id=%q ip=%q method=%q user=%q as=%q asgroups=%q namespace=%q uri=%q\n",
			time.Now().Format(time.RFC3339Nano), id, utilnet.GetClientIP(req), req.Method, attribs.GetUser().GetName(), asuser, asgroups, namespace, req.URL)
		if _, err := fmt.Fprint(out, line); err != nil {
			glog.Errorf("Unable to write audit log: %s, the error is: %v", line, err)
		}
		respWriter := decorateResponseWriter(w, out, id)
		handler.ServeHTTP(respWriter, req)
	})
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:44,代码来源:audit.go

示例6: WithAudit

// WithAudit decorates a http.Handler with audit logging information for all the
// requests coming to the server. If out is nil, no decoration takes place.
// Each audit log contains two entries:
// 1. the request line containing:
//    - unique id allowing to match the response line (see 2)
//    - source ip of the request
//    - HTTP method being invoked
//    - original user invoking the operation
//    - impersonated user for the operation
//    - namespace of the request or <none>
//    - uri is the full URI as requested
// 2. the response line containing:
//    - the unique id from 1
//    - response code
func WithAudit(handler http.Handler, attributeGetter RequestAttributeGetter, out io.Writer) http.Handler {
	if out == nil {
		return handler
	}
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		attribs, err := attributeGetter.GetAttribs(req)
		if err != nil {
			internalError(w, req, err)
			return
		}
		asuser := req.Header.Get("Impersonate-User")
		if len(asuser) == 0 {
			asuser = "<self>"
		}
		namespace := attribs.GetNamespace()
		if len(namespace) == 0 {
			namespace = "<none>"
		}
		id := uuid.NewRandom().String()

		line := fmt.Sprintf("%s AUDIT: id=%q ip=%q method=%q user=%q as=%q namespace=%q uri=%q\n",
			time.Now().Format(time.RFC3339Nano), id, utilnet.GetClientIP(req), req.Method, attribs.GetUser().GetName(), asuser, namespace, req.URL)
		if _, err := fmt.Fprint(out, line); err != nil {
			glog.Errorf("Unable to write audit log: %s, the error is: %v", line, err)
		}
		respWriter := decorateResponseWriter(w, out, id)
		handler.ServeHTTP(respWriter, req)
	})
}
开发者ID:bryk,项目名称:kubernetes,代码行数:43,代码来源:audit.go

示例7: TestGuessAuthToken

func (s *OptionsSuite) TestGuessAuthToken() {
	tmpFile, err := ioutil.TempFile("", "test-auth-token")
	s.Nil(err)

	token := uuid.NewRandom().String()
	_, err = tmpFile.Write([]byte(token))
	s.Nil(err)

	tokenStore := tmpFile.Name()
	defer os.Remove(tokenStore)
	defer tmpFile.Close()

	args := []string{
		"wercker",
		"--auth-token-store", tokenStore,
		"test",
	}

	test := func(c *cli.Context) {
		opts, err := core.NewGlobalOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.Equal(token, opts.AuthToken)
	}

	run(s, globalFlags, emptyFlags, test, args)
}
开发者ID:rlugojr,项目名称:wercker,代码行数:26,代码来源:options_test.go

示例8: CreateRetentionPolicy

func (db *DB) CreateRetentionPolicy(expiry uint) (uuid.UUID, error) {
	id := uuid.NewRandom()
	return id, db.Exec(
		`INSERT INTO retention (uuid, expiry) VALUES (?, ?)`,
		id.String(), expiry,
	)
}
开发者ID:starkandwayne,项目名称:shield,代码行数:7,代码来源:retention.go

示例9: runProcessor

func (p *ProcessorPool) runProcessor(queue JobQueue) error {
	processorUUID := uuid.NewRandom()
	ctx := context.FromProcessor(p.Context, processorUUID.String())

	jobsChan, err := queue.Jobs(ctx)
	if err != nil {
		context.LoggerFromContext(p.Context).WithField("err", err).Error("couldn't create jobs channel")
		return err
	}

	proc, err := NewProcessor(ctx, p.Hostname, jobsChan, p.Provider, p.Generator, p.Canceller, p.HardTimeout, p.LogTimeout)
	if err != nil {
		context.LoggerFromContext(p.Context).WithField("err", err).Error("couldn't create processor")
		return err
	}

	proc.SkipShutdownOnLogTimeout = p.SkipShutdownOnLogTimeout

	p.processorsLock.Lock()
	p.processors = append(p.processors, proc)
	p.processorsLock.Unlock()

	proc.Run()
	return nil
}
开发者ID:henrikhodne-abandoned,项目名称:worker,代码行数:25,代码来源:processor_pool.go

示例10: NewDeployOptions

// NewDeployOptions constructor
func NewDeployOptions(c util.Settings, e *util.Environment) (*PipelineOptions, error) {
	pipelineOpts, err := NewPipelineOptions(c, e)
	if err != nil {
		return nil, err
	}
	// default to last build output if none defined
	target, _ := c.String("target")
	if target == "" {
		found, err := util.Exists("./.wercker/latest/output")
		if err == nil && found {
			util.RootLogger().Println("No target specified, using recent build output.")
			pipelineOpts.ProjectPath, _ = filepath.Abs("./.wercker/latest/output")
		}
	}

	// if the deploy target path does not have a wercker.yml, use the current one
	werckerYml, _ := c.String("wercker-yml")
	if werckerYml == "" {
		found, _ := util.Exists(filepath.Join(pipelineOpts.ProjectPath, "wercker.yml"))
		if !found {
			pipelineOpts.WerckerYml = "./wercker.yml"
		}
	}

	if pipelineOpts.RunID == "" {
		pipelineOpts.RunID = uuid.NewRandom().String()
	}
	return pipelineOpts, nil
}
开发者ID:wercker,项目名称:wercker,代码行数:30,代码来源:options.go

示例11: committer

func (f *StreamAggregatorFilter) committer(fr FilterRunner, h PluginHelper, wg *sync.WaitGroup) {
	initBatch := make([]byte, 0, 10000)
	f.backChan <- initBatch
	var (
		tag      string
		outBatch []byte
	)
	tag = f.StreamAggregatorTag

	for outBatch = range f.batchChan {
		pack, e := h.PipelinePack(f.msgLoopCount)
		if e != nil {
			fr.LogError(e)
			break
		}

		tagField, _ := message.NewField("StreamAggregatorTag", tag, "")
		pack.Message.AddField(tagField)
		pack.Message.SetUuid(uuid.NewRandom())
		if f.OutputType == "json" {
			jsonStr := strings.TrimRight(string(outBatch), ",")
			pack.Message.SetPayload("[" + jsonStr + "]")
		} else {
			pack.Message.SetPayload(string(outBatch))
		}
		fr.Inject(pack)

		outBatch = outBatch[:0]
		f.backChan <- outBatch
	}
	wg.Done()
}
开发者ID:huhongbo,项目名称:heka-stream-aggregator,代码行数:32,代码来源:stream_aggregator_filter.go

示例12: eventsSocket

func eventsSocket(r *http.Request, w http.ResponseWriter) error {
	listener := eventListener{}

	typeStr := r.FormValue("type")
	if typeStr == "" {
		typeStr = "logging,operation"
	}

	c, err := shared.WebsocketUpgrader.Upgrade(w, r, nil)
	if err != nil {
		return err
	}

	listener.active = make(chan bool, 1)
	listener.connection = c
	listener.id = uuid.NewRandom().String()
	listener.messageTypes = strings.Split(typeStr, ",")

	eventsLock.Lock()
	eventListeners[listener.id] = &listener
	eventsLock.Unlock()

	shared.Debugf("New events listener: %s", listener.id)

	<-listener.active

	return nil
}
开发者ID:mickydelfavero,项目名称:lxd,代码行数:28,代码来源:events.go

示例13: getRandVolume

func getRandVolume() *Volinfo {
	v := NewVolinfoFunc()

	v.ID = uuid.NewRandom()
	v.Name = fmt.Sprintf("volume-%d", atomic.AddUint64(&volCount, 1))
	v.Type = DistReplicate
	brickCount := uint64(rand.Intn(256) + 1)
	for i := uint64(1); i <= brickCount; i++ {
		//v.Bricks = append(v.Bricks, fmt.Sprintf("host:/brick-%d", i))
		v.Bricks[i].Hostname = "Host"
		v.Bricks[i].Path = fmt.Sprintf("/brick-%d", i)
		v.Bricks[i].ID = v.ID
	}
	v.DistCount = uint64(rand.Intn(256) + 1)
	v.ReplicaCount = uint16(rand.Intn(10))
	v.StripeCount = uint16(rand.Intn(10))
	v.DisperseCount = uint16(rand.Intn(10))
	v.RedundancyCount = uint16(rand.Intn(10))

	v.Status = VolCreated

	v.Checksum = uint64(rand.Uint32())
	v.Version = 1

	return v
}
开发者ID:anekkunt,项目名称:glusterd2,代码行数:26,代码来源:utils_misc.go

示例14: buildPodManifest

func (img *Image) buildPodManifest(exec []string) *schema.PodManifest {
	bpm := schema.BlankPodManifest()

	// Figure out working path that doesn't exist in the image's rootfs
	workDir := ".jetpack.build."
	for {
		if _, err := os.Stat(img.getRootfs().Path(workDir)); err != nil {
			if os.IsNotExist(err) {
				break
			}
			panic(err)
		}
		workDir = fmt.Sprintf(".jetpack.build.%v", uuid.NewRandom())
	}

	bprta := img.RuntimeApp()
	bprta.Name.Set("jetpack/build")
	bprta.App = &types.App{
		Exec:             exec,
		WorkingDirectory: "/" + workDir,
		User:             "0",
		Group:            "0",
	}
	bpm.Apps = append(bpm.Apps, bprta)

	// This is needed by freebsd-update at least, should be okay to
	// allow this in builders.
	bpm.Annotations.Set("jetpack/jail.conf/allow.chflags", "true")
	bpm.Annotations.Set("jetpack/jail.conf/securelevel", "0")

	return bpm
}
开发者ID:saper,项目名称:jetpack,代码行数:32,代码来源:build.go

示例15: newNotice

func newNotice(config *Configuration, err Error, extra ...interface{}) *Notice {
	notice := Notice{
		APIKey:       config.APIKey,
		Error:        err,
		Token:        uuid.NewRandom().String(),
		ErrorMessage: err.Message,
		ErrorClass:   err.Class,
		Env:          config.Env,
		Hostname:     config.Hostname,
		Backtrace:    composeStack(err.Stack, config.Root),
		ProjectRoot:  config.Root,
		Context:      Context{},
	}

	for _, thing := range extra {
		switch t := thing.(type) {
		case Context:
			notice.setContext(t)
		case Params:
			notice.Params = t
		case CGIData:
			notice.CGIData = t
		case url.URL:
			notice.URL = t.String()
		}
	}

	return &notice
}
开发者ID:jorjeb,项目名称:smart_app,代码行数:29,代码来源:notice.go


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