Exemple #1
0
func main() {
	flag.Parse()

	var conf struct {
		Secret    string
		DbPath    string `toml:"database"`
		BooksPath string `toml:"library"`
		Uberich   struct {
			AppName    string
			AppURL     string
			UberichURL string
			Secret     string
		}
	}
	if _, err := toml.DecodeFile(*settingsPath, &conf); err != nil {
		log.Fatal("toml:", err)
	}

	store := uberich.NewStore(conf.Secret)
	uberich := uberich.NewClient(conf.Uberich.AppName, conf.Uberich.AppURL, conf.Uberich.UberichURL, conf.Uberich.Secret, store)

	db := data.Open(conf.DbPath)
	defer db.Close()

	es := events.New()
	defer es.Close()

	shield := func(h http.Handler) http.Handler {
		return uberich.Protect(h, http.NotFoundHandler())
	}

	route.Handle("/", mux.Method{"GET": uberich.Protect(handlers.List(true), handlers.List(false))})
	route.Handle("/books", shield(handlers.AllBooks(db, es)))
	route.Handle("/books/:id", shield(handlers.Books(db, es)))
	route.Handle("/editions/:id", shield(handlers.Editions(db, conf.BooksPath)))
	route.Handle("/upload", shield(handlers.Upload(db, es, conf.BooksPath)))

	route.Handle("/sign-in", uberich.SignIn("/"))
	route.Handle("/sign-out", uberich.SignOut("/"))
	route.Handle("/events", es)
	route.Handle("/assets/*filepath", http.StripPrefix("/assets/", assets.Server(map[string]string{
		"main.js":        assets.MainJs,
		"mustache.js":    assets.MustacheJs,
		"tablesorter.js": assets.TablesorterJs,
		"tablefilter.js": assets.TablefilterJs,
		"styles.css":     assets.StylesCss,
	})))

	serve.Serve(*port, *socket, filters.Log(route.Default))
}
Exemple #2
0
Fichier : ggg.go Projet : hawx/ggg
func main() {
	var (
		settingsPath = flag.String("settings", "./settings.toml", "Path to 'settings.toml'")
		port         = flag.String("port", "8080", "Port to run on")
		socket       = flag.String("socket", "", "")
	)
	flag.Parse()

	var conf *Conf
	if _, err := toml.DecodeFile(*settingsPath, &conf); err != nil {
		log.Fatal("toml: ", err)
	}

	db := repos.Open(conf.DbPath, conf.GitDir)
	defer db.Close()

	store := uberich.NewStore(conf.Secret)
	uberich := uberich.NewClient(conf.Uberich.AppName, conf.Uberich.AppURL, conf.Uberich.UberichURL, conf.Uberich.Secret, store)

	shield := func(h http.Handler) http.Handler {
		return uberich.Protect(h, http.NotFoundHandler())
	}

	list := handlers.List(db, conf.Title, conf.URL)
	repo := handlers.Repo(db, conf.Title, conf.URL, uberich.Protect)

	route.Handle("/", mux.Method{"GET": uberich.Protect(list.All, list.Public)})

	route.HandleFunc("/:name/*path", func(w http.ResponseWriter, r *http.Request) {
		vars := route.Vars(r)

		if strings.HasSuffix(vars["name"], ".git") {
			repo.Git.ServeHTTP(w, r)
			return
		}

		repo.Html.ServeHTTP(w, r)
	})
	route.Handle("/:name/edit", shield(handlers.Edit(db, conf.Title)))
	route.Handle("/:name/delete", shield(handlers.Delete(db)))

	route.Handle("/-/create", shield(handlers.Create(db, conf.Title)))
	route.Handle("/-/sign-in", uberich.SignIn("/"))
	route.Handle("/-/sign-out", uberich.SignOut("/"))

	route.Handle("/assets/styles.css", mux.Method{"GET": assets.Styles})

	serve.Serve(*port, *socket, filters.Log(route.Default))
}
Exemple #3
0
func main() {
	var (
		settingsPath = flag.String("settings", "./settings.toml", "")
		port         = flag.String("port", "8081", "")
		socket       = flag.String("socket", "", "")
	)
	flag.Usage = func() { fmt.Println(help) }
	flag.Parse()

	if flag.NArg() == 0 {
		fmt.Println(help)
		return
	}

	opmlPath := flag.Arg(0)

	var conf *Conf
	if _, err := toml.DecodeFile(*settingsPath, &conf); err != nil {
		log.Fatal("toml: ", err)
	}

	store := uberich.NewStore(conf.Secret)
	uberich := uberich.NewClient(conf.Uberich.AppName, conf.Uberich.AppURL, conf.Uberich.UberichURL, conf.Uberich.Secret, store)

	shield := func(h http.Handler) http.Handler {
		return uberich.Protect(h, http.NotFoundHandler())
	}

	http.Handle("/", mux.Method{
		"GET": uberich.Protect(
			handlers.List(opmlPath, conf.URL, conf.PathPrefix),
			handlers.Login(conf.URL, conf.PathPrefix),
		),
	})
	http.Handle("/subscribe", shield(mux.Method{
		"GET": handlers.Subscribe(opmlPath, conf.PathPrefix),
	}))
	http.Handle("/unsubscribe", shield(mux.Method{
		"GET": handlers.Unsubscribe(opmlPath, conf.PathPrefix),
	}))
	http.Handle("/sign-in", uberich.SignIn(conf.PathPrefix))
	http.Handle("/sign-out", uberich.SignOut(conf.PathPrefix))

	serve.Serve(*port, *socket, Log(http.DefaultServeMux))
}
Exemple #4
0
func main() {
	var (
		settingsPath = flag.String("settings", "./settings.toml", "")
		port         = flag.String("port", "8080", "")
		socket       = flag.String("socket", "", "")
	)
	flag.Parse()

	var conf *Conf
	if _, err := toml.DecodeFile(*settingsPath, &conf); err != nil {
		log.Fatal("toml:", err)
	}

	db := database.Open(conf.DbPath, conf.Horizon)
	defer db.Close()

	es := eventsource.New(nil, nil)
	defer es.Close()

	store := uberich.NewStore(conf.Secret)
	uberich := uberich.NewClient(conf.Uberich.AppName, conf.Uberich.AppURL, conf.Uberich.UberichURL, conf.Uberich.Secret, store)

	shield := func(h http.Handler) http.Handler {
		return uberich.Protect(h, http.NotFoundHandler())
	}

	http.Handle("/", uberich.Protect(List(conf, db, true), List(conf, db, false)))
	http.Handle("/add", shield(Add(conf, db, es)))
	http.Handle("/preview", shield(Preview))
	http.Handle("/feed", Feed(conf, db))
	http.Handle("/connect", es)

	http.Handle("/sign-in", uberich.SignIn("/"))
	http.Handle("/sign-out", uberich.SignOut("/"))

	http.Handle("/assets/", http.StripPrefix("/assets/", assets.Server(map[string]string{
		"jquery.caret.js":        assets.Caret,
		"jquery.autosize.min.js": assets.AutoSize,
		"styles.css":             assets.Styles,
		"list.js":                assets.List,
	})))

	serve.Serve(*port, *socket, Log(http.DefaultServeMux))
}