當前位置: 首頁>>代碼示例>>Golang>>正文


Golang RequestBundle.GetUsersByJoinDate方法代碼示例

本文整理匯總了Golang中get/2cloud/org/twocloud.RequestBundle.GetUsersByJoinDate方法的典型用法代碼示例。如果您正苦於以下問題:Golang RequestBundle.GetUsersByJoinDate方法的具體用法?Golang RequestBundle.GetUsersByJoinDate怎麽用?Golang RequestBundle.GetUsersByJoinDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在get/2cloud/org/twocloud.RequestBundle的用法示例。


在下文中一共展示了RequestBundle.GetUsersByJoinDate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getUsers

func getUsers(w http.ResponseWriter, r *twocloud.RequestBundle) {
	if !r.AuthUser.IsAdmin {
		Respond(w, r, http.StatusForbidden, "You don't have access to the user list.", []interface{}{})
		return
	}
	active_afterstr := r.Request.URL.Query().Get("active_after")
	active_beforestr := r.Request.URL.Query().Get("active_before")
	joined_afterstr := r.Request.URL.Query().Get("joined_after")
	joined_beforestr := r.Request.URL.Query().Get("joined_before")
	var joined_before, joined_after, active_before, active_after time.Time
	countstr := r.Request.URL.Query().Get("count")
	count := 20
	var err error
	if countstr != "" {
		count, err = strconv.Atoi(countstr)
		if err != nil {
			r.Log.Error(err.Error())
			Respond(w, r, http.StatusBadRequest, "Invalid count param.", []interface{}{})
			return
		}
	}
	if count > 100 {
		count = 100
	}
	if active_afterstr != "" {
		active_after, err = time.Parse(time.RFC3339, active_afterstr)
		if err != nil {
			r.Log.Error(err.Error())
			Respond(w, r, http.StatusBadRequest, "Invalid active_after value.", []interface{}{})
			return
		}
	}
	if active_beforestr != "" {
		active_before, err = time.Parse(time.RFC3339, active_beforestr)
		if err != nil {
			r.Log.Error(err.Error())
			Respond(w, r, http.StatusBadRequest, "Invalid active_before value.", []interface{}{})
			return
		}
	}
	if active_beforestr != "" || active_afterstr != "" {
		users, err := r.GetUsersByActivity(count, active_after, active_before)
		if err != nil {
			r.Log.Error(err.Error())
			Respond(w, r, http.StatusInternalServerError, "Internal server error.", []interface{}{})
			return
		}
		Respond(w, r, http.StatusOK, "Successfully retrieved a list of users", []interface{}{users})
		return
	}
	if joined_afterstr != "" {
		joined_after, err = time.Parse(time.RFC3339, joined_afterstr)
		if err != nil {
			r.Log.Error(err.Error())
			Respond(w, r, http.StatusBadRequest, "Invalid joined_after value.", []interface{}{})
			return
		}
	}
	if joined_beforestr != "" {
		joined_before, err = time.Parse(time.RFC3339, joined_beforestr)
		if err != nil {
			r.Log.Error(err.Error())
			Respond(w, r, http.StatusBadRequest, "Invalid joined_before value.", []interface{}{})
			return
		}
	}
	users, err := r.GetUsersByJoinDate(count, joined_after, joined_before)
	if err != nil {
		r.Log.Error(err.Error())
		Respond(w, r, http.StatusInternalServerError, "Internal server error.", []interface{}{users})
		return
	}
	Respond(w, r, http.StatusOK, "Successfully retrieved a list of users", []interface{}{users})
	return
}
開發者ID:2cloud,項目名稱:api,代碼行數:75,代碼來源:users.go


注:本文中的get/2cloud/org/twocloud.RequestBundle.GetUsersByJoinDate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。