github.com/wfusion/gofusion@v1.1.14/http/parser/application_x_www_form_urlencoded.go (about)

     1  package parser
     2  
     3  import (
     4  	"io"
     5  	"net/url"
     6  	"reflect"
     7  )
     8  
     9  type ApplicationFormUrlencodedParser struct{}
    10  
    11  func (a *ApplicationFormUrlencodedParser) PreParse(args map[string]string) error {
    12  	return nil
    13  }
    14  
    15  func (a *ApplicationFormUrlencodedParser) Parse(src io.Reader, dst reflect.Value) (err error) {
    16  	body, err := io.ReadAll(src)
    17  	if err != nil {
    18  		return
    19  	}
    20  
    21  	vals, err := url.ParseQuery(string(body))
    22  	if err != nil {
    23  		return
    24  	}
    25  
    26  	return MapFormByTag(dst.Addr().Interface(), vals, "json")
    27  }