-
Notifications
You must be signed in to change notification settings - Fork 17
/
result.go
49 lines (42 loc) · 1.26 KB
/
result.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package epp
import (
"fmt"
"github.com/nbio/xx"
)
// Result represents an EPP <result> element.
type Result struct {
Code int `xml:"code,attr"`
Message string `xml:"msg"`
Reason string `xml:"extValue>reason,omitempty"`
}
// IsError determines whether an EPP status code is an error.
// https://tools.ietf.org/html/rfc5730#section-3
func (r *Result) IsError() bool {
return r.Code >= 2000
}
// IsFatal determines whether an EPP status code is a fatal response,
// and the connection should be closed.
// https://tools.ietf.org/html/rfc5730#section-3
func (r *Result) IsFatal() bool {
return r.Code >= 2500
}
// Error implements the error interface.
func (r *Result) Error() string {
return fmt.Sprintf("EPP result code %d: %s", r.Code, r.Message)
}
func init() {
path := "epp > response > result"
scanResponse.MustHandleStartElement(path, func(c *xx.Context) error {
res := c.Value.(*Response)
res.Result.Code = c.AttrInt("", "code")
return nil
})
scanResponse.MustHandleCharData(path+"> msg", func(c *xx.Context) error {
c.Value.(*Response).Result.Message = string(c.CharData)
return nil
})
scanResponse.MustHandleCharData(path+"> extValue > reason", func(c *xx.Context) error {
c.Value.(*Response).Result.Reason = string(c.CharData)
return nil
})
}