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