Skip to content

Instantly share code, notes, and snippets.

@leopard627
Created July 8, 2017 06:04
Show Gist options
  • Save leopard627/b2a9fc263b8a1b81f9005454d940b793 to your computer and use it in GitHub Desktop.
Save leopard627/b2a9fc263b8a1b81f9005454d940b793 to your computer and use it in GitHub Desktop.
BeeGo Tips
func (c *UserController) GetOne() {
o := orm.NewOrm()
var user models.User
idStr := c.Ctx.Input.Param(":id")
// 만일 파람으로 넘어온 키값으로 얻은 유저이름이 다르거나
// 또는 관리자나 슈퍼유저가 아닌경우에 401에러를 날립니다
// 현재 세션은 메모리로 하기때문에 60초 뒤에 날라감
// mysql로 설정 변경 필요
username := c.GetSession("Username")
// 여기서 우리가 위쪽에 선언한 var user에 값이 들어간단 말이다!!!!
// 뭔가 장고와 다르지만 좋다!
err := o.QueryTable("user").Filter("Id", idStr).Filter("username", username).One(&user) // One 으로 헀는데, 만약에 All이면
// var user []*models.User() 이런식으로!!! 하면 된단 말이다!!
if err == orm.ErrNoRows {
// 제대로된 세션이 아닌경우에는
// 401 에러를 보냅니다.
c.Ctx.Output.SetStatus(401)
c.Abort("401")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment