Skip to content

how to serving a FileSystem in mux #131

@xushaoxiao

Description

@xushaoxiao

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions