本文整理匯總了Golang中github.com/MG-RAST/Shock/goweb.Context.RespondWithOK方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.RespondWithOK方法的具體用法?Golang Context.RespondWithOK怎麽用?Golang Context.RespondWithOK使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MG-RAST/Shock/goweb.Context
的用法示例。
在下文中一共展示了Context.RespondWithOK方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Update
// PUT: /node/{id} -> multipart-form
func (cr *NodeController) Update(id string, cx *goweb.Context) {
// Log Request and check for Auth
LogRequest(cx.Request)
u, err := AuthenticateRequest(cx.Request)
if err != nil {
// No Auth is not damning. Other errors are probably a dead db connection
if err.Error() != e.NoAuth {
if err.Error() == e.MongoDocNotFound {
cx.RespondWithErrorMessage("Invalid username or password", http.StatusBadRequest)
return
} else {
fmt.Println("Error at Auth:", err.Error())
cx.RespondWithError(http.StatusInternalServerError)
return
}
}
}
// Gather query params
query := &Query{list: cx.Request.URL.Query()}
// Fake public user
if u == nil {
u = &user.User{Uuid: ""}
}
node, err := store.LoadNode(id, u.Uuid)
if err != nil {
if err.Error() == e.UnAuth {
fmt.Println("Unauthorized")
cx.RespondWithError(http.StatusUnauthorized)
return
} else if err.Error() == e.MongoDocNotFound {
cx.RespondWithNotFound()
return
} else {
// In theory the db connection could be lost between
// checking user and load but seems unlikely.
fmt.Println("[email protected]_Update:LoadNode:", err.Error())
cx.RespondWithError(http.StatusInternalServerError)
return
}
}
if query.Has("index") {
if !node.HasFile() {
cx.RespondWithErrorMessage("node file empty", http.StatusBadRequest)
return
}
newIndexer := indexer.Indexer(query.Value("index"))
f, _ := os.Open(node.DataPath())
defer f.Close()
idxer := newIndexer(f)
err := idxer.Create()
if err != nil {
fmt.Println(err.Error())
}
err = idxer.Dump(node.IndexPath() + "/record")
if err != nil {
cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
return
} else {
cx.RespondWithOK()
return
}
} else {
params, files, err := ParseMultipartForm(cx.Request)
if err != nil {
fmt.Println("err", err.Error())
cx.RespondWithError(http.StatusBadRequest)
return
}
err = node.Update(params, files)
if err != nil {
errors := []string{"node file already set and is immutable", "node file immutable", "node attributes immutable", "node part already exists and is immutable"}
for e := range errors {
if err.Error() == errors[e] {
cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
return
}
}
fmt.Println("err", err.Error())
cx.RespondWithError(http.StatusBadRequest)
return
}
cx.RespondWithData(node)
}
return
}