statik icon indicating copy to clipboard operation
statik copied to clipboard

how to serving a FileSystem in mux

Open xushaoxiao opened this issue 2 years ago • 0 comments

Hi teams,

I want to serving FileSystem handler in gorilla mux framework.

But always don't work well, show code:

import (
	"flag"
	"log"
	"net/http"
	"time"

	"github.com/gorilla/mux"
	"github.com/rakyll/statik/fs"

	_ "github.com/kubeflow/pipelines/backend/src/apiserver/openapi/generate/statik"
)

func main() {
	r := mux.NewRouter()
	// StatikFS serve.
	statikFS, _ := fs.New()
	r.PathPrefix("").Handler(http.StripPrefix("/swagger", http.FileServer(statikFS)))
	srv := &http.Server{
		Handler: r,
		Addr:    "127.0.0.1:8000",
		// Good practice: enforce timeouts for servers you create!
		WriteTimeout: 15 * time.Second,
		ReadTimeout:  15 * time.Second,
	}

	log.Printf("serving")

	log.Fatal(srv.ListenAndServe())
}

thanks

xushaoxiao avatar Feb 10 '23 08:02 xushaoxiao