本文整理汇总了Golang中mig/ninja/mig.Investigator.Status方法的典型用法代码示例。如果您正苦于以下问题:Golang Investigator.Status方法的具体用法?Golang Investigator.Status怎么用?Golang Investigator.Status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mig/ninja/mig.Investigator
的用法示例。
在下文中一共展示了Investigator.Status方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateInvestigator
// updateInvestigator updates the status of an investigator in database
func updateInvestigator(respWriter http.ResponseWriter, request *http.Request) {
var err error
opid := getOpID(request)
loc := fmt.Sprintf("%s%s", ctx.Server.Host, request.URL.String())
resource := cljs.New(loc)
defer func() {
if e := recover(); e != nil {
emsg := fmt.Sprintf("%v", e)
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: emsg}.Err()
resource.SetError(cljs.Error{Code: fmt.Sprintf("%.0f", opid), Message: emsg})
respond(500, resource, respWriter, request)
}
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: "leaving updateInvestigator()"}.Debug()
}()
var inv mig.Investigator
err = request.ParseForm()
if err != nil {
panic(err)
}
iid := request.FormValue("id")
if iid == "" {
panic("Investigator ID must not be empty")
}
inv.ID, err = strconv.ParseFloat(iid, 64)
if err != nil {
panic(err)
}
inv.Status = request.FormValue("status")
if inv.Status == "" {
panic("Investigator status must not be empty")
}
// create the investigator in database
err = ctx.DB.UpdateInvestigatorStatus(inv)
if err != nil {
panic(err)
}
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: fmt.Sprintf("Investigator %.0f status changed to %s", inv.ID, inv.Status)}
err = resource.AddItem(cljs.Item{
Href: fmt.Sprintf("%s/investigator?investigatorid=%.0f", ctx.Server.BaseURL, inv.ID),
Data: []cljs.Data{{Name: "Investigator ID " + fmt.Sprintf("%.0f", inv.ID), Value: inv}},
})
respond(200, resource, respWriter, request)
}
示例2: updateInvestigator
// updateInvestigator updates the status of an investigator in database
func updateInvestigator(respWriter http.ResponseWriter, request *http.Request) {
var err error
opid := getOpID(request)
loc := fmt.Sprintf("%s%s", ctx.Server.Host, request.URL.String())
resource := cljs.New(loc)
defer func() {
if e := recover(); e != nil {
emsg := fmt.Sprintf("%v", e)
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: emsg}.Err()
resource.SetError(cljs.Error{Code: fmt.Sprintf("%.0f", opid), Message: emsg})
respond(http.StatusInternalServerError, resource, respWriter, request)
}
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: "leaving updateInvestigator()"}.Debug()
}()
var inv mig.Investigator
err = request.ParseForm()
if err != nil {
panic(err)
}
iid := request.FormValue("id")
if iid == "" {
panic("Investigator ID must not be empty")
}
inv.ID, err = strconv.ParseFloat(iid, 64)
if err != nil {
panic(err)
}
inv.Status = request.FormValue("status")
isadm := request.FormValue("isadmin")
if inv.Status == "" && isadm == "" {
panic("No updates to the investigator were specified")
}
if inv.Status != "" {
// update the investigator status in database
err = ctx.DB.UpdateInvestigatorStatus(inv)
if err != nil {
panic(err)
}
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: fmt.Sprintf("Investigator %.0f status changed to %s", inv.ID, inv.Status)}
} else {
switch isadm {
case "true":
inv.IsAdmin = true
case "false":
inv.IsAdmin = false
// If the request is to disable the admin flag, make sure we
// are not disabling the only remaining admin
var cnt int
cnt, err = ctx.DB.CountOtherAdminInvestigators(inv)
if err != nil {
panic(err)
}
if cnt < 1 {
resource.SetError(cljs.Error{
Code: fmt.Sprintf("%.0f", opid),
Message: "Will not disable last remaining administrator"})
respond(http.StatusBadRequest, resource, respWriter, request)
return
}
default:
panic("invalid value for isadmin")
}
err = ctx.DB.UpdateInvestigatorAdmin(inv)
if err != nil {
panic(err)
}
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: fmt.Sprintf("Investigator %.0f admin changed to %v", inv.ID, inv.IsAdmin)}
}
err = resource.AddItem(cljs.Item{
Href: fmt.Sprintf("%s/investigator?investigatorid=%.0f", ctx.Server.BaseURL, inv.ID),
Data: []cljs.Data{{Name: "Investigator ID " + fmt.Sprintf("%.0f", inv.ID), Value: inv}},
})
respond(http.StatusOK, resource, respWriter, request)
}