代码拉取完成,页面将自动刷新
package form
import (
"encoding/json"
"github.com/emicklei/go-restful/v3"
)
const (
MIME_POST_FORM = "application/x-www-form-urlencoded"
)
// NewEntityAccessorJSON returns a new EntityReaderWriter for accessing Form content.
// This package is already initialized with such an accessor using the MIME_POST_FORM contentType.
func NewEntityAccessorPostForm() restful.EntityReaderWriter {
return entityPostFormAccess{ContentType: MIME_POST_FORM}
}
type entityPostFormAccess struct {
// This is used for setting the Content-Type header when writing
ContentType string
}
// Read unmarshalls the value from Form
func (e entityPostFormAccess) Read(req *restful.Request, v interface{}) error {
if err := req.Request.ParseForm(); err != nil {
return err
}
return mapForm(v, req.Request.PostForm)
}
// Write marshalls the value to Form and set the Content-Type Header.
func (e entityPostFormAccess) Write(resp *restful.Response, status int, v interface{}) error {
return writeJSON(resp, status, restful.MIME_JSON, v)
}
// write marshalls the value to YAML and set the Content-Type Header.
func writeJSON(resp *restful.Response, status int, contentType string, v interface{}) error {
if v == nil {
resp.WriteHeader(status)
// do not write a nil representation
return nil
}
resp.Header().Set(restful.HEADER_ContentType, contentType)
resp.WriteHeader(status)
return json.NewEncoder(resp).Encode(v)
}
func init() {
restful.RegisterEntityAccessor(MIME_POST_FORM, NewEntityAccessorPostForm())
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。