Beispiel #1
0
func Library(res http.ResponseWriter, req *http.Request) {
	// sharedFiles = ListFiles(info.Dir())
	js, err := json.Marshal(sharedFiles)
	check(err)
	res.Header().Set("Content-Type", "application/json")
	res = info.SetCORS(res)
	if req.Method == "OPTIONS" {
		return
	}
	log.Print("Sending library")
	res.Write(js)
}
Beispiel #2
0
func Shared(res http.ResponseWriter, req *http.Request) {
	path := mux.Vars(req)["path"]
	res = info.SetCORS(res)
	if req.Method == "OPTIONS" {
		return
	}
	if _, ok := sharedFiles[path]; ok {
		log.Print("Serving file: " + path)
		http.ServeFile(res, req, info.Dir()+path)
	} else {
		log.Print("Blocking file: " + path)
		res.WriteHeader(404)
	}
}