()
| 68 | } |
| 69 | |
| 70 | func (p *BodyParam) Encode() (string, error) { |
| 71 | switch p.contentType { |
| 72 | case ContentTypeJSON: |
| 73 | data, err := json.Marshal(p.params) |
| 74 | if err != nil { |
| 75 | return "", fmt.Errorf("body param encode error: %w", err) |
| 76 | } |
| 77 | return string(data), nil |
| 78 | case ContentTypeForm, ContentTypeFile: |
| 79 | data := url.Values{} |
| 80 | for k, v := range p.params { |
| 81 | data.Set(k, fmt.Sprintf("%v", v)) |
| 82 | } |
| 83 | return data.Encode(), nil |
| 84 | default: |
| 85 | return "", fmt.Errorf("unsupported content type: %s", p.contentType) |
| 86 | } |
| 87 | } |
no test coverage detected