本文整理匯總了Golang中github.com/elos/data.DB.NewID方法的典型用法代碼示例。如果您正苦於以下問題:Golang DB.NewID方法的具體用法?Golang DB.NewID怎麽用?Golang DB.NewID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/elos/data.DB
的用法示例。
在下文中一共展示了DB.NewID方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createFixture
func createFixture(ui cli.Ui, ownerID string, db data.DB) (fixture *models.Fixture, err error) {
ui.Output("Creating a fixture")
fixture = models.NewFixture()
fixture.SetID(db.NewID())
fixture.OwnerId = ownerID
fixture.CreatedAt = time.Now()
if fixture.Name, err = stringInput(ui, "Name of the fixture:"); err != nil {
return
}
if fixture.Label, err = boolInput(ui, "Is this a label?"); err != nil {
return
}
if !fixture.Label {
if fixture.StartTime, err = timeInput(ui, "Start time of fixture?"); err != nil {
return
}
if fixture.EndTime, err = timeInput(ui, "End time of fixture?"); err != nil {
return
}
}
fixture.UpdatedAt = time.Now()
err = db.Save(fixture)
return
}
示例2: newTestUserX
func newTestUserX(t *testing.T, db data.DB) *models.User {
u := new(models.User)
u.SetID(db.NewID())
if err := db.Save(u); err != nil {
t.Fatalf("Error newTestUserX: %s", err)
}
return u
}
示例3: newTestCalendar
func newTestCalendar(t *testing.T, db olddata.DB, u *oldmodels.User) *oldmodels.Calendar {
c := oldmodels.NewCalendar()
c.SetID(db.NewID())
c.SetOwner(u)
c.CreatedAt = time.Now()
c.UpdatedAt = c.CreatedAt
return c
}
示例4: newTestUser
func newTestUser(t *testing.T, db data.DB) *oldmodels.User {
u := oldmodels.NewUser()
u.SetID(db.NewID())
u.CreatedAt = time.Now()
u.UpdatedAt = time.Now()
if err := db.Save(u); err != nil {
t.Fatalf("Error newTestUser: %s", err)
}
return u
}
示例5: newTestTag
func newTestTag(t *testing.T, db data.DB, u *models.User) *models.Tag {
tg := models.NewTag()
tg.SetID(db.NewID())
tg.SetOwner(u)
if err := db.Save(tg); err != nil {
t.Fatal(err)
}
return tg
}
示例6: newTestTask
func newTestTask(t *testing.T, db data.DB, u *models.User) *models.Task {
tsk := new(models.Task)
tsk.SetID(db.NewID())
tsk.CreatedAt = models.TimestampFrom(time.Now())
tsk.OwnerId = u.ID().String()
tsk.UpdatedAt = models.TimestampFrom(time.Now())
if err := db.Save(tsk); err != nil {
t.Fatalf("Error newTestTask: %s", err)
}
return tsk
}
示例7: newTestNote
func newTestNote(t *testing.T, db data.DB, u *models.User) *models.Note {
note := models.NewNote()
note.SetID(db.NewID())
note.CreatedAt = time.Now()
note.OwnerId = u.ID().String()
note.UpdatedAt = time.Now()
if err := db.Save(note); err != nil {
t.Fatal("newTestNote Error: %s", err)
}
return note
}
示例8: newTestPerson
func newTestPerson(t *testing.T, db data.DB, u *models.User) *models.Person {
person := models.NewPerson()
person.SetID(db.NewID())
person.CreatedAt = time.Now()
person.OwnerId = u.ID().String()
person.UpdatedAt = time.Now()
if err := db.Save(person); err != nil {
t.Fatalf("newTestPerson Error: %s", err)
}
return person
}
示例9: newCalendar
func newCalendar(db data.DB, userID string) (*models.Calendar, error) {
cal := models.NewCalendar()
cal.SetID(db.NewID())
cal.CreatedAt = time.Now()
cal.Name = "Main"
cal.OwnerId = userID
cal.UpdatedAt = time.Now()
return cal, db.Save(cal)
}
示例10: locationUpdate
func locationUpdate(db data.DB, u *models.User, e *models.Event) {
loc, _ := e.Location(db)
p, err := user.Profile(db, u)
if err == data.ErrNotFound {
p = models.NewProfile()
p.CreatedAt = time.Now()
p.UpdatedAt = p.CreatedAt
p.SetID(db.NewID())
p.SetOwner(u)
}
p.SetLocation(loc)
db.Save(p)
}
示例11: MobileLocationPOST
func MobileLocationPOST(ctx context.Context, w http.ResponseWriter, r *http.Request, l services.Logger, db data.DB) {
// Parse the form value
if err := r.ParseForm(); err != nil {
l.Printf("MobileLocationPOST Error: %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
// Altitude
alt := r.FormValue(altitudeParam)
if alt == "" {
http.Error(w, "You must specify an altitude", http.StatusBadRequest)
return
}
altitude, err := strconv.ParseFloat(alt, 64)
if err != nil {
http.Error(w, "Parsing altitude", http.StatusBadRequest)
return
}
// Latitude
lat := r.FormValue(latitudeParam)
if lat == "" {
http.Error(w, "You must specify a latitude", http.StatusBadRequest)
return
}
latitude, err := strconv.ParseFloat(lat, 64)
if err != nil {
http.Error(w, "Parsing latitude", http.StatusBadRequest)
return
}
// Longitude
lon := r.FormValue(longitudeParam)
if lon == "" {
http.Error(w, "You must specify an longitude", http.StatusBadRequest)
return
}
longitude, err := strconv.ParseFloat(lon, 64)
if err != nil {
http.Error(w, "Parsing longitude", http.StatusBadRequest)
return
}
// Retrieve the user this request was authenticated as
u, ok := user.FromContext(ctx)
if !ok { // This is certainly an issue, and should _never_ happen
l.Print("MobileLocationPOST Error: failed to retrieve user from context")
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
// Create location
loc := location.NewCoords(altitude, latitude, longitude)
loc.SetID(db.NewID())
loc.SetOwner(u)
now := loc.CreatedAt
e := models.NewEvent()
e.CreatedAt = now
e.SetID(db.NewID())
e.SetOwner(u)
e.Name = "Location Update"
e.SetLocation(loc)
e.Time = now
e.UpdatedAt = now
locationTag, err1 := tag.ForName(db, u, tag.Location)
updateTag, err2 := tag.ForName(db, u, tag.Update)
mobileTag, err3 := tag.ForName(db, u, tag.Mobile)
if err1 != nil || err2 != nil || err3 != nil {
l.Printf("MobileLocationPOST Error: %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
e.IncludeTag(locationTag)
e.IncludeTag(updateTag)
e.IncludeTag(mobileTag)
if err = db.Save(loc); err != nil {
l.Printf("MobileLocationPOST Error: %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if err = db.Save(e); err != nil {
l.Printf("MobileLocationPOST Error: %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
bytes, err := json.MarshalIndent(e, "", " ")
if err != nil {
l.Printf("MobileLocationPOST Error: while marshalling json %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusCreated)
//.........這裏部分代碼省略.........