From 176dfefa84e08c20537d763ec96e3e558d3e1c83 Mon Sep 17 00:00:00 2001 From: "Sven.Schmalle" Date: Wed, 20 Nov 2019 21:58:42 +0100 Subject: [PATCH] =?UTF-8?q?Webseite=20ausgebaut=20und=20QR-Codes=20werden?= =?UTF-8?q?=20f=C3=BCr=20Ordner=20erzeugt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 +++++++++-- main.go | 30 ++++++++++++++++++++++++++++-- qrcode.png | 0 web/index.html | 50 +++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 qrcode.png diff --git a/README.md b/README.md index 140f6f3..48037e0 100644 --- a/README.md +++ b/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` + diff --git a/main.go b/main.go index ae47d51..780310b 100644 --- a/main.go +++ b/main.go @@ -3,22 +3,28 @@ package main import ( "encoding/json" "fmt" + "image/png" "io/ioutil" "log" "net/http" + "os" "path" + "github.com/boombuler/barcode" + "github.com/boombuler/barcode/qr" "github.com/gorilla/mux" ) var StartUpPath string +// our main function func main() { - StartUpPath = "Fotos" //dir + StartUpPath = "C:/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.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") log.Fatal(http.ListenAndServe(":8000", router)) } @@ -40,3 +46,23 @@ func GetFolderContent(w http.ResponseWriter, r *http.Request) { 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) +} diff --git a/qrcode.png b/qrcode.png new file mode 100644 index 0000000..e69de29 diff --git a/web/index.html b/web/index.html index 41d5ee9..5109a68 100644 --- a/web/index.html +++ b/web/index.html @@ -16,11 +16,19 @@ $(document).ready(function() { + + ShowHomePage(); + + }); + + function ShowHomePage() { + + $("#Ordner").empty(); $.ajax({ method: "GET", contentType:'application/json; charset=utf-8', - url: ServerAPI+'/folder/2019-11-15', + url: ServerAPI+'/folder/', dataType: "json", data: "", success: function(content){ @@ -28,15 +36,43 @@ //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("
  • "+ - ""+ - ""+ - ObjInhalt+"
  • "); + $("#Ordner").append(""+ + ""+ + ""+ + ObjInhalt+"
    "); } } }); - - }); + + } + + function ShowFolderPics(folder) { + + // Ordner div leeren + $("#Ordner").empty(); + $("#Ordner").append('Zurück
    '); + + $.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(""+ + ""+ + ""+ + ObjInhalt+"
    "); + } + } + }); + + } +