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("