增加yaml/xml结果解析
This commit is contained in:
parent
696d31b0f2
commit
2d69d673ec
16
result.go
16
result.go
@ -10,9 +10,12 @@ package rpc
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"encoding/xml"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// parseResponseBody 解析响应body, 支持 json + xml + ini + yaml
|
// parseResponseBody 解析响应body, 支持 json + xml + ini + yaml
|
||||||
@ -46,6 +49,7 @@ func parseResponseBody(responseType string, body []byte, receiver interface{}) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
var parser *result
|
var parser *result
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
parser = &result{}
|
parser = &result{}
|
||||||
parser = &result{}
|
parser = &result{}
|
||||||
@ -71,7 +75,8 @@ func (r *result) ParseJSON(inputContent []byte, receiver interface{}) error {
|
|||||||
//
|
//
|
||||||
// Date : 18:34 2022/6/30
|
// Date : 18:34 2022/6/30
|
||||||
func (r *result) ParseYaml(inputContent []byte, receiver interface{}) error {
|
func (r *result) ParseYaml(inputContent []byte, receiver interface{}) error {
|
||||||
return nil
|
decoder := yaml.NewDecoder(bytes.NewReader(inputContent))
|
||||||
|
return decoder.Decode(receiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseXml 解析xml数据
|
// ParseXml 解析xml数据
|
||||||
@ -80,9 +85,14 @@ func (r *result) ParseYaml(inputContent []byte, receiver interface{}) error {
|
|||||||
//
|
//
|
||||||
// Date : 18:35 2022/6/30
|
// Date : 18:35 2022/6/30
|
||||||
func (r *result) ParseXml(inputContent []byte, receiver interface{}) error {
|
func (r *result) ParseXml(inputContent []byte, receiver interface{}) error {
|
||||||
return nil
|
return xml.Unmarshal(inputContent, receiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseIni 解析ini
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 11:11 2022/7/1
|
||||||
func (r *result) ParseIni(inputContent []byte, receiver interface{}) error {
|
func (r *result) ParseIni(inputContent []byte, receiver interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user