Exemple #1
0
package hello

import (
	"fmt"
	"net/http"

	"code.google.com/p/gorilla/mux"
	"code.google.com/p/gorilla/sessions"

	gaeSessions "code.google.com/p/gorilla/appengine/sessions"
)

var router = new(mux.Router)
var store = sessions.NewCookieStore([]byte("my-secret-key"),
	[]byte("1234567890123456"))
var dStore = gaeSessions.NewDatastoreStore("", []byte("my-secret-key"),
	[]byte("1234567890123456"))
var mStore = gaeSessions.NewMemcacheStore("", []byte("my-secret-key"),
	[]byte("1234567890123456"))

func init() {
	// Register a couple of routes.
	router.HandleFunc("/", homeHandler).Name("home")
	router.HandleFunc("/{salutation}/{name}", helloHandler).Name("hello")
	router.HandleFunc("/datastore-session", datastoreSessionHandler).Name("datastore-session")
	router.HandleFunc("/cookie-session", cookieSessionHandler).Name("cookie-session")
	router.HandleFunc("/memcache-session", memcacheSessionHandler).Name("memcache-session")
	// Send all incoming requests to router.
	http.Handle("/", router)
}

func homeHandler(w http.ResponseWriter, r *http.Request) {
Exemple #2
0
// +build appengine

package tap

import (
	"appengine"
	"appengine/datastore"
	"appengine/urlfetch"
	"code.google.com/p/gorilla/appengine/sessions"
	"net/http"
)

var (
	Session = sessions.NewDatastoreStore("", []byte("go-tap-very-secret"))
)

func (s *Server) getUserData(screen_name string, r *http.Request) (u UserData, err error) {
	u, ok := s.UserData[screen_name]
	if !ok {
		switch s.ServerType {
		case 0:
			c := appengine.NewContext(r)
			q := datastore.NewQuery("UserData").Filter("ScreenName =", screen_name)
			t := q.Run(c)
			_, err = t.Next(&u)
		case 1:
		}
	}
	return
}