Пример #1
0
func main() {
	session, err := mgo.Dial("localhost")
	if err != nil {
		panic(err)
	}
	defer session.Close()
	session.SetMode(mgo.Monotonic, true)
	ensureIndex(session)

	mux := goji.NewMux()
	mux.HandleFuncC(pat.Get("/books"), allBooks(session))
	mux.HandleFuncC(pat.Post("/books"), addBook(session))
	mux.HandleFuncC(pat.Get("/books/:isbn"), bookByISBN(session))
	mux.HandleFuncC(pat.Put("/books/:isbn"), updateBook(session))
	mux.HandleFuncC(pat.Delete("/books/:isbn"), deleteBook(session))
	http.ListenAndServe("localhost:8080", mux)
}
Пример #2
0
}

var Routes = struct {
	CreateUser, GetUser,
	GetAnimals,
	ListMoods, SetMood, GetMood, DeleteMood,
	ListConversations, CreateConversation, GetConversation, DeleteConversation,
	CreateLine, GetLine, DeleteLine *pat.Pattern
}{
	CreateUser: pat.Post("/users"),
	GetUser:    pat.Get("/users/:id"),

	GetAnimals: pat.Get("/animals"),

	ListMoods:  pat.Get("/moods"),
	SetMood:    pat.Put("/moods/:mood"),
	GetMood:    pat.Get("/moods/:mood"),
	DeleteMood: pat.Delete("/moods/:mood"),

	ListConversations:  pat.Get("/conversations"),
	CreateConversation: pat.Post("/conversations"),
	GetConversation:    pat.Get("/conversations/:conversation"),
	DeleteConversation: pat.Delete("/conversations/:conversation"),

	CreateLine: pat.Post("/conversations/:conversation/lines"),
	GetLine:    pat.Get("/conversations/:conversation/lines/:line"),
	DeleteLine: pat.Delete("/conversations/:conversation/lines/:line"),
}

// App encapsulates the handlers for the saypi API
type App struct {
Пример #3
0
func (m *Mux) Put(pattern string, handler goji.Handler, doc *Doc) {
	muxMap(m, "put", pattern, handler, doc)
	m.webmux.HandleC(pat.Put(pattern), handler)
}
Пример #4
0
func main() {

	log.Println("localhost:4242")

	// Connection a la base de donnee
	initdatabase()
	defer database.Close()

	gob.Register(UserData{})
	gob.Register(InscriptionForm{})

	mux := goji.NewMux()

	mux.HandleFunc(pat.Get("/"), home)

	// Creation d'un compte
	mux.HandleFunc(pat.Get("/inscription"), inscription)
	mux.HandleFunc(pat.Post("/users"), postUsers)

	// Connexion Deconnexion utilisateur
	mux.HandleFunc(pat.Post("/login"), login)
	mux.HandleFunc(pat.Get("/logout"), logout)
	mux.HandleFunc(pat.Get("/me"), connectedUser)

	// User's interests Road
	mux.HandleFunc(pat.Post("/users/me/interests/"), postUsersInterests)
	mux.HandleFunc(pat.Get("/users/me/interests/"), getUsersInterests)
	mux.HandleFuncC(pat.Delete("/users/me/interests/:interestid"), deleteUsersInterests)
	// User's age Road
	mux.HandleFunc(pat.Put("/users/me/age/"), postUsersAge)
	mux.HandleFunc(pat.Get("/users/me/age/"), getUsersAge)
	// User's username Road
	mux.HandleFunc(pat.Put("/users/me/username/"), postUsersUsername)
	mux.HandleFunc(pat.Get("/users/me/username/"), getUsersUsername)
	// User's firstname Road
	mux.HandleFunc(pat.Put("/users/me/firstname/"), postUsersFirstName)
	mux.HandleFunc(pat.Get("/users/me/firstname/"), getUsersFirstName)
	// User's lastname Road
	mux.HandleFunc(pat.Put("/users/me/lastname/"), postUsersLastName)
	mux.HandleFunc(pat.Get("/users/me/lastname/"), getUsersLastName)
	// User's Bio Road
	mux.HandleFunc(pat.Put("/users/me/bio/"), uptdateUsersBio)

	// Public Profile
	mux.HandleFuncC(pat.Get("/users/:id"), publicProfile)
	mux.HandleFuncC(pat.Put("/users/:id/like/"), likeAnUser)
	mux.HandleFuncC(pat.Put("/users/:id/unlike/"), unlikeAnUser)
	// Notifications
	mux.HandleFuncC(pat.Put("/notifications/:id"), setReadNotifications)
	mux.HandleFunc(pat.Get("/notifications/"), getNotifications)

	//Matches
	mux.HandleFunc(pat.Get("/users/me/matches/"), getUsersMatches)

	// Interests
	mux.HandleFunc(pat.Post("/interests/"), postInterests)

	// Chat

	mux.HandleFuncC(pat.Get("/chat/:chatname"), RootHandler)
	mux.Handle(pat.Get("/sock"), websocket.Handler(SockServer))

	// Static Files
	mux.HandleFunc(pat.Get("/css/*"), staticCssFiles)
	mux.HandleFunc(pat.Get("/js/*"), staticJsFiles)

	log.Fatal(http.ListenAndServe(LISTEN_PORT, mux))

}