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


Golang appengine.NewContext函數代碼示例

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


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

示例1: deleteAccountHandler

func deleteAccountHandler(w http.ResponseWriter, r *http.Request) {

	id := ""
	session, err := sessions.Session(r, "", "datastore")
	c1 := appengine.NewContext(r)
	c1.Debugf("deleteAccount: id=%v, session=%v, err=%v\n", session["userID"], session, err)
	if err == nil {
		if session["userID"] != nil {
			id = session["userID"].(string)
		}
	}
	if id != "" {
		user := loadUser(r, id)
		if user.Id != "" {
			c := appengine.NewContext(r)
			key := datastore.NewKey(c, "User", user.Id, 0, nil)
			datastore.Delete(c, key)
			session["userID"] = ""
			sessions.Save(r, w)
			memUserDelete(c, user.Id)
			memcache.Delete(c, "user"+user.Id)
			http.SetCookie(w, &http.Cookie{Name: "userId", Value: "", Domain: appConfig.AppDomain, Path: "/", MaxAge: -1})
		}
	}
	http.Redirect(w, r, "/", http.StatusFound)
}
開發者ID:licio,項目名稱:unico,代碼行數:26,代碼來源:unico.go

示例2: signInTwitterHandler

func signInTwitterHandler(w http.ResponseWriter, r *http.Request) {

	c := appengine.NewContext(r)
	id := r.FormValue("id")
	if id == "" {
		serveError(c, w, errors.New("Missing ID parameter"))
		return
	}

	conf := &tweetlib.Config{
		ConsumerKey:    appConfig.TwitterConsumerKey,
		ConsumerSecret: appConfig.TwitterConsumerSecret,
		Callback:       "http://" + appConfig.AppHost + "/twitter?action=temp&id=" + id}
	tok := &tweetlib.Token{}
	tr := &tweetlib.Transport{Config: conf,
		Token:     tok,
		Transport: &urlfetch.Transport{Context: c}}

	tt, err := tr.TempToken()
	if err != nil {
		c := appengine.NewContext(r)
		serveError(c, w, err)
		c.Errorf("%v", err)
		return
	}
	item := &memcache.Item{
		Key:   tt.Token,
		Value: []byte(tt.Secret),
	}
	// Add the item to the memcache, if the key does not already exist
	memcache.Add(c, item)

	http.Redirect(w, r, tt.AuthURL(), http.StatusFound)
}
開發者ID:robteix,項目名稱:unico,代碼行數:34,代碼來源:twitter.go

示例3: secureWebAccess

func secureWebAccess(w http.ResponseWriter, r *http.Request) *User {
	session, _ := sessionsStore.Get(r, "logindata")
	value := session.Values["id"]

	c := appengine.NewContext(r)
	c.Infof("The Value is: %v", value)

	var u User

	if value == nil {
		c.Infof("Redirecting to login")
		http.Redirect(w, r, "/login.do", http.StatusTemporaryRedirect)
	} else {
		c := appengine.NewContext(r)
		q := datastore.NewQuery("User").
			Filter("Username = ", value.(string))
		//k := datastore.NewKey(c,"User",,0,nil)

		if count, _ := q.Count(c); count == 0 {
			//what ever you have in the session is not in the datastore, these happends when you delete a user directly from the datastore, and the sesion is still active
			http.Redirect(w, r, "/login.do", http.StatusTemporaryRedirect)
			return nil
		}
		t := q.Run(c)
		t.Next(&u)
	}

	return &u
}
開發者ID:Tok3n,項目名稱:tok3nsdkgo_demoAE,代碼行數:29,代碼來源:tok3nsdkgoDemoAE.go

示例4: TestEditVisitPageMissingPathInfo

func TestEditVisitPageMissingPathInfo(t *testing.T) {
	inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	url := "/editvisit/"
	req, err := inst.NewRequest("GET", url, nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w := httptest.NewRecorder()
	c := appengine.NewContext(req)

	addTestUser(c, "[email protected]", true)

	editvisitpage(c, w, req)

	code := w.Code
	if code != http.StatusBadRequest {
		t.Errorf("got code %v, want %v", code, http.StatusBadRequest)
	}

	body := w.Body.Bytes()
	expected := []byte("id is missing in path for update request /editvisit/")
	if !bytes.Contains(body, expected) {
		t.Errorf("got body %v, did not contain %v", string(body),
			string(expected))
	}

	url += "12345"
	req, err = inst.NewRequest("GET", url, nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w = httptest.NewRecorder()
	c = appengine.NewContext(req)

	editvisitpage(c, w, req)

	code = w.Code
	if code != http.StatusBadRequest {
		t.Errorf("got code %v, want %v", code, http.StatusBadRequest)
	}

	body = w.Body.Bytes()
	expected = []byte("id is missing in path for update request /editvisit/")
	if !bytes.Contains(body, expected) {
		t.Errorf("got body %v, did not contain %v", string(body),
			string(expected))
	}

}
開發者ID:jimhopp,項目名稱:frederic,代碼行數:60,代碼來源:web_test.go

示例5: data

func data(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	confData, err := Configs(appengine.NewContext(r))
	handlePanic(w, c, err)
	jsonData, err := json.Marshal(confData)
	handlePanic(w, c, err)
	fmt.Fprintf(w, "%s", jsonData)
}
開發者ID:kpawlik,項目名稱:webchecker,代碼行數:8,代碼來源:main.go

示例6: sendLinks

func sendLinks(w http.ResponseWriter, req *http.Request) {
	m, _ := url.ParseQuery(req.URL.RawQuery)
	col, _ := strconv.Atoi(m["col"][0])
	count, _ := strconv.Atoi(m["count"][0])
	str := controllers.GetImages(col, count, appengine.NewContext(req))
	json, _ := json.Marshal(str)
	c := appengine.NewContext(req)
	c.Infof("%d", len(str))
	io.WriteString(w, string(json))
}
開發者ID:Sfeir,項目名稱:flag42,代碼行數:10,代碼來源:router.go

示例7: get

func (p *Profile) get(w http.ResponseWriter, r *http.Request) {

	// Create a key with a key for Profile with Key = Id
	p.Id = user.Current(appengine.NewContext(r)).ID
	c := appengine.NewContext(r)
	err := datastore.Get(c, datastore.NewKey(c, "Profile", p.Id, 0, nil), p)
	if err != nil {
		//       http.Error(w, err.Error(), http.StatusInternalServerError)
		p.put(w, r)
	}

}
開發者ID:johnwhitton,項目名稱:stunning-agency-409,代碼行數:12,代碼來源:profile.go

示例8: twitterVerify

func twitterVerify(w http.ResponseWriter, r *http.Request) {
	token := r.FormValue("oauth_token")
	id := r.FormValue("id")
	c := appengine.NewContext(r)

	if id == "" {
		serveError(c, w, errors.New("Missing ID parameter"))
		return
	}

	item, _ := memcache.Get(c, token)

	secret := string(item.Value)
	verifier := r.FormValue("oauth_verifier")

	conf := &tweetlib.Config{
		ConsumerKey:    appConfig.TwitterConsumerKey,
		ConsumerSecret: appConfig.TwitterConsumerSecret}
	tok := &tweetlib.Token{}
	tr := &tweetlib.Transport{Config: conf,
		Token:     tok,
		Transport: &urlfetch.Transport{Context: c}}

	tt := &tweetlib.TempToken{Token: token, Secret: secret}
	tok, err := tr.AccessToken(tt, verifier)
	if err != nil {
		c := appengine.NewContext(r)
		serveError(c, w, err)
		c.Errorf("%v", err)
		return
	}
	tr.Token = tok
	tl, _ := tweetlib.New(tr.Client())
	u, err := tl.Account.VerifyCredentials(nil)
	fmt.Printf("err=%v\n", err)
	user := loadUser(r, id)
	user.TwitterOAuthToken = tok.OAuthToken
	user.TwitterOAuthSecret = tok.OAuthSecret
	user.TwitterId = u.IdStr
	user.TwitterScreenName = u.ScreenName
	if err := saveUser(r, &user); err != nil {
		serveError(c, w, err)
		return
	}

	http.Redirect(w, r, "/", http.StatusFound)

}
開發者ID:robteix,項目名稱:unico,代碼行數:48,代碼來源:twitter.go

示例9: primeCache

func primeCache(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	err := model.ForceUpdateStatuses(c)
	if err != nil {
		http.Error(w, "An error occured while updating the cache", http.StatusInternalServerError)
	}
}
開發者ID:bss,項目名稱:hvadsigeralex.dk,代碼行數:7,代碼來源:app.go

示例10: view

func view(w http.ResponseWriter, r *http.Request) {

	id, _ := strconv.Atoi(r.FormValue("id"))

	c := appengine.NewContext(r)

	var view detail_view

	// グループ情報を取得
	if group, err := model.GetGroup(c, id); err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	} else {
		view.Group = group
	}

	// メンバー情報を取得
	if memberlist, err := model.MemberList(c, id); err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	} else {
		view.Member = memberlist
	}

	// 詳細畫麵を表示
	if err := detailTemplate.Execute(w, view); err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
	}
}
開發者ID:tyokoyama,項目名稱:osh2012demo,代碼行數:29,代碼來源:view.go

示例11: handleInboxItem

func handleInboxItem(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	userid, _, err := getSession(c, r)
	if err != nil {
		sendError(w, r, "No session cookie")
		return
	}

	s := newStore(c)
	perma_blobref := r.FormValue("perma")
	item, err := s.GetInboxItem(userid, perma_blobref)
	if err != nil {
		http.Error(w, "Could not get inbox item", http.StatusInternalServerError)
		c.Errorf("handleInboxItem: %v", err)
		return
	}
	entry := make(map[string]interface{})
	entry["perma"] = perma_blobref
	entry["seq"] = item.LastSeq
	err = fillInboxItem(s, perma_blobref, item.LastSeq, entry)
	if err != nil {
		fmt.Fprintf(w, `{"ok":false, "error":%v}`, err.String())
		return
	}

	info, _ := json.Marshal(entry)
	fmt.Fprintf(w, `{"ok":true, "item":%v}`, string(info))
}
開發者ID:AaronO,項目名稱:lightwave,代碼行數:28,代碼來源:server.go

示例12: handleListInbox

func handleListInbox(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	userid, _, err := getSession(c, r)
	if err != nil {
		sendError(w, r, "No session cookie")
		return
	}

	s := newStore(c)
	inbox, err := s.ListInbox(userid, false)
	if err != nil {
		sendError(w, r, err.String())
		return
	}

	// Read the updates for all items in the inbox
	for _, entry := range inbox {
		fillInboxItem(s, entry["perma"].(string), entry["seq"].(int64), entry)
	}

	j := map[string]interface{}{"ok": true, "items": inbox}
	msg, err := json.Marshal(j)
	if err != nil {
		panic("Cannot serialize")
	}
	fmt.Fprint(w, string(msg))
}
開發者ID:AaronO,項目名稱:lightwave,代碼行數:27,代碼來源:server.go

示例13: ArticleDeleteHandler

func ArticleDeleteHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	user := core.AdminUser(c, w)
	if user == nil {
		return
	}

	vars := mux.Vars(r)
	id, err := strconv.ParseInt(vars["id"], 10, 64)
	if err != nil {
		core.HandleError(c, w, err)
		return
	}

	article, err := GetArticleById(c, id, false)
	if err != nil {
		core.HandleNotFound(c, w)
		return
	}

	err = DeleteArticle(c, article)
	if err != nil {
		core.HandleError(c, w, err)
		return
	}

	http.Redirect(w, r, "/", 302)
}
開發者ID:vmihailenco,項目名稱:goblog,代碼行數:29,代碼來源:handlers.go

示例14: ArticlePermaLinkHandler

func ArticlePermaLinkHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	vars := mux.Vars(r)
	id, err := strconv.ParseInt(vars["id"], 10, 64)
	if err != nil {
		core.HandleError(c, w, err)
		return
	}

	article, err := GetArticleById(c, id, true)
	if err != nil {
		core.HandleNotFound(c, w)
		return
	}

	if !article.IsPublic {
		user := auth.CurrentUser(c)
		if !user.IsAdmin {
			core.HandleAuthRequired(c, w)
			return
		}
	}

	redirectTo, err := article.URL()
	if err != nil {
		core.HandleNotFound(c, w)
		return
	}
	http.Redirect(w, r, redirectTo.Path, 302)
}
開發者ID:vmihailenco,項目名稱:goblog,代碼行數:31,代碼來源:handlers.go

示例15: handleIndex

func handleIndex(w http.ResponseWriter, r *http.Request) {
    c := appengine.NewContext(r)

    // Get user info
    userInfo := getUserInfo(c)

    // Get post id and page id
    pageId, _ := strconv.Atoi(getUrlQuery(r.URL, "pid"))
    pageSize  := config.PageSize

    // Get offset and page numbers
    offset, pageNums := getOffset("Article", pageId, pageSize, c)

    // New PageSetting
    pageSetting := new(PageSetting)

    // Setting PageSetting
    pageSetting.Title       = config.Title
    pageSetting.Description = config.Description
    pageSetting.Layout      = "column2"
    pageSetting.ShowSidebar = true

    // showNext and showPrev button
    if pageId <= 0 || pageId > pageNums {
        pageId = 1
    }
    if pageId < pageNums {
        pageSetting.ShowPrev = true
    }
    if pageId != 1 {
        pageSetting.ShowNext = true
    }
    pageSetting.PrevPageID = pageId + 1
    pageSetting.NextPageID = pageId - 1

    // Get article data
    dbQuery          := datastore.NewQuery("Article").Order("-Date").Offset(offset).Limit(pageSize)
    articleData, err := getArticleData(dbQuery, true, c)
    if err != nil {
        serveError(c, w, err)
        return
    }

    // Get widget data
    dbQuery          = datastore.NewQuery("Widget").Order("Sequence")
    widgetData, err := getWidgetData(dbQuery, true, c)
    if err != nil {
        serveError(c, w, err)
        return
    }

    // New PageData
    pageData := &PageData{ User: userInfo, Article: articleData, Widget: widgetData }

    // New Page
    page := NewPage(pageSetting, pageData)

    // Render page
    page.Render("index", w)
}
開發者ID:fanflash,項目名稱:GoBlog,代碼行數:60,代碼來源:index.go


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