本文整理匯總了Golang中github.com/raphaelm/backupd/backupd/datastore.DataStore.Job方法的典型用法代碼示例。如果您正苦於以下問題:Golang DataStore.Job方法的具體用法?Golang DataStore.Job怎麽用?Golang DataStore.Job使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/raphaelm/backupd/backupd/datastore.DataStore
的用法示例。
在下文中一共展示了DataStore.Job方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: JobDelete
func JobDelete(store datastore.DataStore, w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id, err := strconv.Atoi(vars["id"])
if err != nil {
w.Write([]byte(fmt.Sprintf("Error: %s", err)))
w.WriteHeader(http.StatusBadRequest)
return
}
obj, err := store.Job(int64(id))
if obj.ID == 0 || err != nil {
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(fmt.Sprintf("Error: %s", err)))
return
}
deleted, err := store.DeleteJob(&obj)
if !deleted || err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("Error: %s", err)))
return
}
w.WriteHeader(http.StatusOK)
}
示例2: testJobs
func testJobs(s datastore.DataStore, t *testing.T) {
// Test only valid RemoteIDs are accepted
j := model.Job{JobName: "foo", RemoteID: 0}
created, err := s.SaveJob(&j)
assert.NotNil(t, err)
r := model.Remote{Driver: "ssh", Location: "foo"}
created, err = s.SaveRemote(&r)
r2 := model.Remote{Driver: "ssh", Location: "bar"}
created, err = s.SaveRemote(&r2)
j = model.Job{JobName: "foo", RemoteID: r.ID}
created, err = s.SaveJob(&j)
assert.Equal(t, true, created)
assert.Nil(t, err)
j2, err := s.Job(j.ID)
assert.Nil(t, err)
assert.Equal(t, j.JobName, j2.JobName)
assert.Equal(t, j.ID, j2.ID)
j2.JobName = "bar"
created, err = s.SaveJob(&j2)
assert.Equal(t, false, created)
assert.Nil(t, err)
jslice, err := s.Jobs()
assert.Nil(t, err)
assert.Equal(t, 1, len(jslice))
assert.Equal(t, j2.JobName, jslice[0].JobName)
assert.Equal(t, j2.ID, jslice[0].ID)
jslice, err = s.JobsForRemote(&r)
assert.Nil(t, err)
assert.Equal(t, 1, len(jslice))
jslice, err = s.JobsForRemote(&r2)
assert.Nil(t, err)
assert.Equal(t, 0, len(jslice))
s.DeleteJob(&j2)
jslice, err = s.Jobs()
assert.Nil(t, err)
assert.Equal(t, 0, len(jslice))
_, err = s.Job(j.ID)
assert.NotNil(t, err)
s.DeleteRemote(&r)
s.DeleteRemote(&r2)
}
示例3: JobUpdate
func JobUpdate(store datastore.DataStore, w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
body, err := ioutil.ReadAll(r.Body)
if err != nil {
fmt.Printf("Error: %s\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
id, err := strconv.Atoi(vars["id"])
if err != nil {
w.Write([]byte(fmt.Sprintf("Error: %s", err)))
w.WriteHeader(http.StatusBadRequest)
return
}
obj, err := store.Job(int64(id))
if obj.ID == 0 || err != nil {
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(fmt.Sprintf("Error: %s", err)))
return
}
oldid := obj.ID
err = json.Unmarshal(body, &obj)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(fmt.Sprintf("Error: %s", err)))
return
}
if obj.ID != oldid {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("Error: You cannot change an ID"))
return
}
_, err = store.SaveJob(&obj)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("Error: %s", err)))
return
}
w.WriteHeader(http.StatusOK)
}