本文整理汇总了Golang中einvite/framework.WebContext.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang WebContext.Error方法的具体用法?Golang WebContext.Error怎么用?Golang WebContext.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类einvite/framework.WebContext
的用法示例。
在下文中一共展示了WebContext.Error方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestHighLoad
func (this *GoogleController) TestHighLoad(ctx framework.WebContext) framework.WebResult {
n := randomizer.Int63()
email := fmt.Sprintf("user%[email protected]", n)
name := fmt.Sprintf("User %d", n)
dto := &contracts.User{Email: email, Name: name}
credentials := &contracts.UserAuthCredentials{
Type: framework.AuthType_Google,
AccessToken: fmt.Sprintf("Access token for user %s", name),
RefreshToken: fmt.Sprintf("Refresh token for user %s", name),
Expiry: time.Now().Add(1 * time.Hour),
}
_, err := this.userService.SaveWithCredentials(dto, credentials)
if err != nil {
log.Println(err)
return ctx.Error(err)
}
session := ctx.Session()
session.SetUser(&framework.SessionUser{
UserId: email,
AuthType: framework.AuthType_Google,
AuthData: credentials.AccessToken,
})
return ctx.Text("OK")
}
示例2: ListUsers
func (this UserController) ListUsers(ctx framework.WebContext) framework.WebResult {
users, err := this.userService.List()
if err == nil {
return ctx.Json(users)
}
return ctx.Error(err)
}
示例3: AuthCallback
// Function that handles the callback from the Google server
func (this *FacebookController) AuthCallback(ctx framework.WebContext) framework.WebResult {
//Get the code from the response
code, _ := ctx.Param("code")
t := &oauth.Transport{Config: this.oauthCfg}
// Exchange the received code for a token
t.Exchange(code)
//now get user data based on the Transport which has the token
resp, err := t.Client().Get(this.profileInfoURL)
if err != nil {
log.Println(err)
return ctx.FrameworkError(framework.ToError(framework.Error_Web_UnableToAuthenticate, err))
}
userprofile := make(map[string]interface{})
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&userprofile)
if err != nil {
log.Println(err)
return ctx.FrameworkError(framework.ToError(framework.Error_Web_UnableToAuthenticate, err))
}
fmt.Println(userprofile)
email := userprofile["email"].(string)
name := userprofile["name"].(string)
userDto := &contracts.User{Email: email, Name: name}
userCredentialsDto := &contracts.UserAuthCredentials{
Type: framework.AuthType_Facebook,
AccessToken: t.Token.AccessToken,
RefreshToken: t.Token.RefreshToken,
Expiry: t.Token.Expiry,
}
user, err2 := this.userService.SaveWithCredentials(userDto, userCredentialsDto)
if err2 != nil {
return ctx.Error(err2)
}
ctx.Session().SetUser(&framework.SessionUser{
UserId: user.Email,
AuthType: framework.AuthType_Facebook,
AuthData: t.AccessToken,
})
return ctx.Template(userInfoTemplate, fmt.Sprintf("Name: %s Email: %s", name, email))
}
示例4: GetUser
func (this UserController) GetUser(ctx framework.WebContext) framework.WebResult {
name, _ := ctx.Param("name")
email, _ := ctx.Param("email")
user, err := this.userService.Create(&contracts.User{Email: email, Name: name})
if err == nil {
return ctx.Json(user)
}
return ctx.Error(err)
}