本文整理匯總了Golang中code/google/com/p/go-uuid/uuid.Parse函數的典型用法代碼示例。如果您正苦於以下問題:Golang Parse函數的具體用法?Golang Parse怎麽用?Golang Parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Parse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetUserPerfectMatch
func (repo *CassandraChatRepo) GetUserPerfectMatch(rpf types.PerfectNumber) (types.PerfectNumber, error) {
// get match for user by id
var perfectNumber types.PerfectNumber
var user_id string
var err error
err = nil
sql := fmt.Sprintf(`SELECT user_id, perfect_number
FROM perfect_numbers WHERE perfect_number < %v LIMIT 1 ALLOW FILTERING`, rpf.PerfectNumber)
log.Printf(sql)
if err = session.Query(sql).Scan(&user_id, &perfectNumber.PerfectNumber); err != nil {
log.Printf(fmt.Sprintf("CassandraChatRepo.GetUserPerfectMatch() - Error: %v", err.Error()))
sql := fmt.Sprintf("SELECT user_id, perfect_number FROM perfect_numbers LIMIT 1")
log.Printf(sql)
if err = session.Query(sql).Scan(&user_id, &perfectNumber.PerfectNumber); err != nil {
log.Printf(fmt.Sprintf("CassandraChatRepo.GetUserPerfectMatch() - Error: %v", err.Error()))
} else {
if user_id != rpf.UserId.String() {
perfectNumber.UserId = uuid.Parse(user_id)
} else {
err = errors.New("not found")
}
}
} else {
perfectNumber.UserId = uuid.Parse(user_id)
}
return perfectNumber, err
}
示例2: CreateMessage
func CreateMessage(userId string, receiverId string, mr types.MessageRequest) error {
var err error
err = nil
if err = utilsservice.CheckIfMatchExists(userId, receiverId); err == nil {
var m types.Message
m.SenderId = uuid.Parse(userId)
m.ReceiverId = uuid.Parse(receiverId)
m.MessageId = uuid.NewRandom()
m.IsRead = false
m.Text = strings.Replace(mr.Text, "'", "''", -1)
if mr.Timestamp != 0 {
m.Timestamp = int64(time.Unix(mr.Timestamp, 0).UTC().Unix())
} else {
m.Timestamp = int64(time.Now().UTC().Unix())
}
if err = messageRepo.CreateMessage(m); err == nil {
err = chatservice.UpdateLastMessageChat(userId, receiverId, m.Text)
if lastActivity, errA := activityservice.GetUserActivity(receiverId); errA == nil {
senderUsername, _ := utilsservice.GetUserUsername(userId)
pushMessage := fmt.Sprintf("%s: %s", senderUsername, m.Text)
notificationsservice.SendPushNotification(lastActivity.DeviceType, lastActivity.PushToken, pushMessage)
}
}
}
return err
}
示例3: GetUserMatch
func (repo *CassandraMatchRepo) GetUserMatch(userId string) (types.Match, error) {
// get match for user by id
log.Printf(fmt.Sprintf("CassandraMatchRepo.GetUserMatch() - Received userId: %v", userId))
var match types.Match
var user_id string
var matched_user_id string
var err error
err = nil
sql := fmt.Sprintf(`SELECT user_id, matched_user_id,
matched_username, timestamp
FROM matches WHERE user_id = %v LIMIT 1`, userId)
log.Printf(sql)
if err = session.Query(sql).Scan(&user_id, &matched_user_id,
&match.MatchedUsername, &match.Timestamp); err != nil {
log.Printf(fmt.Sprintf("CassandraMatchRepo.GetUserMatch() - Error: %v", err.Error()))
} else {
match.UserId = uuid.Parse(user_id)
match.MatchedUserId = uuid.Parse(matched_user_id)
}
return match, err
}
示例4: GetUserLastMessageByReceiverId
func (repo *CassandraMessageRepo) GetUserLastMessageByReceiverId(userId string, receiverId string) (types.Message, error) {
// get last message for user
log.Printf(fmt.Sprintf("CassandraMessageRepo.GetUserLastMessageByReceiverId() - Received userId: %v", userId))
log.Printf(fmt.Sprintf("CassandraMessageRepo.GetUserLastMessageByReceiverId() - Received receiverId: %v", receiverId))
var messages types.Messages
var err error
err = nil
var message_id, sender_id, receiver_id string
var text string
var is_read bool
var timestamp int64
var sql string
//sender messages
sql = fmt.Sprintf(`SELECT message_id, sender_id, receiver_id, text, is_read,
timestamp FROM messages WHERE sender_id = %v AND receiver_id = %v LIMIT 1`, userId, receiverId)
log.Printf(sql)
iter := session.Query(sql).Iter()
for iter.Scan(&message_id, &sender_id, &receiver_id, &text, &is_read, ×tamp) {
messages = append(messages, types.Message{MessageId: uuid.Parse(message_id), SenderId: uuid.Parse(sender_id),
ReceiverId: uuid.Parse(receiver_id), Text: text, IsRead: is_read, Timestamp: timestamp})
}
if err = iter.Close(); err != nil {
log.Printf(fmt.Sprintf("CassandraMessageRepo.GetUserLastMessageByReceiverId() - Error: %v", err.Error()))
}
//receiver messages
sql = fmt.Sprintf(`SELECT message_id, sender_id, receiver_id, text, is_read,
timestamp FROM messages WHERE sender_id = %v AND receiver_id = %v`, receiverId, userId)
log.Printf(sql)
iter2 := session.Query(sql).Iter()
for iter2.Scan(&message_id, &sender_id, &receiver_id, &text, &is_read, ×tamp) {
messages = append(messages, types.Message{MessageId: uuid.Parse(message_id), SenderId: uuid.Parse(sender_id),
ReceiverId: uuid.Parse(receiver_id), Text: text, IsRead: is_read, Timestamp: timestamp})
}
if err = iter2.Close(); err != nil {
log.Printf(fmt.Sprintf("CassandraMessageRepo.GetUserLastMessageByReceiverId() - Error: %v", err.Error()))
}
if messages != nil {
sort.Sort(ByTimestamp(messages))
}
var message types.Message
if len(messages) > 0 {
message = messages[0]
}
return message, err
}
示例5: TestUniqueKeyCreation
func TestUniqueKeyCreation(t *testing.T) {
uniqueKey := NewUniqueKey("")
if uuid.Parse(uniqueKey.String()) == nil {
t.Error("Invalid uuid generated")
}
uniqueKey.Next()
if uuid.Parse(uniqueKey.String()) == nil {
t.Error("Invalid uuid generated")
}
}
示例6: CreateMatch
func CreateMatch(mr types.MatchRequest) error {
var err error
err = nil
if err = utilsservice.CheckIfUserExists(mr.FirstUserId); err == nil {
if err = utilsservice.CheckIfUserExists(mr.SecondUserId); err == nil {
var firstUsername string
var secondUsername string
if firstUsername, err = utilsservice.GetUserUsername(mr.FirstUserId); err == nil {
if secondUsername, err = utilsservice.GetUserUsername(mr.SecondUserId); err == nil {
var m types.Match
m.UserId = uuid.Parse(mr.FirstUserId)
m.MatchedUserId = uuid.Parse(mr.SecondUserId)
m.MatchedUsername = secondUsername
m.Timestamp = int64(time.Now().UTC().Unix())
//create first match
if err = chatRepo.CreateMatch(m); err == nil {
m.UserId = uuid.Parse(mr.SecondUserId)
m.MatchedUserId = uuid.Parse(mr.FirstUserId)
m.MatchedUsername = firstUsername
m.Timestamp = int64(time.Now().UTC().Unix())
//create second match
if err = chatRepo.CreateMatch(m); err == nil {
var cr types.ChatRequest
//create chat
cr.FirstUserId = mr.FirstUserId
cr.SecondUserId = mr.SecondUserId
err = CreateChat(cr)
//send push message to first user
if lastActivity, errA := activityservice.GetUserActivity(mr.FirstUserId); errA == nil {
notificationsservice.SendPushNotification(lastActivity.DeviceType, lastActivity.PushToken, "you've been matched!")
}
//send push message to second user
if lastActivity, errA := activityservice.GetUserActivity(mr.SecondUserId); errA == nil {
notificationsservice.SendPushNotification(lastActivity.DeviceType, lastActivity.PushToken, "you've been matched!")
}
}
}
}
}
}
}
return err
}
示例7: LookUpServers
// LookUpServers attempts to return identifiers matching a pattern
func (c *ScalewayCache) LookUpServers(needle string, acceptUUID bool) []string {
c.Lock.Lock()
defer c.Lock.Unlock()
var res []string
var exactMatches []string
if acceptUUID && uuid.Parse(needle) != nil {
res = append(res, needle)
}
nameRegex := regexp.MustCompile(`(?i)` + regexp.MustCompile(`[_-]`).ReplaceAllString(needle, ".*"))
for identifier, name := range c.Servers {
if name == needle {
exactMatches = append(exactMatches, identifier)
}
if strings.HasPrefix(identifier, needle) || nameRegex.MatchString(name) {
res = append(res, identifier)
}
}
if len(exactMatches) == 1 {
return exactMatches
}
return utils.RemoveDuplicates(res)
}
示例8: request_get_NEAREST
func request_get_NEAREST(q *btrdb.Quasar, w http.ResponseWriter, r *http.Request) {
atomic.AddInt32(&outstandingHttpReqs, 1)
defer func() {
atomic.AddInt32(&outstandingHttpReqs, -1)
}()
r.ParseForm()
ids := r.Form.Get(":uuid")
id := uuid.Parse(ids)
if id == nil {
doError(w, "malformed uuid")
return
}
t, ok, msg := parseInt(r.Form.Get("time"), -(16 << 56), (48 << 56))
if !ok {
doError(w, "bad time: "+msg)
return
}
bws := r.Form.Get("backwards")
bw := bws != ""
rec, _, err := q.QueryNearestValue(id, t, bw, btrdb.LatestGeneration)
if err != nil {
doError(w, "Bad query: "+err.Error())
return
}
w.Write([]byte(fmt.Sprintf("[%d, %f]", rec.Time, rec.Val)))
}
示例9: parseRow
func parseRow(row connection.Row) (Record, error) {
r := Record{}
var rUUID, dUUID string
var rtID int32
var pID int32
var jsonBuf []byte
err := row.Scan(&rUUID, &dUUID, &r.Name, &jsonBuf, &rtID, &r.Date, &pID, &r.Added)
if err != nil {
return r, err
}
err = json.Unmarshal(jsonBuf, &r.Args)
if err != nil {
return r, err
}
r.UUID = uuid.Parse(rUUID)
r.Domain, err = domains.GetByUUID(dUUID).One()
if err != nil {
return r, err
}
r.Type, err = types.GetByID(rtID).One()
if err != nil {
return r, err
}
// ignore error as we dont need a Parser
p, _ := parser.Get(parser.GetByID(), pID)
r.Parser = p
return r, nil
}
示例10: getTestMessageWithFunnyFields
func getTestMessageWithFunnyFields() *message.Message {
field, _ := message.NewField(`"foo`, "bar\n", "")
field1, _ := message.NewField(`"number`, 64, "")
field2, _ := message.NewField("\xa3", "\xa3", "")
field3, _ := message.NewField("idField", "1234", "")
msg := &message.Message{}
msg.SetType("TEST")
loc, _ := time.LoadLocation("UTC")
t, _ := time.ParseInLocation("2006-01-02T15:04:05.000Z", "2013-07-16T15:49:05.070Z",
loc)
msg.SetTimestamp(t.UnixNano())
msg.SetUuid(uuid.Parse("87cf1ac2-e810-4ddf-a02d-a5ce44d13a85"))
msg.SetLogger("GoSpec")
msg.SetSeverity(int32(6))
msg.SetPayload("Test Payload")
msg.SetEnvVersion("0.8")
msg.SetPid(14098)
msg.SetHostname("hostname")
msg.AddField(field)
msg.AddField(field1)
msg.AddField(field2)
msg.AddField(field3)
return msg
}
示例11: handleNeighborUpdate
func (m *OpsConfigManager) handleNeighborUpdate(update ovsdb.TableUpdate) []*server.GrpcRequest {
_, id, _ := m.getBGPRouterUUID()
addrs, ids, err := m.getBGPNeighborUUIDs(id)
if err != nil {
return nil
}
reqs := make([]*server.GrpcRequest, 0, len(addrs))
for k, v := range update.Rows {
for idx, id := range ids {
if uuid.Equal(id, uuid.Parse(k)) {
asn, ok := v.New.Fields["remote_as"].(float64)
if !ok {
log.Debugf("remote-as is not configured yet")
continue
}
reqs = append(reqs, server.NewGrpcRequest(server.REQ_MOD_NEIGHBOR, "", bgp.RouteFamily(0), &api.ModNeighborArguments{
Operation: api.Operation_ADD,
Peer: &api.Peer{
Conf: &api.PeerConf{
NeighborAddress: addrs[idx].String(),
PeerAs: uint32(asn),
},
},
}))
}
}
}
return reqs
}
示例12: getBGPNeighborUUIDs
func (m *OpsConfigManager) getBGPNeighborUUIDs(id uuid.UUID) ([]net.IP, []uuid.UUID, error) {
global, ok := m.cache["BGP_Router"]
if !ok {
return nil, nil, fmt.Errorf("BGP_Router table not found")
}
for k, v := range global {
if uuid.Equal(id, uuid.Parse(k)) {
neighbors := v.Fields["bgp_neighbors"].(ovsdb.OvsMap).GoMap
if len(neighbors) < 1 {
return nil, nil, fmt.Errorf("no bgp neighbor configured")
}
addrs := make([]net.IP, 0, len(neighbors))
ids := make([]uuid.UUID, 0, len(neighbors))
for k, v := range neighbors {
addrs = append(addrs, net.ParseIP(k.(string)))
id := extractUUID(v)
if id == nil {
return nil, nil, fmt.Errorf("invalid uuid schema")
}
ids = append(ids, id)
}
return addrs, ids, nil
}
}
return nil, nil, fmt.Errorf("not found")
}
示例13: CreateAccelerations
func CreateAccelerations(userId string, accelerations types.AccelerationsRequest) error {
var err error
err = nil
if err = utilsservice.CheckIfUserExists(userId); err == nil {
for _, ar := range accelerations {
var a types.Acceleration
a.UserId = uuid.Parse(userId)
a.X = ar.X
a.Y = ar.Y
a.Z = ar.Z
if ar.Timestamp != 0 {
a.Timestamp = int64(time.Unix(ar.Timestamp, 0).UTC().Unix())
} else {
a.Timestamp = int64(time.Now().UTC().Unix())
}
err = accelerationRepo.CreateAcceleration(a)
if err != nil {
break
}
}
//increment walking progress for test users
if err == nil {
if user, errU := userservice.GetUser(userId); errU == nil {
if userExtraInfo, errU := userservice.GetUserExtraInfo(userId); errU == nil {
if userExtraInfo.WalkingProgress < 100 {
if user.IsTest {
var userExtraInfoRequest types.UserExtraInfoRequest
if userExtraInfo.WalkingProgress >= 95 {
userExtraInfoRequest.WalkingProgress = 100
} else {
userExtraInfoRequest.WalkingProgress = userExtraInfo.WalkingProgress + 3
}
if errU := userservice.UpdateUserExtraInfo(userId, userExtraInfoRequest); errU != nil {
log.Printf(fmt.Sprintf("AccelerationService.CreateAccelerations() - Error: %v", errU.Error()))
}
} else {
if accelerations != nil && len(accelerations) > 1 {
kafkaMessage := fmt.Sprintf("%v,%v,%v", userId, accelerations[0].Timestamp, accelerations[len(accelerations)-1].Timestamp)
kafkaservice.ProduceMessage(kafkaMessage)
}
}
}
} else {
log.Printf(fmt.Sprintf("AccelerationService.CreateAccelerations() - Error: %v", errU.Error()))
}
} else {
log.Printf(fmt.Sprintf("AccelerationService.CreateAccelerations() - Error: %v", errU.Error()))
}
}
}
return err
}
示例14: initdb
func initdb() {
if *showquery {
// don't need a database for printing queries
return
} else if *dbname == "" {
log.Fatal("must specify database with -db flag")
}
var err error
db, err = sql.Open("sqlite3", *dbname)
fatalif(err)
if *simidstr == "" {
ids, err := query.SimIds(db)
fatalif(err)
simid = ids[0]
} else {
simid = uuid.Parse(*simidstr)
if simid == nil {
log.Fatalf("invalid simid '%s'", *simidstr)
}
}
post.Process(db)
}
示例15: GetUser
func (repo *CassandraUserRepo) GetUser(userId string) (types.User, error) {
// get user by id
var user types.User
var user_id string
var err error
err = nil
sql := fmt.Sprintf(`SELECT user_id, username, facebook_access_token,
twitter_access_token, google_access_token, push_token,
device_type, email, password, is_test, is_anonymous, gender_preference,
timestamp FROM users WHERE user_id = %v LIMIT 1`, userId)
log.Printf(sql)
if err = session.Query(sql).Scan(&user_id,
&user.Username, &user.FacebookAccessToken, &user.TwitterAccessToken, &user.GoogleAccessToken,
&user.PushToken, &user.DeviceType, &user.Email,
&user.Password, &user.IsTest, &user.IsAnonymous, &user.GenderPreference, &user.Timestamp); err != nil {
log.Printf(fmt.Sprintf("CassandraUserRepo.GetUser() - Error: %v", err.Error()))
} else {
user.UserId = uuid.Parse(user_id)
}
return user, err
}