Skip to content
This repository was archived by the owner on Feb 9, 2025. It is now read-only.

Commit d169488

Browse files
committed
🔥 feat: add ReplyXML method
1 parent 1414374 commit d169488

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

docs/api/ctx.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,30 @@ func Handler(ctx *volta.Ctx) error {
208208
```
209209
{% endcode %}
210210

211+
## ReplyXML
212+
213+
Function to reply to a message with automatically xml marshal.
214+
215+
body: interface{} - The message body to reply with.
216+
217+
{% code title="Signature" lineNumbers="true" %}
218+
```go
219+
func (ctx *Ctx) ReplyXML(body interface{}) error
220+
```
221+
{% endcode %}
222+
223+
{% code title="Example" lineNumbers="true" %}
224+
```go
225+
type User struct {
226+
Name string `xml:"name"`
227+
}
228+
229+
func Handler(ctx *volta.Ctx) error {
230+
return ctx.ReplyXML(&User{Name: "John"})
231+
}
232+
```
233+
{% endcode %}
234+
211235
## ContentType
212236

213237
Function to get the message content type.

volta_context.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ func (ctx *Ctx) ReplyJSON(data interface{}) error {
4545
return ctx.Reply(jsonData)
4646
}
4747

48+
func (ctx *Ctx) ReplyXML(data interface{}) error {
49+
xmlData, err := xml.Marshal(data)
50+
if err != nil {
51+
return err
52+
}
53+
54+
return ctx.Reply(xmlData)
55+
}
56+
4857
func (ctx *Ctx) Next() error {
4958
ctx.handlerCursor++
5059
if ctx.handlerCursor < len(ctx.handlers) {

0 commit comments

Comments
 (0)