本文整理匯總了Golang中github.com/mshockwave/nthuaplus-backend/public.ResponseStatusAsJson函數的典型用法代碼示例。如果您正苦於以下問題:Golang ResponseStatusAsJson函數的具體用法?Golang ResponseStatusAsJson怎麽用?Golang ResponseStatusAsJson使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ResponseStatusAsJson函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleGMRecommsResend
func handleGMRecommsResend(resp http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
hash := vars["recommHash"]
appDb := public.GetNewApplicationDatabase()
defer appDb.Session.Close()
recomm := appDb.C(public.APPLICATION_DB_RECOMM_COLLECTION)
q := recomm.Find(bson.M{
"hash": hash,
})
recommObj := db.Recomm{}
if err := q.One(&recommObj); err != nil || len(hash) <= 0 {
public.ResponseStatusAsJson(resp, 404, &public.SimpleResult{
Message: "Error",
Description: "No Such page",
})
return
}
url := "https://application.nthuaplus.org/recomm.html?hash=" + hash
if e := public.SendMail(recommObj.Recommender.Email, recommObj.ApplyUser, url); e != nil {
public.LogE.Printf("Error sending email: %s\n", e.Error())
public.ResponseStatusAsJson(resp, 500, &public.SimpleResult{
Message: "Error",
})
} else {
public.ResponseOkAsJson(resp, nil)
}
}
示例2: removeStagingRecomm
func removeStagingRecomm(resp http.ResponseWriter, req *http.Request) {
user_id, _ := public.GetSessionUserId(req)
vars := mux.Vars(req)
hash := vars["hash"]
stagingDb := public.GetNewStagingDatabase()
defer stagingDb.Session.Close()
recomm := stagingDb.C(public.APPLICATION_DB_RECOMM_COLLECTION)
q := recomm.Find(bson.M{
"hash": hash,
"recommender": user_id,
})
recomm_result := db.RecommEntity{}
if e := q.One(&recomm_result); e != nil {
public.ResponseStatusAsJson(resp, 404, &public.SimpleResult{
Message: "No such recomm entry",
})
return
}
if e := recomm.RemoveId(recomm_result.Id); e != nil {
public.LogE.Printf("Remove recomm entity failed: %s\n", e.Error())
public.ResponseStatusAsJson(resp, 500, &public.SimpleResult{
Message: "Remove recomm failed",
})
} else {
public.ResponseOkAsJson(resp, nil)
}
}
示例3: gmMockWrapper
func gmMockWrapper(resp http.ResponseWriter, req *http.Request, handler http.HandlerFunc) {
email := req.URL.Query().Get("email")
if len(email) <= 0 {
public.ResponseStatusAsJson(resp, 400, &public.SimpleResult{
Message: "Error",
Description: "Need email",
})
return
}
userDb := public.GetNewUserDatabase()
defer userDb.Session.Close()
profiles := userDb.C(USER_DB_PROFILE_COLLECTION)
q := profiles.Find(bson.M{"email": email})
user := db.User{}
if e := q.One(&user); e != nil {
public.LogE.Printf("Get controlled user failed: %s\n", e.Error())
public.ResponseStatusAsJson(resp, 400, &public.SimpleResult{
Message: "Error",
Description: "Need email",
})
return
}
req.Header.Set(public.GM_PERMITTED_HEADER_KEY, user.Id.Hex())
handler(resp, req)
}
示例4: handleInspectStagingRecomm
func handleInspectStagingRecomm(resp http.ResponseWriter, req *http.Request) {
user_perm, _ := public.GetSessionUserPermission(req)
if !user_perm.ContainsPermission(public.USER_PERMISSION_RECOMM) {
public.ResponseStatusAsJson(resp, 403, &public.SimpleResult{
Message: "Not Recommender",
})
return
}
switch strings.ToLower(req.Method) {
case "get":
viewStagingRecomm(resp, req)
break
case "post":
editStagingRecomm(resp, req)
break
case "put":
editStagingRecomm(resp, req)
break
case "delete":
removeStagingRecomm(resp, req)
break
default:
public.ResponseStatusAsJson(resp, 404, &public.SimpleResult{
Message: "No such http method",
})
}
}
示例5: handleReviewLogin
func handleReviewLogin(resp http.ResponseWriter, req *http.Request) {
email := public.EmailFilter(req.FormValue("email"))
password := req.FormValue("password")
if len(email) <= 0 || len(password) <= 0 {
r := public.SimpleResult{
Message: "Error",
Description: "Incorrect email or password",
}
public.ResponseStatusAsJson(resp, 403, &r)
return
}
//Check login status
if _, err := public.GetSessionReviewerId(req); err == nil {
r := public.SimpleResult{
Message: "Already Login",
Description: email,
}
public.ResponseOkAsJson(resp, &r)
return
}
reviewerDb := public.GetNewReviewerDatabase()
defer reviewerDb.Session.Close()
profiles := reviewerDb.C(REVIEWER_DB_PROFILE_COLLECTION)
q := profiles.Find(bson.M{"baseprofile.email": email})
reviewer := db.Reviewer{}
if q.One(&reviewer) == nil {
//Check password
if bcrypt.CompareHashAndPassword([]byte(reviewer.BaseProfile.AuthInfo.BcyptHash), []byte(password)) != nil {
r := public.SimpleResult{
Message: "Error",
Description: "Incorrect email or password",
}
public.ResponseStatusAsJson(resp, 403, &r)
return
}
if err := public.SetReviewerSessionValue(req, resp, public.REVIEWER_ID_SESSION_KEY, reviewer.Id.Hex()); err != nil {
public.LogE.Printf("Error setting session user id: %s\n", err.Error())
}
r := public.SimpleResult{
Message: "Login Successed",
Description: email,
}
public.ResponseOkAsJson(resp, &r)
} else {
r := public.SimpleResult{
Message: "Error",
Description: "Incorrect email or password",
}
public.ResponseStatusAsJson(resp, 403, &r)
return
}
}
示例6: handleSubmitRecomm
func handleSubmitRecomm(resp http.ResponseWriter, req *http.Request) {
user_id, _ := public.GetSessionUserId(req)
user_perm, _ := public.GetSessionUserPermission(req)
vars := mux.Vars(req)
hash_str := vars["hash"]
stagingDb := public.GetNewStagingDatabase()
defer stagingDb.Session.Close()
staging_recomm := stagingDb.C(public.APPLICATION_DB_RECOMM_COLLECTION)
q := staging_recomm.Find(bson.M{
"hash": hash_str,
})
recomm_result := db.RecommEntity{}
if e := q.One(&recomm_result); e != nil {
public.ResponseStatusAsJson(resp, 404, &public.SimpleResult{
Message: "No such recomm entity",
})
return
}
// Permission check
if recomm_result.Recommender != user_id && user_perm != public.USER_PERMISSION_GM {
public.ResponseStatusAsJson(resp, 403, nil)
return
}
// Migrate from staging db to application db
staging_recomm.RemoveId(recomm_result.Id)
appDb := public.GetNewApplicationDatabase()
defer appDb.Session.Close()
recomm := appDb.C(public.APPLICATION_DB_RECOMM_COLLECTION)
new_recomm := recomm_result
new_recomm.Id = bson.NewObjectId()
new_recomm.LastModified = time.Now()
if e := recomm.Insert(new_recomm); e != nil {
public.LogE.Printf("Error migrating recomm from staging db to application db: %s\n", e.Error())
public.ResponseStatusAsJson(resp, 500, &public.SimpleResult{
Message: "Submit failed",
})
}
}
示例7: handleBulletinNotes
func handleBulletinNotes(resp http.ResponseWriter, req *http.Request) {
miscDb := public.GetNewMiscDatabase()
defer miscDb.Session.Close()
bulletin := miscDb.C(MISC_DB_BULLETIN_COLLECTION)
q := bulletin.Find(bson.M{})
if _, e := q.Count(); e != nil {
public.ResponseStatusAsJson(resp, 500, &public.SimpleResult{
Message: "Error",
Description: "Failed fetching bulletin notes",
})
return
}
var results []bulletinNoteResult
it := q.Iter()
result := db.BulletinNote{}
for it.Next(&result) {
results = append(results, bulletinNoteResult{
Title: result.Title,
Content: result.Content,
TimeStamp: result.TimeStamp,
})
}
public.ResponseOkAsJson(resp, &results)
}
示例8: editStagingRecomm
func editStagingRecomm(resp http.ResponseWriter, req *http.Request) {
user_id, _ := public.GetSessionUserId(req)
vars := mux.Vars(req)
hash := vars["hash"]
stagingDb := public.GetNewStagingDatabase()
defer stagingDb.Session.Close()
recomm := stagingDb.C(public.APPLICATION_DB_RECOMM_COLLECTION)
q := recomm.Find(bson.M{
"hash": hash,
"recommender": user_id,
})
recomm_result := db.RecommEntity{}
if e := q.One(&recomm_result); e != nil {
public.ResponseStatusAsJson(resp, 404, &public.SimpleResult{
Message: "No such recomm entry",
})
return
}
content := req.FormValue("content")
attachment := req.FormValue("attachment")
if len(content) > 0 {
recomm_result.Content = content
recomm_result.LastModified = time.Now()
}
if len(attachment) > 0 {
recomm_result.Attachment = public.FileStoragePath(attachment)
recomm_result.LastModified = time.Now()
}
if e := recomm.UpdateId(recomm_result.Id, &recomm_result); e != nil {
public.LogE.Printf("Update recomm entity failed: %s\n", e.Error())
public.ResponseStatusAsJson(resp, 500, &public.SimpleResult{
Message: "Update recomm failed",
})
} else {
public.ResponseOkAsJson(resp, nil)
}
}
示例9: handleViewRecomm
func handleViewRecomm(resp http.ResponseWriter, req *http.Request) {
user_id, _ := public.GetSessionUserId(req)
user_perm, _ := public.GetSessionUserPermission(req)
vars := mux.Vars(req)
hash_str := vars["hash"]
appDb := public.GetNewApplicationDatabase()
defer appDb.Session.Close()
recomm := appDb.C(public.APPLICATION_DB_RECOMM_COLLECTION)
q := recomm.Find(bson.M{
"hash": hash_str,
})
recomm_result := db.RecommEntity{}
if e := q.One(&recomm_result); e != nil {
public.ResponseStatusAsJson(resp, 404, &public.SimpleResult{
Message: "No such recomm entity",
})
return
}
// Permission check
if recomm_result.Recommender != user_id && user_perm != public.USER_PERMISSION_GM {
public.ResponseStatusAsJson(resp, 403, nil)
return
}
signed_url := ""
if client, err := storage.GetNewStorageClient(); err == nil {
expireTime := time.Now().Add(time.Duration(1) * time.Hour) //an hour
signed_url, _ = client.GetNewSignedURL(string(recomm_result.Attachment), expireTime)
}
public.ResponseOkAsJson(resp, &public.RecommView{
Hash: recomm_result.Hash,
ApplyUser: recomm_result.ApplyUser,
Topic: recomm_result.Topic,
LastModified: recomm_result.LastModified,
Content: recomm_result.Content,
Attachment: signed_url,
})
}
示例10: handleFormFileUpload
func handleFormFileUpload(resp http.ResponseWriter, req *http.Request) {
if f, h, e := req.FormFile("file"); e == nil && f != nil && h != nil {
if objName, err := saveFile(h, f); err == nil {
public.ResponseOkAsJson(resp, &public.SimpleResult{
Message: "Success",
Description: objName,
})
} else {
public.LogE.Printf("Error storing file: %s\n", err.Error())
public.ResponseStatusAsJson(resp, 400, &public.SimpleResult{
Message: "Error",
})
}
} else {
public.ResponseStatusAsJson(resp, 400, &public.SimpleResult{
Message: "Error",
})
}
}
示例11: handleQueryAccount
func handleQueryAccount(resp http.ResponseWriter, req *http.Request) {
email := req.URL.Query().Get("email")
if len(email) > 0 {
userDb := public.GetNewUserDatabase()
defer userDb.Session.Close()
profiles := userDb.C(USER_DB_PROFILE_COLLECTION)
q := profiles.Find(bson.M{"email": email})
user := db.User{}
if e := q.One(&user); e == nil {
//GM can get more information
public.ResponseOkAsJson(resp, &user)
} else {
public.ResponseStatusAsJson(resp, 404, nil)
}
} else {
public.ResponseStatusAsJson(resp, 404, nil)
}
}
示例12: handleRecommDoorBell
func handleRecommDoorBell(resp http.ResponseWriter, req *http.Request) {
_, user_err := public.GetSessionUserId(req)
if user_err != nil {
public.ResponseStatusAsJson(resp, 403, nil)
return
}
user_perm, _ := public.GetSessionUserPermission(req)
if !user_perm.ContainsPermission(public.USER_PERMISSION_RECOMM) {
public.ResponseStatusAsJson(resp, 403, &public.SimpleResult{
Message: "Not Recommender",
})
return
}
public.ResponseOkAsJson(resp, &public.SimpleResult{
Message: "Ok",
})
}
示例13: handleRecommFileUpload
func handleRecommFileUpload(resp http.ResponseWriter, req *http.Request) {
user_perm, _ := public.GetSessionUserPermission(req)
if user_perm.ContainsPermission(public.USER_PERMISSION_RECOMM) {
handleFormFileUpload(resp, req)
} else {
public.ResponseStatusAsJson(resp, 403, &public.SimpleResult{
Message: "Not Recommender",
})
}
}
示例14: handleReviewerLogout
func handleReviewerLogout(resp http.ResponseWriter, req *http.Request) {
if err := public.SetReviewerSessionValue(req, resp, public.REVIEWER_ID_SESSION_KEY, nil); err != nil {
public.LogE.Printf("Logout Failed: %s\n", err.Error())
public.ResponseStatusAsJson(resp, 500, &public.SimpleResult{
Message: "Error",
Description: "Logout Failed",
})
} else {
public.ResponseOkAsJson(resp, &public.SimpleResult{
Message: "Logout Success",
})
}
}
示例15: handleInspectRecomm
func handleInspectRecomm(resp http.ResponseWriter, req *http.Request) {
user_perm, _ := public.GetSessionUserPermission(req)
if !user_perm.ContainsPermission(public.USER_PERMISSION_RECOMM) {
public.ResponseStatusAsJson(resp, 403, &public.SimpleResult{
Message: "Not Recommender",
})
return
}
switch strings.ToLower(req.Method) {
case "get":
{
// View formal recommendation
handleViewRecomm(resp, req)
break
}
case "put":
{
// Submit as formal recommendation
handleSubmitRecomm(resp, req)
break
}
case "post":
{
// Submit as formal recommendation
handleSubmitRecomm(resp, req)
break
}
default:
public.ResponseStatusAsJson(resp, 404, &public.SimpleResult{
Message: "No such http method",
})
}
}