Exemplo n.º 1
0
func main() {
	app := ess.NewApplication("user-signup-example")

	http.HandleFunc("/", ShowSignupForm)
	http.Handle("/signups", HandleSignup(app))
	log.Fatal(http.ListenAndServe("localhost:8080", nil))
}
Exemplo n.º 2
0
func main() {
	logger := log.New(os.Stderr, "blog ", 0)
	store, err := ess.NewEventsOnDisk("events.json", ess.SystemClock)
	if err != nil {
		logger.Fatal(err)
	}

	allPostsInMemory := NewAllPostsInMemory()
	allSessionsInMemory := NewAllSessionsInMemory()
	application := ess.NewApplication("blog").
		WithLogger(logger).
		WithStore(store).
		WithProjection("all-posts", allPostsInMemory).
		WithProjection("all-sessions", allSessionsInMemory)

	if err := application.Init(); err != nil {
		logger.Fatal(err)
	}

	http.Handle("/sessions", &SessionsResource{app: application, allSessions: allSessionsInMemory})
	http.Handle("/sessions/", &SessionsResource{app: application, allSessions: allSessionsInMemory})
	http.Handle("/signups", &SignupsResource{app: application})
	http.Handle("/posts/", &PostResource{app: application, allPosts: allPostsInMemory, allSessions: allSessionsInMemory})
	http.Handle("/posts", &PostsResource{app: application, allSessions: allSessionsInMemory})
	http.Handle("/", &IndexResource{app: application, allPosts: allPostsInMemory, allSessions: allSessionsInMemory})

	logger.Fatal(http.ListenAndServe(args(args(os.Args[1:]...), "localhost:6060"), nil))
}