-
Notifications
You must be signed in to change notification settings - Fork 12
/
errors.go
49 lines (41 loc) · 891 Bytes
/
errors.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 gobizflyErr
import (
"bytes"
"html/template"
)
var tmpl = template.New("GobizflyTemplate")
type GobizflyErr struct {
Message string
Code string
Metadata map[string]interface{}
}
func (err GobizflyErr) Error() string {
message := err.GetMessage()
return message
}
func (err GobizflyErr) String() string {
message := err.GetMessage()
return message
}
func (err GobizflyErr) GetMessage() string {
newTmpl, tmplErr := tmpl.Parse(err.Message)
if tmplErr != nil {
return err.Message
}
var result bytes.Buffer
tmplErr = newTmpl.Execute(&result, err.Metadata)
if tmplErr != nil {
return err.Message
}
return result.String()
}
func (err GobizflyErr) SetMetadata(metadata map[string]interface{}) GobizflyErr {
err.Metadata = metadata
return err
}
var (
InvalidRegion = GobizflyErr{
Message: "Invalid region {{.Region}}",
Code: "InvalidRegion",
}
)