Webseite ausgebaut und QR-Codes werden für Ordner erzeugt
This commit is contained in:
parent
8e42684a57
commit
176dfefa84
11
README.md
11
README.md
@ -1,2 +1,9 @@
|
|||||||
# golangtest
|
# Go test App
|
||||||
|
|
||||||
|
Zum Kompilieren folgende Go-Abhängigkeiten installieren:
|
||||||
|
- `go get github.com/gorilla/mux`
|
||||||
|
- `go get github.com/boombuler/barcode`
|
||||||
|
- `go get github.com/boombuler/barcode/qr`
|
||||||
|
|
||||||
|
Kompilieren mit: `go build main.go`
|
||||||
|
|
||||||
|
30
main.go
30
main.go
@ -3,22 +3,28 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image/png"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
"github.com/boombuler/barcode"
|
||||||
|
"github.com/boombuler/barcode/qr"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
var StartUpPath string
|
var StartUpPath string
|
||||||
|
|
||||||
|
// our main function
|
||||||
func main() {
|
func main() {
|
||||||
StartUpPath = "Fotos" //dir
|
StartUpPath = "C:/Fotos" //dir
|
||||||
|
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.HandleFunc("/folder/{foldername:.*}", GetFolderContent).Methods("GET")
|
router.HandleFunc("/folder/{foldername:.*}", GetFolderContent).Methods("GET")
|
||||||
router.PathPrefix("/img/").Handler(http.StripPrefix("/img/", http.FileServer(http.Dir(StartUpPath)))).Methods("GET")
|
router.HandleFunc("/qr/{qrlink:.*}", GetQRCode).Methods("GET")
|
||||||
|
router.PathPrefix("/img/").Handler(http.StripPrefix("/img/", http.FileServer(http.Dir("C:/Fotos")))).Methods("GET")
|
||||||
router.PathPrefix("/").Handler(http.FileServer(http.Dir("web"))).Methods("GET")
|
router.PathPrefix("/").Handler(http.FileServer(http.Dir("web"))).Methods("GET")
|
||||||
log.Fatal(http.ListenAndServe(":8000", router))
|
log.Fatal(http.ListenAndServe(":8000", router))
|
||||||
}
|
}
|
||||||
@ -40,3 +46,23 @@ func GetFolderContent(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
json.NewEncoder(w).Encode(dateien)
|
json.NewEncoder(w).Encode(dateien)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetQRCode(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
// Variablen auswerten
|
||||||
|
params := mux.Vars(r)
|
||||||
|
pQRLink := params["qrlink"]
|
||||||
|
|
||||||
|
// QR-Code erstellen
|
||||||
|
qrCode, _ := qr.Encode(pQRLink, qr.M, qr.Auto)
|
||||||
|
|
||||||
|
// Größe festlegen
|
||||||
|
qrCode, _ = barcode.Scale(qrCode, 200, 200)
|
||||||
|
|
||||||
|
// Datei erstellen
|
||||||
|
file, _ := os.Create("qrcode.png")
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
// Datei ausgeben
|
||||||
|
png.Encode(w, qrCode)
|
||||||
|
}
|
||||||
|
0
qrcode.png
Normal file
0
qrcode.png
Normal file
@ -16,11 +16,19 @@
|
|||||||
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
ShowHomePage();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
function ShowHomePage() {
|
||||||
|
|
||||||
|
$("#Ordner").empty();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
contentType:'application/json; charset=utf-8',
|
contentType:'application/json; charset=utf-8',
|
||||||
url: ServerAPI+'/folder/2019-11-15',
|
url: ServerAPI+'/folder/',
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data: "",
|
data: "",
|
||||||
success: function(content){
|
success: function(content){
|
||||||
@ -28,15 +36,43 @@
|
|||||||
//http://127.0.0.1:8000/img/2019-11-15/IMG_4186.JPG
|
//http://127.0.0.1:8000/img/2019-11-15/IMG_4186.JPG
|
||||||
for ( var i = 0, l = content.length; i < l; i++ ) {
|
for ( var i = 0, l = content.length; i < l; i++ ) {
|
||||||
var ObjInhalt = content[i];
|
var ObjInhalt = content[i];
|
||||||
$("#Ordner").append("<li>"+
|
$("#Ordner").append(""+
|
||||||
"<img src=\""+ServerAPI+"/img/2019-11-15/"+ObjInhalt+"\" width=100 height=100>"+
|
"<img src=\""+ServerAPI+"/qr/"+ServerAPI+"/dir/"+ObjInhalt+"\" width=150 height=150>"+
|
||||||
"<a href=\"#\" onclick=\"ShowFolder('"+ObjInhalt+"')\">"+
|
"<a href=\"#\" onclick=\"ShowFolderPics('"+ObjInhalt+"')\">"+
|
||||||
ObjInhalt+"</a></li>");
|
ObjInhalt+"</a><hr>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
}
|
||||||
|
|
||||||
|
function ShowFolderPics(folder) {
|
||||||
|
|
||||||
|
// Ordner div leeren
|
||||||
|
$("#Ordner").empty();
|
||||||
|
$("#Ordner").append('<a href="#" onclick=ShowHomePage()>Zurück</a><hr>');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "GET",
|
||||||
|
contentType:'application/json; charset=utf-8',
|
||||||
|
url: ServerAPI+'/folder/'+folder,
|
||||||
|
dataType: "json",
|
||||||
|
data: "",
|
||||||
|
success: function(content){
|
||||||
|
|
||||||
|
//http://127.0.0.1:8000/img/2019-11-15/IMG_4186.JPG
|
||||||
|
for ( var i = 0, l = content.length; i < l; i++ ) {
|
||||||
|
var ObjInhalt = content[i];
|
||||||
|
$("#Ordner").append(""+
|
||||||
|
"<img src=\""+ServerAPI+"/img/"+folder+"/"+ObjInhalt+"\" width=100 height=100>"+
|
||||||
|
"<a href=\""+ServerAPI+"/img/"+folder+"/"+ObjInhalt+"\">"+
|
||||||
|
ObjInhalt+"</a><hr>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user