Organized the current server code

This commit is contained in:
2024-05-03 16:00:45 +01:00
parent d0281cffd4
commit 511cd8a570
3 changed files with 66 additions and 44 deletions
+28
View File
@@ -0,0 +1,28 @@
package server
import (
"fmt"
"io"
"net/http"
thermalprinter "thermalPrinter/thermalPrinter"
)
func printMessage(message string) {
printer := thermalprinter.GetInstance(nil)
printer.Print(message)
}
func LaunchServer(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
if !authenticate(w, r) {
return
}
data, _ := io.ReadAll(r.Body)
fmt.Println(string(data))
// printMessage(string(data) + "\n\n\n\n\n")
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"message": "welcome to thermics"}`))
}