github.com/posener/gitfs@v1.2.2-0.20200410105819-ea4e48d73ab9/examples/godoc/godoc.go (about) 1 // An example locally serves files from github.com/golang/go/doc. 2 package main 3 4 import ( 5 "context" 6 "log" 7 "net/http" 8 9 "github.com/posener/gitfs" 10 ) 11 12 func main() { 13 ctx := context.Background() 14 fs, err := gitfs.New(ctx, "github.com/golang/go/doc") 15 if err != nil { 16 log.Fatalf("Failed initializing git filesystem: %s.", err) 17 } 18 http.Handle("/", http.RedirectHandler("/doc/", http.StatusMovedPermanently)) 19 http.Handle("/doc/", http.StripPrefix("/doc/", http.FileServer(fs))) 20 log.Printf("Listening on :8080") 21 log.Fatal(http.ListenAndServe(":8080", nil)) 22 }