Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to serving a FileSystem in mux #131

Open
xushaoxiao opened this issue Feb 10, 2023 · 0 comments
Open

how to serving a FileSystem in mux #131

xushaoxiao opened this issue Feb 10, 2023 · 0 comments

Comments

@xushaoxiao
Copy link

xushaoxiao commented Feb 10, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant