当前位置: 首页>>代码示例>>Golang>>正文


Golang context.NewContext函数代码示例

本文整理汇总了Golang中github.com/scotch/aego/v1/context.NewContext函数的典型用法代码示例。如果您正苦于以下问题:Golang NewContext函数的具体用法?Golang NewContext怎么用?Golang NewContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewContext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestEdit

func TestEdit(t *testing.T) {
	defer context.Close()
	c := context.NewContext(nil)

	// Set it.

	m := map[string]string{
		"A": "1",
	}
	cnfg, err := GetOrInsert(c, "first", m)

	// Change it.

	cnfg.Values["A"] = "2"

	// Save it.

	err = cnfg.Put(c)
	checkErr(t, err)

	// Confirm.

	cnfg, err = Get(c, "first")

	checkErr(t, err)
	if x := cnfg.Values["A"]; x != "2" {
		t.Errorf(`cnfg["A"]: %v, want %v`, x, "2")
	}
}
开发者ID:scotch,项目名称:aego,代码行数:29,代码来源:config_test.go

示例2: verifyHandler

func verifyHandler(w http.ResponseWriter, r *http.Request) {
	//code := r.FormValue("code")
	var e *Email
	var et *token.Token
	var err error
	c := context.NewContext(r)
	code := r.URL.Query().Get("code")
	errURL := "/"
	successURL := "/"
	et, err = token.Get(c, code)
	if err != nil {
		goto Error
	}
	e, err = Get(c, et.EmailAddress)
	if err != nil {
		goto Error
	}
	e.Status = verified
	if err = e.Put(c); err != nil {
		goto Error
	}
	http.Redirect(w, r, successURL, http.StatusFound)

Error:
	// TODO added error to session
	http.Redirect(w, r, errURL, http.StatusNotFound)
}
开发者ID:scotch,项目名称:aego,代码行数:27,代码来源:verify.go

示例3: Authenticate

// Authenticate process the request and returns a populated UserProfile.
// If the Authenticate method can not authenticate the User based on the
// request, an error or a redirect URL wll be return.
func (p *Provider) Authenticate(w http.ResponseWriter, r *http.Request) (
	up *profile.Profile, redirectURL string, err error) {

	c := context.NewContext(r)

	url := r.FormValue("provider")
	// Set provider info.
	up = profile.New(p.Name, url)

	// Check for current User.

	u := aeuser.Current(c)

	if u == nil {
		redirectURL := r.URL.Path + "/callback"
		loginUrl, err := aeuser.LoginURLFederated(c, redirectURL, url)
		return up, loginUrl, err
	}

	if u.FederatedIdentity != "" {
		up.ID = u.FederatedIdentity
	} else {
		up.ID = u.ID
	}

	per := new(person.Person)
	per.Email = u.Email
	per.Emails = []*person.PersonEmails{
		&person.PersonEmails{true, "home", u.Email},
	}
	per.URL = u.FederatedIdentity
	up.Person = per

	return up, "", nil
}
开发者ID:scotch,项目名称:aego,代码行数:38,代码来源:appengine_openid.go

示例4: Test_handler

func Test_handler(t *testing.T) {
	setup()
	defer teardown()
	_ = context.NewContext(nil)

	// Register the Provider

	p := &TPComplete{}
	Register("example5", p)
	r, _ := http.NewRequest("GET", "http://localhost:8080/-/auth/example5", nil)
	w := httptest.NewRecorder()

	// Run it through the auth handler.

	handler(w, r)

	// Inspected the redirect.

	hdr := w.Header()
	if hdr["Location"][0] != SuccessURL {
		t.Errorf(`hdr["Location"]: %q, want %q`, hdr["Location"][0], SuccessURL)
		t.Errorf(`w: %q`, w)
		t.Errorf(`hdr: %q`, hdr)
	}
}
开发者ID:scotch,项目名称:aego,代码行数:25,代码来源:auth_test.go

示例5: TestDelete

func TestDelete(t *testing.T) {
	setup()
	c := context.NewContext(nil)
	defer tearDown()
	var x interface{}
	// Put A
	x = &A{S: "a", I: 1, B: []byte{}, T: now}
	key := datastore.NewKey(c, "A", "1", 0, nil)
	key, _ = Put(c, key, x)
	// Delete A
	err := Delete(c, key)
	if err != nil {
		t.Errorf(`err = %s; expected nil`, err)
	}
	// Test Store for absence of values
	x = &A{}
	err = memory.Get(c, key, x)
	if err != dserrors.ErrNoSuchEntity {
		t.Errorf(`err = %s; expected %s`, err, dserrors.ErrNoSuchEntity)
	}
	err = memcache.Get(c, key, x)
	if err != dserrors.ErrNoSuchEntity {
		t.Errorf(`err = %s; expected %s`, err, dserrors.ErrNoSuchEntity)
	}
	err = dsds.Get(c, key, x)
	if err != dserrors.ErrNoSuchEntity {
		t.Errorf(`err = %s; expected %s`, err, dserrors.ErrNoSuchEntity)
	}
}
开发者ID:scotch,项目名称:aego,代码行数:29,代码来源:ds_test.go

示例6: TestDelete

func TestDelete(t *testing.T) {
	setup()
	defer tearDown()
	c := context.NewContext(nil)

	// Put.

	k, x := NewX(c, "1")
	_, err := s.Put(c, k, x)

	// Delete.
	err = s.Delete(c, k)
	if err != nil {
		t.Errorf("err: %v; want: %v.", err, nil)
	}

	// Delete non-existence

	k = datastore.NewKey(c, "X", "fakekey", 0, nil)
	r := new(X)
	err = s.Get(c, k, r)

	if err != dse.ErrNoSuchEntity {
		t.Errorf("err: %v; want: %v.", err, dse.ErrNoSuchEntity)
	}
}
开发者ID:scotch,项目名称:aego,代码行数:26,代码来源:datastore_test.go

示例7: TestGetOrInsert

func TestGetOrInsert(t *testing.T) {
	defer context.Close()
	c := context.NewContext(nil)

	// Set it.

	m := map[string]string{
		"A": "1",
	}
	cnfg, err := GetOrInsert(c, "first", m)

	// Confirm.

	checkErr(t, err)
	if x := cnfg.Values["A"]; x != "1" {
		t.Errorf(`config["A"]: %v, want %v`, x, "1")
	}

	// The orginal map should be returned.

	m = map[string]string{
		"A": "2",
	}

	cnfg, err = GetOrInsert(c, "first", m)

	// Confirm.

	checkErr(t, err)
	if x := cnfg.Values["A"]; x != "1" {
		t.Errorf(`config["A"]: %v, want %v`, x, "1")
	}
}
开发者ID:scotch,项目名称:aego,代码行数:33,代码来源:config_test.go

示例8: TestPut

func TestPut(t *testing.T) {
	setup()
	defer tearDown()
	c := context.NewContext(nil)

	k, x1 := NewX(c, "1")
	_, err := s.Put(c, k, x1)
	if err != nil {
		t.Errorf("err: %v; want: %v.", err, nil)
	}
}
开发者ID:scotch,项目名称:aego,代码行数:11,代码来源:datastore_test.go

示例9: TestNewKey

func TestNewKey(t *testing.T) {
	c := context.NewContext(nil)
	defer tearDown()

	k1 := datastore.NewKey(c, "AuthProfile", "google|12345", 0, nil)
	k2 := newKey(c, "Google", "12345")
	if k1.String() != k2.String() {
		t.Errorf("k2: %q, want %q.", k2, k1)
		t.Errorf("k1:", k1)
		t.Errorf("k2:", k2)
	}
}
开发者ID:scotch,项目名称:aego,代码行数:12,代码来源:profile_test.go

示例10: callback

func (p *Provider) callback(r *http.Request) error {
	// Exchange code for an access token at OAuth provider.
	code := r.FormValue("code")
	t := &oauth.Transport{
		Config: p.Config(r.URL),
		Transport: &urlfetch.Transport{
			Context: context.NewContext(r),
		},
	}
	_, err := t.Exchange(code)
	return err
}
开发者ID:scotch,项目名称:aego,代码行数:12,代码来源:oauth2.go

示例11: CreateAndLogin

// CreateAndLogin does the following:
//
//  - Search for an existing user - session -> Profile -> email address
//  - Saves the Profile to the datastore
//  - Creates a User or appends the AuthID to the Requesting user's account
//  - Logs in the User
//  - Adds the admin role to the User if they are an GAE Admin.
func CreateAndLogin(w http.ResponseWriter, r *http.Request,
	p *profile.Profile) (u *user.User, err error) {
	c := context.NewContext(r)
	if u, err = p.UpdateUser(w, r); err != nil {
		return
	}
	if err = user.CurrentUserSetID(w, r, p.UserID); err != nil {
		return
	}
	err = p.Put(c)
	return
}
开发者ID:scotch,项目名称:aego,代码行数:19,代码来源:auth.go

示例12: Current

// Current returns the current users password object minus the password
func (s *Service) Current(w http.ResponseWriter, r *http.Request,
	args *Args, reply *Args) (err error) {

	c := context.NewContext(r)
	var isSet bool
	userID, _ := user.CurrentUserID(r)
	_, err = profile.Get(c, profile.GenAuthID("Password", userID))
	if err == nil {
		isSet = true
	}
	reply.Password = &Password{IsSet: isSet}
	return nil
}
开发者ID:scotch,项目名称:aego,代码行数:14,代码来源:service.go

示例13: Current

// Current checks the requesting User's session to see if they have an
// account. If they do, the provided User struct is populated with the
// information that is saved in the datastore. If they don't an error is
// returned.
func Current(r *http.Request) (*User, error) {
	id, _ := CurrentUserID(r)

	if id != "" {
		c := context.NewContext(r)
		u := new(User)
		key := datastore.NewKey(c, "User", id, 0, nil)
		err := ds.Get(c, key, u)
		u.Key = key
		return u, err
	}
	return nil, ErrNoLoggedInUser
}
开发者ID:scotch,项目名称:aego,代码行数:17,代码来源:session.go

示例14: GetAll

func (s *Service) GetAll(w http.ResponseWriter, r *http.Request,
	args *Args, reply *Reply) (err error) {

	c := context.NewContext(r)
	u, err := user.Current(r)
	if err != nil {
		return err
	}
	if reply.Profiles, err = GetPersonMulti(c, u.AuthIDs); err != nil {
		return err
	}
	return nil
}
开发者ID:scotch,项目名称:aego,代码行数:13,代码来源:service.go

示例15: TestGetMulti

func TestGetMulti(t *testing.T) {
	setup()
	defer tearDown()
	c := context.NewContext(nil)

	if cnt := s.Count(c); cnt != 0 {
		t.Errorf(`Before Put; s.Count(c): %v; want %v`, cnt, 0)
	}

	// Put.

	k1, x1 := NewX(c, "1")
	k2, x2 := NewX(c, "2")
	k3, x3 := NewX(c, "3")
	keys := []*datastore.Key{k1, k2, k3}
	xs := []*X{x1, x2, x3}
	keys, err := s.PutMulti(c, keys, xs)

	// Get.

	xs = []*X{&X{}, &X{}, &X{}}
	err = s.GetMulti(c, keys, xs)

	// Confirm.

	if err != nil {
		t.Errorf("err: %v; want: %v.", err, nil)
	}
	CheckX(c, t, xs[0], "1")
	CheckX(c, t, xs[1], "2")
	CheckX(c, t, xs[2], "3")

	// Get non-existence

	k4, _ := NewX(c, "4")
	k5, _ := NewX(c, "5")
	xs = []*X{&X{}, &X{}, &X{}, &X{}, &X{}}
	keys = []*datastore.Key{k1, k2, k3, k4, k5}

	err = s.GetMulti(c, keys, xs)

	if err.Error() != "ds: no such entity (and 1 other error)" {
		t.Errorf("err: %v; want: %v.", err.Error(), "ds: no such entity (and 1 other error)")
	}

	// Check.

	CheckX(c, t, xs[0], "1")
	CheckX(c, t, xs[1], "2")
	CheckX(c, t, xs[2], "3")
}
开发者ID:scotch,项目名称:aego,代码行数:51,代码来源:memcache_test.go


注:本文中的github.com/scotch/aego/v1/context.NewContext函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。