簡化傳參

This commit is contained in:
2023-05-16 02:56:25 +08:00
parent a6a8f257a4
commit 9681b09b05
4 changed files with 42 additions and 49 deletions

View File

@@ -3,6 +3,7 @@ package utils
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"math/rand"
"net/http"
@@ -10,6 +11,20 @@ import (
"time"
)
func BodyRead(r *http.Request) (form map[string]interface{}) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Println(err)
return
}
defer r.Body.Close()
if err = json.Unmarshal(body, &form); err != nil {
log.Println(err)
return
}
return
}
// 獲取查詢參數(int 類型)
func ParamInt(value string, defaultValue int) int {
if value == "" {