當前位置: 首頁>>代碼示例>>Golang>>正文


Golang framework.WebContext類代碼示例

本文整理匯總了Golang中einvite/framework.WebContext的典型用法代碼示例。如果您正苦於以下問題:Golang WebContext類的具體用法?Golang WebContext怎麽用?Golang WebContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了WebContext類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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)
}
開發者ID:mfelicio,項目名稱:go-einvite-traditional,代碼行數:10,代碼來源:userController.go

示例2: Auth

// Start the authorization process
func (this *FacebookController) Auth(ctx framework.WebContext) framework.WebResult {

	//can be used to pass state between server-to-server calls (roundtripped)
	state := ""

	//Get the Google URL which shows the Authentication page to the user
	url := this.oauthCfg.AuthCodeURL(state)

	//redirect user to that page
	return ctx.Redirect(url)
}
開發者ID:mfelicio,項目名稱:go-einvite-traditional,代碼行數:12,代碼來源:facebook.go

示例3: Test

func (this EventController) Test(ctx framework.WebContext) framework.WebResult {

	//note: time.sleep frees the thread and allows other goroutines to execute
	//sending 1000 concurrent requests with AB all complete within 5seconds

	time.Sleep(1 * time.Second)

	fmt.Println(ctx.Header())

	fmt.Println("Test invoked")

	return ctx.Text("test operation")
}
開發者ID:mfelicio,項目名稱:go-einvite-traditional,代碼行數:13,代碼來源:eventController.go

示例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)
}
開發者ID:mfelicio,項目名稱:go-einvite-traditional,代碼行數:13,代碼來源:userController.go

示例5: 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")
}
開發者ID:mfelicio,項目名稱:go-einvite-traditional,代碼行數:29,代碼來源:google.go

示例6: Write

//adapted from Revel framework BinaryResult.Apply method
func (r *StreamResult) Write(ctx framework.WebContext) error {

	var err error

	// If we have a ReadSeeker, delegate to http.ServeContent
	if rs, ok := r.Reader.(io.ReadSeeker); ok {
		http.ServeContent(ctx, ctx.Req(), r.Name, r.ModTime, rs)

	} else {
		// Else, do a simple io.Copy.

		if r.Length != -1 {
			ctx.Header().Set("Content-Length", strconv.FormatInt(r.Length, 10))
		}

		ctx.WriteHeader(http.StatusOK)
		//TODO: use a mime-type to file extension strategy like Revel does
		//ctx.ContentType("application/octet-stream")
		//ctx.ContentType(ContentTypeByFilename(r.Name))
		_, err = io.Copy(ctx, r.Reader)
	}

	// Close the Reader if we can
	if v, ok := r.Reader.(io.Closer); ok {
		v.Close()
	}

	return err
}
開發者ID:mfelicio,項目名稱:go-einvite-traditional,代碼行數:30,代碼來源:result.go

示例7: HandleRoot

func (this *GoogleController) HandleRoot(ctx framework.WebContext) framework.WebResult {

	session := ctx.Session()

	if sessionUser := session.User(); sessionUser == nil {

		return ctx.Template(notAuthenticatedTemplate, nil)
	} else {
		email := sessionUser.UserId
		user, _ := this.userService.Get(email)
		return ctx.Template(authenticatedTemplate, user.Name)
	}
}
開發者ID:mfelicio,項目名稱:go-einvite-traditional,代碼行數:13,代碼來源:google.go

示例8: 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))
}
開發者ID:mfelicio,項目名稱:go-einvite-traditional,代碼行數:54,代碼來源:facebook.go

示例9: CreateEvent

func (this EventController) CreateEvent(ctx framework.WebContext) framework.WebResult {

	return ctx.Unauthorized("Thou shall not create an event")
}
開發者ID:mfelicio,項目名稱:go-einvite-traditional,代碼行數:4,代碼來源:eventController.go

示例10: CreateUser

func (this UserController) CreateUser(ctx framework.WebContext) framework.WebResult {

	return ctx.Forbidden("Thou shall not create an user")
}
開發者ID:mfelicio,項目名稱:go-einvite-traditional,代碼行數:4,代碼來源:userController.go

示例11: Who

func (this UserController) Who(ctx framework.WebContext) framework.WebResult {

	return ctx.Text("Anonymous")
}
開發者ID:mfelicio,項目名稱:go-einvite-traditional,代碼行數:4,代碼來源:userController.go


注:本文中的einvite/framework.WebContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。