Пример #1
0
func Routes(assetPath, clonesPath, sourcePath string) http.Handler {
	mux := httprouter.New()
	assetPath = filepath.Clean(assetPath)
	users, err := file.GetUserStore(filepath.Join(assetPath, "data"))
	if err != nil {
		log.Panic(err)
	}
	go func() {
		sigs := make(chan os.Signal, 1)
		signal.Notify(sigs, os.Interrupt, os.Kill)
		for s := range sigs {
			users.Close()
			log.Println("Closed Users")
			signal.Stop(sigs)
			signalSelf(s)
			break
		}
	}()
	v := &Views{
		assetPath:  assetPath,
		clonesPath: filepath.Clean(clonesPath),
		sourcePath: filepath.Clean(sourcePath),
		sessions:   mem.NewSessionMapStore("session"),
		users:      users,
		decoder:    schema.NewDecoder(),
	}
	mux.GET("/", v.Context(v.Index))
	mux.GET("/logout", v.Context(v.LoggedOut(v.Logout, "/")))
	mux.GET("/register", v.Context(v.LoggedInRedirect(v.Register, "/survey")))
	mux.POST("/register", v.Context(v.LoggedInRedirect(v.DoRegister, "/survey")))
	mux.GET("/login", v.Context(v.LoggedInRedirect(v.Login, "/survey")))
	mux.POST("/login", v.Context(v.LoggedInRedirect(v.DoLogin, "/survey")))
	mux.GET("/survey", v.Context(v.LoggedIn(v.Survey)))
	mux.GET("/survey/:clone", v.Context(v.LoggedIn(v.SurveyQuestion)))
	mux.POST("/survey/:clone", v.Context(v.LoggedIn(v.DoSurveyQuestion)))

	mux.GET("/clones/:clone/pattern.png", v.Context(v.LoggedIn(v.PatternImg)))
	mux.GET("/clones/:clone/instances/:instance/embedding.png", v.Context(v.LoggedIn(v.InstanceImg)))

	mux.ServeFiles("/static/*filepath", http.Dir(filepath.Join(assetPath, "static")))

	v.Init()
	return mux
}
Пример #2
0
func AnswerRoutes(assetPath, clonesPath, sourcePath string) http.Handler {
	mux := httprouter.New()
	assetPath = filepath.Clean(assetPath)
	v := &Views{
		assetPath:  assetPath,
		clonesPath: filepath.Clean(clonesPath),
		sourcePath: filepath.Clean(sourcePath),
		sessions:   mem.NewSessionMapStore("session"),
		users:      nil,
		decoder:    schema.NewDecoder(),
	}
	mux.GET("/", v.Context(v.Answers))
	mux.GET("/answers/:answer", v.Context(v.Answer))

	mux.GET("/clones/:clone/pattern.png", v.Context(v.PatternImg))
	mux.GET("/clones/:clone/instances/:instance/embedding.png", v.Context(v.InstanceImg))

	mux.ServeFiles("/static/*filepath", http.Dir(filepath.Join(assetPath, "static")))

	v.Init()
	return mux
}