Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: da384a25cd
Fetching contributors…

Cannot retrieve contributors at this time

29 lines (24 sloc) 0.733 kb
// This code is in Public Domain. Take all the code you want, we'll just write more.
package main
import (
"fmt"
"net/http"
"path/filepath"
)
func serveFileFromDir(w http.ResponseWriter, r *http.Request, dir, fileName string) {
filePath := filepath.Join(dir, fileName)
if !PathExists(filePath) {
fmt.Printf("serveFileFromDir() file=%s doesn't exist\n", filePath)
}
http.ServeFile(w, r, filePath)
}
// handler for url: /s/
func handleStatic(w http.ResponseWriter, r *http.Request) {
file := r.URL.Path[len("/s/"):]
serveFileFromDir(w, r, "static", file)
}
// handler for url: /img/
func handleStaticImg(w http.ResponseWriter, r *http.Request) {
file := r.URL.Path[len("/img/"):]
serveFileFromDir(w, r, "img", file)
}
Jump to Line
Something went wrong with that request. Please try again.