diff options
author | Přemysl Janouch <p@janouch.name> | 2019-04-12 23:10:42 +0200 |
---|---|---|
committer | Přemysl Janouch <p@janouch.name> | 2019-04-12 23:43:42 +0200 |
commit | 89fc9d86c727aa8dc80232b461a7903a3c16d10e (patch) | |
tree | 38cf909bf94ccb0c18943d8df95a36da04ec4bfd /label-exp/main.go | |
parent | 4c2f29384dc13f0e63393ac21ee33ee0881b750b (diff) | |
download | sklad-89fc9d86c727aa8dc80232b461a7903a3c16d10e.tar.gz sklad-89fc9d86c727aa8dc80232b461a7903a3c16d10e.tar.xz sklad-89fc9d86c727aa8dc80232b461a7903a3c16d10e.zip |
Cleanup, improve communication while printing
Diffstat (limited to 'label-exp/main.go')
-rw-r--r-- | label-exp/main.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/label-exp/main.go b/label-exp/main.go index e15f71c..dd4f8c2 100644 --- a/label-exp/main.go +++ b/label-exp/main.go @@ -182,7 +182,6 @@ func getStatus(printer *ql.Printer) error { if err := printer.UpdateStatus(); err != nil { return err } - log.Printf("status\n%s", printer.LastStatus) return nil } @@ -192,17 +191,23 @@ func handle(w http.ResponseWriter, r *http.Request) { return } - var initErr error + var ( + initErr error + mediaInfo *ql.MediaInfo + ) printer, printerErr := getPrinter() if printerErr == nil { defer printer.Close() - initErr = getStatus(printer) - } + printer.StatusNotify = func(status *ql.Status) { + log.Printf("\x1b[1mreceived status\x1b[m\n%s", status) + } - var mediaInfo *ql.MediaInfo - if printer.LastStatus != nil { - mediaInfo = ql.GetMediaInfo(printer.LastStatus.MediaWidthMM(), - printer.LastStatus.MediaLengthMM()) + if initErr = getStatus(printer); initErr == nil { + mediaInfo = ql.GetMediaInfo( + printer.LastStatus.MediaWidthMM(), + printer.LastStatus.MediaLengthMM(), + ) + } } var params = struct { @@ -269,7 +274,7 @@ func main() { log.Fatalln(err) } - log.Println("Starting server") + log.Println("starting server") http.HandleFunc("/", handle) log.Fatal(http.ListenAndServe(":8080", nil)) } |