Exemple #1
0
func NewApplication(ctx context.Context) http.Handler {
	statics := http.FileServer(http.Dir("."))
	handleStatics := func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		statics.ServeHTTP(w, r)
	}
	handleUI := func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, "gallery/statics/index.html")
	}

	return &application{
		ctx: ctx,
		rt: web.NewRouter(web.Routes{
			{`/`, web.RedirectHandler("/ui/", http.StatusMovedPermanently), "GET"},
			{`/ui/.*`, handleUI, "GET"},

			{`/api/v1/images`, handleUploadImage, "PUT"},
			{`/api/v1/images`, handleListImages, "GET"},
			{`/api/v1/images/{id}\.jpg`, handleServeImage, "GET"},
			{`/api/v1/images/{id}/tags`, handleTagImage, "PUT"},
			{`/api/v1/images/{id}`, handleImageDetails, "GET"},

			{`.*`, handleStatics, "GET"},

			{`.*`, web.StdJSONHandler(http.StatusNotFound), web.AnyMethod},
		}),
	}
}
Exemple #2
0
func NewApplication(ctx context.Context) http.Handler {
	return &application{
		ctx: ctx,
		rt: web.NewRouter(web.Routes{
			{"POST", `/`, handleAuthenticate},
			{"GET", `/key/{key-id}`, handlePublicKey},

			{web.AnyMethod, `.*`, web.StdJSONHandler(http.StatusNotFound)},
		}),
	}
}