зеркало из https://github.com/softlandia/samples.git
This commit is contained in:
Родитель
de8a83a430
Коммит
7fbfcae84e
|
@ -35,10 +35,13 @@ func qrGenerate(c *gin.Context) {
|
||||||
}
|
}
|
||||||
body, _ := ioutil.ReadAll(c.Request.Body)
|
body, _ := ioutil.ReadAll(c.Request.Body)
|
||||||
q := qrRequest{}
|
q := qrRequest{}
|
||||||
_ = json.Unmarshal(body, &q)
|
if err := json.Unmarshal(body, &q); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
c.String(400, "%s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
log.Println(q)
|
log.Println(q)
|
||||||
|
dataString := fmt.Sprintf(`{"employeeID":%d,"officeID":%d,"date":%s}`, q.EmployeeID, q.OfficeID, q.Date.Format("2006-01-02"))
|
||||||
dataString := fmt.Sprintf(`{\n"employeeID":%d,\n"officeID":%d,\n"date":%s\n}`, q.EmployeeID, q.OfficeID, q.Date)
|
|
||||||
qrCode, _ := qr.Encode(dataString, qr.L, qr.Auto)
|
qrCode, _ := qr.Encode(dataString, qr.L, qr.Auto)
|
||||||
qrCode, _ = barcode.Scale(qrCode, 512, 512)
|
qrCode, _ = barcode.Scale(qrCode, 512, 512)
|
||||||
b := bytes.NewBuffer([]byte{})
|
b := bytes.NewBuffer([]byte{})
|
||||||
|
|
|
@ -28,7 +28,7 @@ type Page struct {
|
||||||
{
|
{
|
||||||
userID: uint64,
|
userID: uint64,
|
||||||
officeID: uint64,
|
officeID: uint64,
|
||||||
date: 2020-11-28
|
date: 2009-11-10 23:00:00 +0000 UTC
|
||||||
}
|
}
|
||||||
в ответ получают png файл с картинкой
|
в ответ получают png файл с картинкой
|
||||||
*/
|
*/
|
||||||
|
@ -40,11 +40,21 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getQRHandler(w http.ResponseWriter, r *http.Request) {
|
func getQRHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
resp, err := http.Post("http://localhost:8080/qr", "application/json", bytes.NewReader([]byte(`{"employeeID":1,"officeID":2,"date":"2000-02-15"}`)))
|
resp, err := http.Post(
|
||||||
|
"http://localhost:8080/qr",
|
||||||
|
"application/json",
|
||||||
|
bytes.NewReader([]byte(`{"employeeID":1,"officeID":2,"date":"2020-02-15T20:15:00Z"}`)),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(w, "%v", err)
|
fmt.Fprintf(w, "%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
b := []byte{}
|
||||||
|
resp.Body.Read(b)
|
||||||
|
fmt.Fprintf(w, "qr-server return status: %d, body: %v", resp.StatusCode, string(b))
|
||||||
|
return
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
b, _ := ioutil.ReadAll(resp.Body)
|
b, _ := ioutil.ReadAll(resp.Body)
|
||||||
ioutil.WriteFile("data-resp.png", b, 0644)
|
ioutil.WriteFile("data-resp.png", b, 0644)
|
||||||
|
@ -57,11 +67,11 @@ func getQRHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
qrReader := qrcode.NewQRCodeReader()
|
qrReader := qrcode.NewQRCodeReader()
|
||||||
result, _ := qrReader.Decode(bmp, nil)
|
result, _ := qrReader.Decode(bmp, nil)
|
||||||
log.Println(result)
|
log.Println(result)
|
||||||
|
fmt.Fprintf(w, "%s", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func homeHandler(w http.ResponseWriter, r *http.Request) {
|
func homeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
p := Page{Title: "QR Code Generator"}
|
p := Page{Title: "QR Code Generator"}
|
||||||
|
|
||||||
t, _ := template.ParseFiles("generator.html")
|
t, _ := template.ParseFiles("generator.html")
|
||||||
t.Execute(w, p)
|
t.Execute(w, p)
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче