示例#1
0
文件: app.go 项目: husio/apps
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},
		}),
	}
}
示例#2
0
文件: app.go 项目: husio/apps
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)},
		}),
	}
}