fasthttp.RequestCtx 使用範例
simplejson "github.com/bitly/go-simplejson"
取得header 變數
signature := string(ctx.Request.Header.Peek("X-Hub88-Signature"))
取得json格式資訊
js, jerr := simplejson.NewJson([]byte(ctx.PostBody()))
token := js.Get("token").MustString()
取得formData資訊
mapped := FormDataToMap(ctx.PostBody())
secret_key := mapped["secret_key"]
func FormDataToMap(frmdat []byte) map[string]string {
formStr := string(frmdat)
pathParams := make(map[string]string)
decoded, err := url.PathUnescape(formStr)
if err != nil {
logrus.Error(err)
return nil
}
m, err := url.ParseQuery(decoded)
if err != nil {
logrus.Error(err)
return nil
}
for _, v := range strings.Split(formStr, "&") {
oneA := strings.Split(v, "=")
if len(oneA) > 1 {
key := oneA[0]
param := m.Get(key)
pathParams[key] = fmt.Sprintf("%v", param)
}
}
return pathParams
}
留言列表