簡化傳參
This commit is contained in:
@@ -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 == "" {
|
||||
|
Reference in New Issue
Block a user