当前位置: 首页>>代码示例>>Golang>>正文


Golang response.OK函数代码示例

本文整理汇总了Golang中github.com/bbhmakerlab/openinnovation/response.OK函数的典型用法代码示例。如果您正苦于以下问题:Golang OK函数的具体用法?Golang OK怎么用?Golang OK使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了OK函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: 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

示例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: 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

示例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: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例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: logout

//
// /logout
//
func logout(w http.ResponseWriter, r *http.Request) {
	switch r.Method {
	case "POST":
		session.Clear(w, r)
		response.OK(w, "Successfully logged out.")
	default:
		response.ClientError(w, http.StatusMethodNotAllowed)
	}
}
开发者ID:bbh-labs,项目名称:openinnovation-old,代码行数:12,代码来源:api.go

示例13: login

//
// /login
//
func login(w http.ResponseWriter, r *http.Request) {
	switch r.Method {
	case "POST":
		Login(w, r)
	case "GET":
		response.OK(w, store.CurrentUser(r))
	default:
		response.ClientError(w, http.StatusMethodNotAllowed)
	}
}
开发者ID:bbh-labs,项目名称:openinnovation-old,代码行数:13,代码来源:api.go

示例14: loginSuccess

func loginSuccess(w http.ResponseWriter, r *http.Request, email string) {
	session.Set(w, r, email)

	user := store.CurrentUser(r)
	if !user.Exists() {
		response.ClientError(w, http.StatusForbidden)
		return
	}

	response.OK(w, user)
}
开发者ID:bbh-labs,项目名称:openinnovation-old,代码行数:11,代码来源:login.go

示例15: 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


注:本文中的github.com/bbhmakerlab/openinnovation/response.OK函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。