add form
parent
2a2ba16833
commit
74435682fa
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ggicci/httpin"
|
"github.com/ggicci/httpin"
|
||||||
|
|
@ -34,7 +35,6 @@ func Handle[In any, Out any](fn UnaryFunc[In, Out]) func(w http.ResponseWriter,
|
||||||
handleName := getHandleName(fn)
|
handleName := getHandleName(fn)
|
||||||
|
|
||||||
f := func(w http.ResponseWriter, r *http.Request) {
|
f := func(w http.ResponseWriter, r *http.Request) {
|
||||||
r.Header.Set("Content-Type", "application/json")
|
|
||||||
st := time.Now()
|
st := time.Now()
|
||||||
var err error
|
var err error
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
@ -139,6 +139,11 @@ func decodeReq[T any](r *http.Request) (*T, error) {
|
||||||
return in, nil
|
return in, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理表单请求
|
||||||
|
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
|
||||||
|
return in, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Post 请求等, 从body中获取
|
// Post 请求等, 从body中获取
|
||||||
body, err := io.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue