wo-bisch-web/order.go

34 lines
677 B
Go

package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
type order_struct struct {
Quantity string
Email string
DeliveryAdress string
BillingAdress string
}
// order handler
func orderHandler(response http.ResponseWriter, request *http.Request) {
body, err := ioutil.ReadAll(request.Body)
if err != nil {
panic(err)
}
log.Println(string(body))
sendOrderEmail("joerg.lehmann@nbit.ch", string(body))
var t order_struct
err = json.Unmarshal(body, &t)
if err != nil {
log.Println("Error, invalid json: %v", err)
}
response.Header().Set("Content-Type", "text/json; charset=utf-8")
fmt.Fprintln(response, string(body))
}