Golang github.com-ArdanStudios-gotraining-12-http-api-app.Context类(方法)实例源码

下面列出了Golang github.com-ArdanStudios-gotraining-12-http-api-app.Context 类(方法)源码代码实例,从而了解它的用法。

作者:rlugoj    项目:gotrainin   
// Retrieve returns the specified user from the system.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (uh usersHandle) Retrieve(c *app.Context) error {
	u, err := services.Users.Retrieve(c, c.Params["id"])
	if err != nil {
		return err
	}

	c.Respond(u, http.StatusOK)
	return nil
}

作者:rlugoj    项目:gotrainin   
// List returns all the existing users in the system.
// 200 Success, 404 Not Found, 500 Internal
func (uh usersHandle) List(c *app.Context) error {
	u, err := services.Users.List(c)
	if err != nil {
		return err
	}

	c.Respond(u, http.StatusOK)
	return nil
}

作者:rlugoj    项目:gotrainin   
// Update updates the specified user in the system.
// 200 Success, 400 Bad Request, 500 Internal
func (uh usersHandle) Update(c *app.Context) error {
	var u models.User
	if err := json.NewDecoder(c.Request.Body).Decode(&u); err != nil {
		return err
	}

	if v, err := services.Users.Update(c, c.Params["id"], &u); err != nil {
		switch err {
		case app.ErrValidation:
			c.RespondInvalid(v)
			return nil

		default:
			return err
		}
	}

	return Users.Retrieve(c)
}


问题


面经


文章

微信
公众号

扫码关注公众号