本文整理汇总了Golang中github.com/robmeades/utm/service/models.User.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang User.Get方法的具体用法?Golang User.Get怎么用?Golang User.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/robmeades/utm/service/models.User
的用法示例。
在下文中一共展示了User.Get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Profile
// TODO
func (u *User) Profile(response http.ResponseWriter, request *http.Request) {
user_id, _ := utilities.GetUserId(request)
db := utilities.GetDB(request)
user := new(models.User)
user.Get(db, user_id)
user.Password = ""
out, _ := json.Marshal(user)
response.Write(out)
}
示例2: User
/// Method for the authentication struct that takes
// an HTTP request and returns an HTTP response containing
// the user's details.
func (a *Auth) User(request http.ResponseWriter, response *http.Request) {
db := utilities.GetDB(response)
session := sessions.GetSession(response)
user_id := session.Get("user_id")
fmt.Println(user_id)
if user_id == nil {
request.WriteHeader(403)
} else {
user := new(models.User)
user.Get(db, user_id.(string))
fmt.Println(user)
outData, _ := json.Marshal(user)
request.Write(outData)
}
}
示例3: Get
/// Method for the user struct that takes an HTTP request and
// returns an HTTP response containing the user's details for
// their ID.
func (u *User) Get(response http.ResponseWriter, request *http.Request) {
vars := mux.Vars(request)
id := vars["id"]
db := utilities.GetDB(request)
user := new(models.User)
err := user.Get(db, id)
if err != nil {
response.WriteHeader(404)
} else {
user.Password = ""
out, _ := json.Marshal(user)
response.Write(out)
}
}