本文整理汇总了Golang中github.com/satori/go/uuid.FromString函数的典型用法代码示例。如果您正苦于以下问题:Golang FromString函数的具体用法?Golang FromString怎么用?Golang FromString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FromString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSubscription
func TestSubscription(t *testing.T) {
var s Subscription
var sJSON = []byte(`
{
"id": "5b2e1b6f-b3f7-4a94-8b05-aa441606d886",
"event_type": "test_event_type",
"context": "test_context",
"account_id": "e4f05126-a0e8-437d-94f9-b553c959cdfb",
"timestamp": "2015-07-10T10:50:34.437512Z"
}`)
if err := json.Unmarshal(sJSON, &s); err != nil {
t.Error(err.Error())
}
sAccountID, _ := uuid.FromString("e4f05126-a0e8-437d-94f9-b553c959cdfb")
sID, _ := uuid.FromString("5b2e1b6f-b3f7-4a94-8b05-aa441606d886")
sTime, _ := time.Parse(time.RFC3339, "2015-07-10T10:50:34.437512Z")
cases := []struct {
label, actual, expected interface{}
}{
{"id", s.ID, sID},
{"event type", s.EventType, "test_event_type"},
{"context", s.Context, "test_context"},
{"account id", s.AccountID, sAccountID},
{"created at date", s.CreatedAt, sTime},
}
for _, c := range cases {
if c.actual != c.expected {
t.Errorf("Subscriber %v is %q, but expected %q", c.label, c.actual, c.expected)
}
}
}
示例2: updateRecordWithUserId
func updateRecordWithUserId(input interface{}, fieldNames map[string]bool, id, userId string, session *xorm.Session) (statusCode int, err error) {
if _, err := uuid.FromString(id); err != nil {
return http.StatusBadRequest, errUuidNotValid
}
if _, err := uuid.FromString(userId); err != nil {
return http.StatusBadRequest, errUuidNotValid
}
//convert the fields set to array
array := []string{}
for k, _ := range fieldNames {
array = append(array, k)
}
//update the database
affected, err := session.Where("id = ? and user_id = ?", id, userId).Cols(array...).Update(input)
if err != nil {
return http.StatusInternalServerError, err
}
if affected == 0 {
return http.StatusNotFound, errors.New("The record is not found.")
}
return http.StatusNoContent, nil
}
示例3: PutOAuthUser
func PutOAuthUser(mdb *Store, u *pb.OAuthUser) (*pb.OAuthUser, error) {
key, v, err := GetOAuthUser(mdb, u.Provider, u.UserId)
if err != nil {
return nil, err
}
if v != nil {
if u.Uuid != "" && v.Uuid != "" {
uuid1, _ := uuid.FromString(u.Uuid)
uuid2, _ := uuid.FromString(v.Uuid)
if !uuid.Equal(uuid1, uuid2) {
return nil, fmt.Errorf("user mismatch")
}
}
if u.Uuid == "" {
u.Uuid = v.Uuid
}
}
bytes, err := proto.Marshal(u)
if err != nil {
return nil, err
}
// refresh OAuth User info to store
err = mdb.Put(key.Bytes(), bytes)
if err != nil {
return nil, err
}
return u, nil
}
示例4: TestMysqlGTIDSync
func (t *testSyncerSuite) TestMysqlGTIDSync(c *C) {
t.setupTest(c, mysql.MySQLFlavor)
r, err := t.c.Execute("SELECT @@gtid_mode")
c.Assert(err, IsNil)
modeOn, _ := r.GetString(0, 0)
if modeOn != "ON" {
c.Skip("GTID mode is not ON")
}
r, err = t.c.Execute("SHOW GLOBAL VARIABLES LIKE 'SERVER_UUID'")
c.Assert(err, IsNil)
var masterUuid uuid.UUID
if s, _ := r.GetString(0, 1); len(s) > 0 && s != "NONE" {
masterUuid, err = uuid.FromString(s)
c.Assert(err, IsNil)
}
set, _ := mysql.ParseMysqlGTIDSet(fmt.Sprintf("%s:%d-%d", masterUuid.String(), 1, 2))
s, err := t.b.StartSyncGTID(set)
c.Assert(err, IsNil)
t.testSync(c, s)
}
示例5: toID
func toID(param string) uuid.UUID {
val, err := uuid.FromString(param)
if err != nil {
log.Fatal(err)
}
return val
}
示例6: TestUUIDFlakeKey
func TestUUIDFlakeKey(t *testing.T) {
Convey("Giving key, convert to bytes", t, func() {
id, err := uuid.FromString("c6f8dca8-54f0-11dd-b489-003048343a40")
So(err, ShouldBeNil)
So(hex.EncodeToString(id.Bytes()), ShouldEqual, hex.EncodeToString(id[:16][:]))
fid := flake.Id{}
suffix := hex.EncodeToString(fid[:])
key := NewUUIDFlakeKey(TableFeed, id, fid)
So(key.Len(), ShouldEqual, 36)
uid := "c6f8dca854f011ddb489003048343a40"
So(key.String(), ShouldEqual, "00000001"+uid+suffix)
So(hex.EncodeToString(key.Prefix().Bytes()), ShouldEqual, "00000001"+uid)
So(string(key.Prefix().Bytes()), ShouldEqual, string(key.UUIDKey.Bytes()))
key.UUIDKey.PrefixTable = TableFeedinfo
So(key.String(), ShouldEqual, "00000002"+uid+suffix)
So(hex.EncodeToString(key.Prefix().Bytes()), ShouldEqual, "00000002"+uid)
key.Id[15] = 1
suffix = hex.EncodeToString(key.Id[:])
So(key.String(), ShouldEqual, "00000002"+uid+suffix)
So(hex.EncodeToString(key.Prefix().Bytes()), ShouldEqual, "00000002"+uid)
})
}
示例7: FetchProfile
func (s *ApiServer) FetchProfile(ctx context.Context, req *pb.ProfileRequest) (*pb.Profile, error) {
uuid1, err := uuid.FromString(req.Uuid)
if err != nil {
return nil, err
}
return store.GetProfileFromUuid(s.mdb, uuid1)
}
示例8: NewWorker
// Creates new instance of Worker. Returns error on fail.
func NewWorker() (worker *Worker, err error) {
sock, err := newAsyncRWSocket("unix", flagEndpoint, time.Second*5)
if err != nil {
return
}
logger, err := NewLogger()
if err != nil {
return
}
workerID, _ := uuid.FromString(flagUUID)
disown_timeout := 5 * time.Second
w := Worker{
unpacker: newStreamUnpacker(),
uuid: workerID,
logger: logger,
heartbeat_timer: time.NewTimer(HEARTBEAT_TIMEOUT),
disown_timer: time.NewTimer(disown_timeout),
sessions: make(map[int64](*Request)),
from_handlers: make(chan rawMessage),
socketIO: sock,
fallback: defaultFallbackHandler,
disown_timeout: disown_timeout,
}
w.disown_timer.Stop()
w.handshake()
w.heartbeat()
worker = &w
return
}
示例9: Decode
// Decode decodes a string according to the alphabet into a uuid.UUID. If s is
// too short, its most significant bits (MSB) will be padded with 0 (zero).
func (b base57) Decode(u string) (uuid.UUID, error) {
str, err := b.stringToNum(u)
if err != nil {
return uuid.Nil, err
}
return uuid.FromString(str)
}
示例10: LikeEntry
func (s *ApiServer) LikeEntry(ctx context.Context, req *pb.LikeRequest) (*pb.Entry, error) {
entry, err := store.GetEntry(s.rdb, req.Entry)
if err != nil {
return nil, err
}
uuid1, err := uuid.FromString(req.User)
if err != nil {
return nil, err
}
profile, err := store.GetProfileFromUuid(s.mdb, uuid1)
if err != nil || profile == nil {
return nil, err
}
if req.Like {
var key *store.UUIDKey
key, entry, err = store.Like(s.rdb, profile, entry)
if err == nil {
s.spread(key)
}
} else {
entry, err = store.DeleteLike(s.rdb, profile, entry)
}
return entry, err
}
示例11: Delete
// Delete deletes the work item link category with the given id
// returns NotFoundError or InternalError
func (r *GormWorkItemLinkCategoryRepository) Delete(ctx context.Context, ID string) error {
id, err := satoriuuid.FromString(ID)
if err != nil {
// treat as not found: clients don't know it must be a UUID
return errors.NewNotFoundError("work item link category", ID)
}
var cat = WorkItemLinkCategory{
ID: id,
}
log.Info(ctx, map[string]interface{}{
"pkg": "link",
"wilcID": ID,
}, "Work item link category to delete")
db := r.db.Delete(&cat)
if db.Error != nil {
return errors.NewInternalError(db.Error.Error())
}
if db.RowsAffected == 0 {
return errors.NewNotFoundError("work item link category", id.String())
}
return nil
}
示例12: List
// List runs the list action.
func (c *SpaceIterationsController) List(ctx *app.ListSpaceIterationsContext) error {
spaceID, err := uuid.FromString(ctx.ID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
}
return application.Transactional(c.db, func(appl application.Application) error {
_, err = appl.Spaces().Load(ctx, spaceID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
}
iterations, err := appl.Iterations().List(ctx, spaceID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
// fetch extra information(counts of WI in each iteration of the space) to be added in response
wiCounts, err := appl.WorkItems().GetCountsPerIteration(ctx, spaceID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
res := &app.IterationList{}
res.Data = ConvertIterations(ctx.RequestData, iterations, UpdateIterationsWithCounts(wiCounts))
return ctx.OK(res)
})
}
示例13: Load
// Load returns the work item link type for the given ID.
// Returns NotFoundError, ConversionError or InternalError
func (r *GormWorkItemLinkTypeRepository) Load(ctx context.Context, ID string) (*app.WorkItemLinkTypeSingle, error) {
id, err := satoriuuid.FromString(ID)
if err != nil {
// treat as not found: clients don't know it must be a UUID
return nil, errors.NewNotFoundError("work item link type", ID)
}
log.Info(ctx, map[string]interface{}{
"pkg": "link",
"wiltID": ID,
}, "Loading work item link type")
res := WorkItemLinkType{}
db := r.db.Model(&res).Where("id=?", ID).First(&res)
if db.RecordNotFound() {
log.Error(ctx, map[string]interface{}{
"wiltID": ID,
}, "work item link type not found")
return nil, errors.NewNotFoundError("work item link type", id.String())
}
if db.Error != nil {
return nil, errors.NewInternalError(db.Error.Error())
}
// Convert the created link type entry into a JSONAPI response
result := ConvertLinkTypeFromModel(res)
return &result, nil
}
示例14: Extract
func (mgm tokenManager) Extract(tokenString string) (*account.Identity, error) {
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
return mgm.publicKey, nil
})
if err != nil {
return nil, errors.WithStack(err)
}
if !token.Valid {
return nil, errors.New("Token not valid")
}
claimedUUID := token.Claims.(jwt.MapClaims)["sub"]
if claimedUUID == nil {
return nil, errors.New("Subject can not be nil")
}
// in case of nil UUID, below type casting will fail hence we need above check
id, err := uuid.FromString(token.Claims.(jwt.MapClaims)["sub"].(string))
if err != nil {
return nil, errors.WithStack(err)
}
ident := account.Identity{
ID: id,
Username: token.Claims.(jwt.MapClaims)["preferred_username"].(string),
}
return &ident, nil
}
示例15: Delete
// Delete deletes the work item link with the given id
// returns NotFoundError or InternalError
func (r *GormWorkItemLinkRepository) Delete(ctx context.Context, ID string) error {
id, err := satoriuuid.FromString(ID)
if err != nil {
// treat as not found: clients don't know it must be a UUID
return errors.NewNotFoundError("work item link", ID)
}
var link = WorkItemLink{
ID: id,
}
log.Info(ctx, map[string]interface{}{
"pkg": "link",
"wilID": ID,
}, "Deleting the work item link repository")
db := r.db.Delete(&link)
if db.Error != nil {
log.Error(ctx, map[string]interface{}{
"wilID": ID,
"err": db.Error,
}, "unable to delete work item link repository")
return errors.NewInternalError(db.Error.Error())
}
if db.RowsAffected == 0 {
return errors.NewNotFoundError("work item link", id.String())
}
return nil
}