43 lines
981 B
Go
43 lines
981 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"io/ioutil"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
"path"
|
||
|
|
||
|
"github.com/gorilla/mux"
|
||
|
)
|
||
|
|
||
|
var StartUpPath string
|
||
|
|
||
|
func main() {
|
||
|
StartUpPath = "Fotos" //dir
|
||
|
|
||
|
router := mux.NewRouter()
|
||
|
router.HandleFunc("/folder/{foldername:.*}", GetFolderContent).Methods("GET")
|
||
|
router.PathPrefix("/img/").Handler(http.StripPrefix("/img/", http.FileServer(http.Dir(StartUpPath)))).Methods("GET")
|
||
|
router.PathPrefix("/").Handler(http.FileServer(http.Dir("web"))).Methods("GET")
|
||
|
log.Fatal(http.ListenAndServe(":8000", router))
|
||
|
}
|
||
|
|
||
|
func GetFolderContent(w http.ResponseWriter, r *http.Request) {
|
||
|
|
||
|
params := mux.Vars(r)
|
||
|
pFolder := params["foldername"]
|
||
|
fmt.Println(path.Join(StartUpPath, pFolder))
|
||
|
files, err := ioutil.ReadDir(path.Join(StartUpPath, pFolder))
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
var dateien []string
|
||
|
for _, f := range files {
|
||
|
dateien = append(dateien, f.Name())
|
||
|
}
|
||
|
|
||
|
json.NewEncoder(w).Encode(dateien)
|
||
|
}
|