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


Golang response.ServerError函數代碼示例

本文整理匯總了Golang中github.com/bbhmakerlab/openinnovation/response.ServerError函數的典型用法代碼示例。如果您正苦於以下問題:Golang ServerError函數的具體用法?Golang ServerError怎麽用?Golang ServerError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: UpdateTask

func UpdateTask(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser

	projectID := parser.Int(r.FormValue("projectID"))
	if parser.Err != nil {
		response.ServerError(w, parser.Err)
		return
	}

	user := context.Get(r, "user").(store.User)
	if !user.IsMember(projectID) {
		response.ClientError(w, http.StatusForbidden)
		return
	}

	var taskID int64
	if err := store.UpdateTask(store.UpdateTaskParams{
		TaskID:      r.FormValue("taskID"),
		Title:       r.FormValue("title"),
		Description: r.FormValue("description"),
		Tags:        r.Form["tags"],
		StartDate:   r.FormValue("startDate"),
		EndDate:     r.FormValue("endDate"),
	}); err != nil {
		response.ServerError(w, err)
		return
	}

	response.OK(w, taskID)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:30,代碼來源:task.go

示例2: Update

func Update(w http.ResponseWriter, r *http.Request) {
	err := r.ParseForm()
	if err != nil {
		response.ServerError(w, err)
		return
	}

	user := context.Get(r, "user").(store.User)

	for k, v := range r.Form {
		switch k {
		case "fullname":
			err = user.UpdateFullname(v[0])
		case "title":
			err = user.UpdateTitle(v[0])
		case "description":
			err = user.UpdateDescription(v[0])
		case "interests":
			err = user.UpdateInterests(strings.Split(v[0], ","))
		}

		if err != nil {
			response.ServerError(w, err)
			return
		}
	}

	response.OK(w, nil)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:29,代碼來源:user.go

示例3: SetFeaturedProject

func SetFeaturedProject(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser

	const existSQL = `
	SELECT COUNT(*) FROM featured_project
	WHERE project_id = $1`

	projectID := parser.Int(r.FormValue("projectID"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	if exists, err := store.Exists(existSQL, projectID); err != nil {
		response.ServerError(w, err)
		return
	} else if exists {
		response.OK(w, nil)
		return
	}

	if err := store.SetFeaturedProject(projectID); err != nil {
		response.ServerError(w, err)
	}

	response.OK(w, nil)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:27,代碼來源:project.go

示例4: RemoveMember

func RemoveMember(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser

	projectID := parser.Int(r.FormValue("projectID"))
	userID := parser.Int(r.FormValue("userID"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	user := context.Get(r, "user").(store.User)
	if user.ID() != userID {
		response.ClientError(w, http.StatusForbidden)
		return
	}

	if exists, err := store.MemberExists(projectID, userID); err != nil {
		response.ServerError(w, err)
		return
	} else if !exists {
		response.OK(w, nil)
		return
	}

	if err := store.RemoveMember(projectID, userID); err != nil {
		response.ServerError(w, err)
		return
	}

	response.OK(w, nil)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:31,代碼來源:member.go

示例5: GetChats

func GetChats(w http.ResponseWriter, r *http.Request) {
	if err := r.ParseForm(); err != nil {
		response.ServerError(w, err)
		return
	}

	var parser store.Parser
	var startID int64
	var count int64 = 10

	if v, ok := r.Form["count"]; ok {
		count = parser.Int(v[0])
	}

	if v, ok := r.Form["startID"]; ok {
		startID = parser.Int(v[0])
	}

	channelID := parser.Int(r.FormValue("channelID"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}
	channelType := r.FormValue("channelType")

	user := context.Get(r, "user").(store.User)
	chats, err := store.GetChats(user.ID(), channelID, channelType, startID, count)
	if err != nil {
		response.ServerError(w, err)
		return
	}

	response.OK(w, chats)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:34,代碼來源:chat.go

示例6: GetProject

func GetProject(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser

	projectID := parser.Int(r.FormValue("projectID"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	p, err := store.GetProject(projectID)
	if err != nil {
		response.ServerError(w, err)
		return
	}

	if p.Author, err = store.GetUser(p.AuthorID); err != nil {
		response.ServerError(w, err)
		return
	}

	user := context.Get(r, "user").(store.User)
	p.IsMember = store.IsMember(projectID, user.ID())

	response.OK(w, p)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:25,代碼來源:project.go

示例7: PostChat

func PostChat(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser

	userID := parser.Int(r.FormValue("userID"))
	channelID := parser.Int(r.FormValue("channelID"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	chatParams := store.PostChatParams{
		UserID:      userID,
		ChannelID:   channelID,
		ChannelType: r.FormValue("channelType"),
		Text:        r.FormValue("text"),
	}

	id, err := store.PostChat(chatParams)
	if err != nil {
		response.ServerError(w, err)
		return
	}

	if err = store.NotifyChat(store.NotifyChatParams{id, chatParams}); err != nil {
		debug.Warn(err)
		return
	}

	response.OK(w, id)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:30,代碼來源:chat.go

示例8: GetFriends

func GetFriends(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser

	userID := parser.Int(r.FormValue("userID"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	users, err := store.GetFriends(userID)
	if err != nil {
		response.ServerError(w, err)
		return
	}

	for i := range users {
		if _, ok := h.connections[users[i].ID()]; ok {
			users[i].SetStatus("Online")
		} else {
			users[i].SetStatus("Offline")
		}
	}

	response.OK(w, users)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:25,代碼來源:friend.go

示例9: UpdateMilestone

func UpdateMilestone(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser

	projectID := parser.Int(r.FormValue("projectID"))
	milestoneID := parser.Int(r.FormValue("milestoneID"))
	date := parser.Time(r.FormValue("date"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	user := context.Get(r, "user").(store.User)
	if !user.IsAuthor(projectID) {
		response.ClientError(w, http.StatusForbidden)
		return
	}

	title := r.FormValue("title")
	description := r.FormValue("description")

	if err := store.UpdateMilestone(store.UpdateMilestoneParams{
		MilestoneID: milestoneID,
		Title:       title,
		Description: description,
		Date:        date,
	}); err != nil {
		response.ServerError(w, err)
		return
	}

	response.OK(w, nil)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:32,代碼來源:milestone.go

示例10: GetUser

func GetUser(w http.ResponseWriter, r *http.Request) {
	userIDStr := r.FormValue("userID")
	if userIDStr == "me" {
		response.OK(w, store.CurrentUser(r))
		return
	}

	var parser store.Parser
	userID := parser.Int(userIDStr)
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	user := context.Get(r, "user").(store.User)

	otherUser, err := store.GetUserWithParams(userID, store.GetUserParams{user.ID()})
	if err != nil {
		response.ServerError(w, err)
		return
	}

	if otherUser == nil {
		response.ClientError(w, http.StatusNotFound)
		return
	}

	response.OK(w, otherUser)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:29,代碼來源:user.go

示例11: GetAllUsers

func GetAllUsers(w http.ResponseWriter, r *http.Request) {
	users, err := store.GetAllUsers()
	if err != nil {
		response.ServerError(w, err)
		return
	}

	response.OK(w, users)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:9,代碼來源:user.go

示例12: CreateProject

func CreateProject(w http.ResponseWriter, r *http.Request) {
	title := r.FormValue("title")
	if title == "" {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	user := context.Get(r, "user").(store.User)
	tagline := r.FormValue("tagline")
	description := r.FormValue("description")

	// basic project info
	projectID, err := store.CreateProject(map[string]string{
		"authorID":    user.IDStr(),
		"title":       title,
		"tagline":     tagline,
		"description": description,
	})
	if err != nil {
		response.ServerError(w, err)
		return
	}

	var ok bool

	// add author to project user list
	if err = store.AddMember(projectID, user.ID()); err != nil {
		goto error
	}

	// image
	if ok, err = store.SaveProjectImage(w, r, projectID); err != nil || !ok {
		goto error
	}

	response.OK(w, projectID)
	return

error:
	if err := store.DeleteProject(projectID); err != nil {
		debug.Warn(err)
	}
	response.ServerError(w, err)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:44,代碼來源:project.go

示例13: UpdateProject

func UpdateProject(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser

	projectID := parser.Int(r.FormValue("projectID"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	user := context.Get(r, "user").(store.User)
	if !user.IsAuthor(projectID) {
		response.ClientError(w, http.StatusForbidden)
		return
	}

	for k, v := range r.Form {
		var err error

		if len(v) == 0 {
			continue
		}

		switch k {
		case "title":
			err = store.UpdateProjectTitle(projectID, v[0])
		case "tagline":
			err = store.UpdateProjectTagline(projectID, v[0])
		case "description":
			err = store.UpdateProjectDescription(projectID, v[0])
		}
		if err != nil {
			response.ServerError(w, err)
			return
		}
	}

	if _, err := store.SaveProjectImage(w, r, projectID); err != nil {
		response.ServerError(w, err)
		return
	}

	response.OK(w, nil)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:43,代碼來源:project.go

示例14: RemoveFriend

func RemoveFriend(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser
	otherUserID := parser.Int(r.FormValue("userID"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	user := context.Get(r, "user").(store.User)
	if isFriend, err := store.IsFriend(user.ID(), otherUserID); err != nil {
		response.ServerError(w, err)
		return
	} else if !isFriend {
		response.OK(w, nil)
		return
	}

	if err := store.RemoveFriend(user.ID(), otherUserID); err != nil {
		response.ServerError(w, err)
		return
	}

	response.OK(w, nil)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:24,代碼來源:friend.go

示例15: DeleteMilestone

func DeleteMilestone(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser

	milestoneID := parser.Int(r.FormValue("milestoneID"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	if err := store.DeleteMilestone(milestoneID); err != nil {
		response.ServerError(w, err)
		return
	}

	response.OK(w, nil)
}
開發者ID:bbh-labs,項目名稱:openinnovation-old,代碼行數:16,代碼來源:milestone.go


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