コード例 #1
0
func (t *SwiftSampleApi) PostMessage(r *http.Request, req *PostReq, res *PostRes) error {

	c := endpoints.NewContext(r)

	if u, error := endpoints.CurrentUser(c, Scopes, Audiences, ClientIds); error != nil {
		return endpoints.NewUnauthorizedError("Need auth")
	} else {
		req.Email = u.Email
	}

	req.RegisteredAt = time.Now()

	g := goon.NewGoon(r)

	if _, error := g.Put(req); error != nil {
		return error
	}

	res.Email = req.Email
	res.Message = req.Message
	res.Id = req.Id
	res.RegisteredAt = req.RegisteredAt

	return nil
}
コード例 #2
0
func (t *SwiftSampleApi) GetMessage(r *http.Request, _ *GetReq, res *GetRes) error {

	c := endpoints.NewContext(r)

	if u, error := endpoints.CurrentUser(c, Scopes, Audiences, ClientIds); error != nil {
		res.Message = "Hello World!"
		return nil
	} else {
		res.Message = fmt.Sprintf("Hello %s", u.Email)
		return nil
	}
}
コード例 #3
0
ファイル: api.go プロジェクト: rwl/go-tictactoe
// ScoresInsert inserts a new score for the current user.
func (ttt *TicTacToeApi) ScoresInsert(r *http.Request,
	req *ScoreReqMsg, resp *ScoreRespMsg) error {

	c := endpoints.NewContext(r)
	u, err := getCurrentUser(c)
	if err != nil {
		return err
	}
	score := newScore(req.Outcome, u)
	if err := score.put(c); err != nil {
		return err
	}
	score.toMessage(resp)
	return nil
}
コード例 #4
0
ファイル: api.go プロジェクト: rwl/go-tictactoe
// ScoresList queries scores for the current user.
// Exposed as API endpoint
func (ttt *TicTacToeApi) ScoresList(r *http.Request,
	req *ScoresListReq, resp *ScoresListResp) error {

	c := endpoints.NewContext(r)
	u, err := getCurrentUser(c)
	if err != nil {
		return err
	}
	q := newUserScoreQuery(u)
	if req.Limit <= 0 {
		req.Limit = 10
	}
	scores, err := fetchScores(c, q, req.Limit)
	if err != nil {
		return err
	}
	resp.Items = make([]*ScoreRespMsg, len(scores))
	for i, score := range scores {
		resp.Items[i] = score.toMessage(nil)
	}
	return nil
}