package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", handlePostForm)
err := http.ListenAndServe(":8102", nil)
if err != nil {
log.Fatal(err)
}
}
func handlePostForm(writer http.ResponseWriter, request *http.Request) {
fmt.Println(request.Method)
buf := bytes.NewBuffer(make([]byte, 0, 512))
length, _ := buf.ReadFrom(request.Body)
fmt.Println(string(buf.Bytes()))
fmt.Println(length)
type sendMsg struct {
Code string `json:"code"`
Message string `json:"message"`
Data struct
{
Message string `json:"message"`
}`json:"data"`
}
var sendBodyMsg sendMsg
sendBodyMsg.Code = "200"
sendBodyMsg.Message = "ok"
sendBodyMsg.Data.Message = "success"
bt, _ := json.Marshal(sendBodyMsg)
io.WriteString(writer, string(bt))
}