Variablen / Funktions-Namen umbenannt und Code aufgeräumt
This commit is contained in:
		
							
								
								
									
										30
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								main.go
									
									
									
									
									
								
							| @@ -17,27 +17,27 @@ import ( | ||||
| 	"github.com/gorilla/mux" | ||||
| ) | ||||
|  | ||||
| var StartUpPath string | ||||
| var imgPath = "C:/Fotos" | ||||
|  | ||||
| // our main function | ||||
| func main() { | ||||
| 	StartUpPath = "C:/Fotos" //dir | ||||
|  | ||||
| 	router := mux.NewRouter() | ||||
| 	router.HandleFunc("/folder/{foldername:.*}", GetFolderContent).Methods("GET") | ||||
| 	router.HandleFunc("/qr/{qrlink:.*}", GetQRCode).Methods("GET") | ||||
| 	router.HandleFunc("/thumb/{imgname:.*}", GetThumbNail).Methods("GET") | ||||
| 	router.PathPrefix("/img/").Handler(http.StripPrefix("/img/", http.FileServer(http.Dir("C:/Fotos")))).Methods("GET") | ||||
| 	router.HandleFunc("/folder/{foldername:.*}", getFolderContent).Methods("GET") | ||||
| 	router.HandleFunc("/qr/{qrlink:.*}", getQRCode).Methods("GET") | ||||
| 	router.HandleFunc("/thumb/{imgname:.*}", getThumbNail).Methods("GET") | ||||
| 	router.PathPrefix("/img/").Handler(http.StripPrefix("/img/", http.FileServer(http.Dir(imgPath)))).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) { | ||||
| 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)) | ||||
| 	fmt.Println(path.Join(imgPath, pFolder)) | ||||
| 	files, err := ioutil.ReadDir(path.Join(imgPath, pFolder)) | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
| @@ -52,7 +52,7 @@ func GetFolderContent(w http.ResponseWriter, r *http.Request) { | ||||
| 	json.NewEncoder(w).Encode(dateien) | ||||
| } | ||||
|  | ||||
| func GetQRCode(w http.ResponseWriter, r *http.Request) { | ||||
| func getQRCode(w http.ResponseWriter, r *http.Request) { | ||||
|  | ||||
| 	// Variablen auswerten | ||||
| 	params := mux.Vars(r) | ||||
| @@ -72,16 +72,16 @@ func GetQRCode(w http.ResponseWriter, r *http.Request) { | ||||
| 	png.Encode(w, qrCode) | ||||
| } | ||||
|  | ||||
| func GetThumbNail(w http.ResponseWriter, r *http.Request) { | ||||
| func getThumbNail(w http.ResponseWriter, r *http.Request) { | ||||
|  | ||||
| 	// Variablen auswerten | ||||
| 	params := mux.Vars(r) | ||||
| 	pIMGName := params["imgname"] | ||||
|  | ||||
| 	// Das Thumbnail soll nur generiert werden wenn es noch nicht existiert | ||||
| 	if !fileExists(StartUpPath + "/" + pIMGName + ".thumb.jpg") { | ||||
| 	if !fileExists(imgPath + "/" + pIMGName + ".thumb.jpg") { | ||||
| 		//  Originaldatei öffnen, welche angefragt wird | ||||
| 		src, err := imaging.Open(StartUpPath + "/" + pIMGName) | ||||
| 		src, err := imaging.Open(imgPath + "/" + pIMGName) | ||||
| 		if err != nil { | ||||
| 			log.Fatalf("failed to open image: %v", err) | ||||
| 		} | ||||
| @@ -89,7 +89,7 @@ func GetThumbNail(w http.ResponseWriter, r *http.Request) { | ||||
| 		// Foto auf 200px skalieren | ||||
| 		src = imaging.Resize(src, 200, 0, imaging.NearestNeighbor) | ||||
|  | ||||
| 		err = imaging.Save(src, StartUpPath+"/"+pIMGName+".thumb.jpg") | ||||
| 		err = imaging.Save(src, imgPath+"/"+pIMGName+".thumb.jpg") | ||||
| 		if err != nil { | ||||
| 			log.Fatalf("failed to save image: %v", err) | ||||
| 		} | ||||
| @@ -98,7 +98,7 @@ func GetThumbNail(w http.ResponseWriter, r *http.Request) { | ||||
| 		png.Encode(w, src) | ||||
| 	} else { | ||||
|  | ||||
| 		src, err := imaging.Open(StartUpPath + "/" + pIMGName + ".thumb.jpg") | ||||
| 		src, err := imaging.Open(imgPath + "/" + pIMGName + ".thumb.jpg") | ||||
| 		if err != nil { | ||||
| 			log.Fatalf("failed to open image: %v", err) | ||||
| 		} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user