本文整理汇总了Golang中github.com/dchest/uniuri.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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
}
示例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
}
示例4: generateRandomFilename
func generateRandomFilename(contentType string) string {
filename := uniuri.New()
if contentType == "image/png" {
return filename + ".png"
}
return filename + ".jpg"
}
示例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
}
示例6: rndStringSlice
func rndStringSlice(count int) []string {
var r []string
for i := 0; i < count; i++ {
r = append(r, uniuri.New())
}
return r
}
示例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)
}
示例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)
}
示例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
}
示例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
}
示例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(),
}
}
示例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)
}
示例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
}
示例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()
}
示例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
}