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

Golang uniuri.New函数代码示例

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

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



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

示例1: init

func init() {
	var err error
	session, err = gorethink.Connect(gorethink.ConnectOpts{
		Address: "127.0.0.1:28015",
	})
	if err != nil {
		panic(err)
	}

	key2find = uniuri.New()

	// Create a new table
	gorethink.Db("test").TableDrop("benchmark_keys_list").Run(session)
	gorethink.Db("test").TableCreate("benchmark_keys_list").Run(session)

	var klist []*KeysList

	// Populate with sample data
	for n := 0; n < 300; n++ {
		keys := rndStringSlice(999)
		keys = randomlyInsert(keys, key2find)

		y := uniuri.New()
		if n == 153 {
			table2search = y
		}

		klist = append(klist, &KeysList{
			ID:    y,
			Voted: keys,
		})
	}

	gorethink.Db("test").Table("benchmark_keys_list").Insert(klist).Run(session)
}
开发者ID:carriercomm,项目名称:api-1,代码行数:35,代码来源:benchmark_test.go


示例2: HandleHit

func (s *Service) HandleHit(w http.ResponseWriter, req *http.Request) error {
	h, e := NewHitFromRequest(req)
	if e != nil {
		return e
	}
	if ok, e := s.Store.HasSite(h.Host); !ok {
		if e != nil {
			return e
		}
		return ErrUnknownSite
	}
	if h.Ssid == "new" {
		h.Ssid = uniuri.New()
		newCookie := &http.Cookie{Name: SsidCookieName, Value: h.Ssid}
		http.SetCookie(w, newCookie)
	}
	if h.Uid == "new" {
		h.Uid = uniuri.New()
		now := time.Now()
		newCookie := &http.Cookie{Name: UidCookieName, Value: h.Uid, MaxAge: UidCookieMaxAge, Expires: now.Add(time.Duration(UidCookieMaxAge))}
		http.SetCookie(w, newCookie)
	}

	h.SetStore(s.Store)
	go s.Save(h)
	return nil
}
开发者ID:zhuharev,项目名称:stat,代码行数:27,代码来源:service.go


示例3: createRoom

func (h *GameHub) createRoom(gameType string, playerId string) {
	r := &GameRoom{roomId: uniuri.New()}
	// Add room to game hub
	h.rooms[r.roomId] = r
	// Move calling player to that room
	r.players[playerId] = true
}
开发者ID:jwill,项目名称:go-game-server,代码行数:7,代码来源:gamehub.go


示例4: generateRandomFilename

func generateRandomFilename(contentType string) string {
	filename := uniuri.New()
	if contentType == "image/png" {
		return filename + ".png"
	}
	return filename + ".jpg"
}
开发者ID:rand99,项目名称:photoshare,代码行数:7,代码来源:image.go


示例5: generateSHA1

func generateSHA1(parent string) (id string, err error) {
	id = ""

	usr, err := user.Current()
	if err != nil {
		return
	}

	// add entropy
	s := uniuri.New()

	// maybe s would be enough, but just in case, we add more
	payload := parent + s + usr.Uid + usr.Gid + usr.Username + usr.Name + usr.HomeDir

	h := sha1.New()

	if cnt, err := io.WriteString(h, payload); cnt != len(payload) {
		return "", KinIDGenerationError{"can't write payload for SHA1"}
	} else if err != nil {
		return "", err
	}

	id = hex.EncodeToString(h.Sum(nil))

	return
}
开发者ID:ivotron,项目名称:kin,代码行数:26,代码来源:idgenerator.go


示例6: rndStringSlice

func rndStringSlice(count int) []string {
	var r []string
	for i := 0; i < count; i++ {
		r = append(r, uniuri.New())
	}
	return r
}
开发者ID:carriercomm,项目名称:api-1,代码行数:7,代码来源:benchmark_test.go


示例7: TestLinkFailures

func (suite *StoreImplTest) TestLinkFailures(c *C) {
	tableName := uniuri.New()
	db := dynamodb.New(session.New(), fakeDynamodbServer.Config)
	s := &Tree{TableName: tableName, DB: db}
	err := s.CreateTable()
	c.Assert(err, IsNil)

	v := AccountT{
		ID:                  "12345",
		Name:                "alice",
		Email:               "[email protected]",
		UnmarshalFailPlease: true,
	}
	err = s.Put([]string{"Accounts", "12345"}, &v)
	c.Assert(err, IsNil)

	err = s.PutLink([]string{"AccountsByEmail", "[email protected]"}, []string{"Accounts", "12345"})
	c.Assert(err, IsNil)

	_, err = s.GetLink([]string{"AccountsByEmail", "missing"})
	c.Assert(err, Equals, ErrNotFound)

	_, err = s.GetLink([]string{"Accounts", "12345"})
	c.Assert(err, Equals, ErrNotLink)
}
开发者ID:crewjam,项目名称:dynamotree,代码行数:25,代码来源:dynamodb_test.go


示例8: TestLongPath

func (suite *StoreImplTest) TestLongPath(c *C) {
	tableName := uniuri.New()
	db := dynamodb.New(session.New(), fakeDynamodbServer.Config)
	s := &Tree{TableName: tableName, DB: db}
	err := s.CreateTable()
	c.Assert(err, IsNil)

	v := AccountT{
		ID:                  "12345",
		Name:                "alice",
		Email:               "[email protected]",
		UnmarshalFailPlease: true,
	}
	key := []string{}
	for i := 0; i < 50; i++ {
		key = append(key, "X")
	}
	err = s.Put(key, &v)
	c.Assert(err, IsNil)

	key2 := []string{}
	for i := 0; i < 50; i++ {
		key2 = append(key2, "L")
	}
	err = s.PutLink(key2, []string{"foo"})
	c.Assert(err, IsNil)

	err = s.Delete(key)
	c.Assert(err, IsNil)
	err = s.Delete(key2)
	c.Assert(err, IsNil)
}
开发者ID:crewjam,项目名称:dynamotree,代码行数:32,代码来源:dynamodb_test.go


示例9: Request

func (c *Client) Request(method, path string, headers map[string]string, body interface{}) ([]string, string, error) {
	if headers == nil {
		headers = map[string]string{}
	}

	if c.Headers != nil {
		for k, v := range c.Headers {
			headers[k] = v
		}
	}

	req := &Request{
		ID:      uniuri.New(),
		Type:    "request",
		Path:    path,
		Method:  method,
		Headers: headers,
	}

	if body != nil {
		data, err := json.Marshal(body)
		if err != nil {
			return nil, "", err
		}

		req.Body = string(data)
	}

	d, err := Encode(req)
	if err != nil {
		return nil, "", err
	}

	return d, req.ID, nil
}
开发者ID:carriercomm,项目名称:api-1,代码行数:35,代码来源:client.go


示例10: Take

// Take n tokens from bucket t, key k
func (client *Client) Take(t string, k string, n int32) (response *limitd.Response, takeResponse *limitd.TakeResponse, err error) {
	requestID := uniuri.New()

	request := &limitd.Request{
		Id:     proto.String(requestID),
		Method: limitd.Request_TAKE.Enum(),
		Type:   proto.String(t),
		Key:    proto.String(k),
		Count:  proto.Int32(n),
	}

	// goprotobuf.EncodeVarint followed by proto.Marshal
	responseChan := make(chan *limitd.Response)
	client.PendingRequests[requestID] = responseChan

	data, _ := proto.Marshal(request)
	data = append(proto.EncodeVarint(uint64(len(data))), data...)
	client.Conn.Write(data)

	response = <-responseChan
	takeR, err := proto.GetExtension(response, limitd.E_TakeResponse_Response)
	if err != nil {
		return
	}

	if takeResponseCasted, ok := takeR.(*limitd.TakeResponse); ok {
		takeResponse = takeResponseCasted
	}

	return
}
开发者ID:limitd,项目名称:go-client,代码行数:32,代码来源:limitd.go


示例11: NewEtcdGlobalMutexService

// NewEtcdGlobalMutexService returns a global mutex service implementation
// based on ETCD.
func NewEtcdGlobalMutexService(etcdClient client.Client, prefix string) GlobalMutexService {
	return &etcdGlobalMutexService{
		etcdClient: etcdClient,
		prefix:     prefix,
		ownerID:    uniuri.New(),
	}
}
开发者ID:pulcy,项目名称:robin,代码行数:9,代码来源:etcd_service.go


示例12: TestReservedCharacters

func (suite *StoreImplTest) TestReservedCharacters(c *C) {
	tableName := uniuri.New()
	db := dynamodb.New(session.New(), fakeDynamodbServer.Config)
	s := &Tree{
		TableName:        tableName,
		DB:               db,
		SpecialCharacter: "X",
	}
	err := s.CreateTable()
	c.Assert(err, IsNil)

	v := AccountT{
		ID:    "12345",
		Name:  "alice",
		Email: "[email protected]",
	}
	err = s.Put([]string{"Accounts", "12X345"}, &v)
	c.Assert(err, Equals, ErrReservedCharacterInKey)

	v.Xfoo = "cannot be set"
	err = s.Put([]string{"Accounts", "12345"}, &v)
	c.Assert(err, Equals, ErrReservedCharacterInAttribute)

	v.Xfoo = ""
	v.FooXBar = "can be set"
	err = s.Put([]string{"Accounts", "12345"}, &v)
	c.Assert(err, IsNil)

	err = s.PutLink([]string{"AccountsXEmail", "[email protected]"}, []string{"Accounts", "12345"})
	c.Assert(err, Equals, ErrReservedCharacterInKey)

	err = s.PutLink([]string{"AccountsByEmail", "[email protected]"}, []string{"AccountsX", "12345"})
	c.Assert(err, Equals, ErrReservedCharacterInKey)
}
开发者ID:crewjam,项目名称:dynamotree,代码行数:34,代码来源:dynamodb_test.go


示例13: CreateContainer

func (d *dockerMock) CreateContainer(docker.CreateContainerOptions) (*docker.Container, error) {
	container := &docker.Container{
		ID: uniuri.New(),
	}
	d.containers = append(d.containers, container)
	return container, nil
}
开发者ID:k2nr,项目名称:dokkaa-conductor,代码行数:7,代码来源:docker_test.go


示例14: AddTodo

// AddTodo appends a new todo to the list.
func (list *TodoList) AddTodo(title string) {
	list.todos = append(list.todos, &Todo{
		id:    uniuri.New(),
		title: title,
		list:  list,
	})
	list.changed()
}
开发者ID:influx6,项目名称:examples,代码行数:9,代码来源:todo_list.go


示例15: Start

func (lw *LocalWorker) Start(taskType string, wg *sync.WaitGroup, reqChan chan int64, resChan chan *common.Result) error {
	lw.reqChan = reqChan
	lw.resChan = resChan
	lw.wg = wg
	lw.wg.Add(1)
	go lw.runWorker(taskType, uniuri.New())

	return nil
}
开发者ID:pquerna,项目名称:hurl,代码行数:9,代码来源:worker.go


示例16: Add

func Add() (object *Object, err error) {
	object = &Object{}
	object.ObjectId = uniuri.New()
	object.Score = 0
	object.Lives = 5
	object.Completed = []string{}

	err = Set(object)
	return object, err
}
开发者ID:gkrania,项目名称:helloworldquiz,代码行数:10,代码来源:main.go


示例17: CreateLink

// CreateLink handles requests to create links
func CreateLink(c web.C, w http.ResponseWriter, r *http.Request) {
	account := r.Header.Get("X-Remote-User")
	l := Link{
		ShortLink: uniuri.New(),
		Target:    r.FormValue("t"),
		Owner:     account,
	}
	links[l.ShortLink] = l

	fmt.Fprintf(w, "%s\n", l.ShortLink)
	return
}
开发者ID:crewjam,项目名称:saml,代码行数:13,代码来源:service.go


示例18: TestDoubleCreate

func (suite *StoreImplTest) TestDoubleCreate(c *C) {
	tableName := uniuri.New()
	db := dynamodb.New(session.New(), fakeDynamodbServer.Config)
	s := &Tree{TableName: tableName, DB: db}
	err := s.CreateTable()
	c.Assert(err, IsNil)

	// Create the table again. The create fails because the table exists, which is
	// what we expect.
	err = s.CreateTable()
	c.Assert(err, IsNil)
}
开发者ID:crewjam,项目名称:dynamotree,代码行数:12,代码来源:dynamodb_test.go


示例19: wsHandler

func wsHandler(ws *websocket.Conn) {
	player := &Player{id: uniuri.New(), conn: &connection{send: make(chan string, 256), ws: ws}}
	gamehub.register <- player
	gamehub.broadcast <- player.AnnouncePlayer("Lobby", false)
	player.SendPlayerIdentity()
	defer func() {
		gamehub.unregister <- player
		gamehub.broadcast <- player.AnnouncePlayer("", true)
	}()
	go player.conn.writer()
	player.conn.reader()
}
开发者ID:jwill,项目名称:go-game-server,代码行数:12,代码来源:connection.go


示例20: NewXHR

func NewXHR(address string) (*XHR, error) {
	xhr := &XHR{
		Address:   address,
		ServerID:  paddedRandomIntn(999),
		SessionID: uniuri.New(),
	}
	xhr.TransportAddress = address + "/" + xhr.ServerID + "/" + xhr.SessionID
	if err := xhr.Init(); err != nil {
		return nil, err
	}
	xhr.StartReading()

	return xhr, nil
}
开发者ID:carriercomm,项目名称:api-1,代码行数:14,代码来源:xhr.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang uniuri.NewLen函数代码示例发布时间:2022-05-23
下一篇:
Golang siphash.Hash函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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