コード例 #1
0
// TestRootRequest tests
func TestRootRequest(t *testing.T) {
	assert := assert.New(t)

	var req RootRequest
	req = RootRequest{}
	req.needAccessToken = false
	assert.NoError(req.validate())
	req.needAccessToken = true
	assert.Error(req.validate())
	assert.Equal("", req.GetAccessToken())

	token := accesstoken.Generate([]byte("foobar"))
	req.SetAccessToken(token.String())
	assert.Equal(token.String(), req.GetAccessToken())
}
コード例 #2
0
ファイル: me_service.go プロジェクト: gophergala2016/source
// CreateMe new user
func (s MeService) CreateMe(name, avatarURL, location string) (*models.User, error) {
	token := accesstoken.Generate(accesstoken.GenerateRandomKey(32))
	user := models.NewUser(name, avatarURL, location, token.String())
	userRepository := models.NewUserRepository(s.ctx)
	return userRepository.Create(user)
}