-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarshaler.go
48 lines (41 loc) · 1.42 KB
/
marshaler.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
package astconf
import (
"fmt"
"io"
"reflect"
)
// Marshaler is the interface implemented by types that can marshal
// themselves into valid asterisk configuration blocks.
//
// The provided encoder is only valid for the duration of the call. Marshalers
// must not retain a reference to e.
type Marshaler interface {
MarshalAsterisk(e *Encoder) error
}
// ObjectMarshaler is the interface implemented by types that can marshal
// themselves into valid asterisk configuration objects.
type ObjectMarshaler interface {
MarshalAsteriskObject(w io.Writer) error
}
// SettingMarshaler is the interface implemented by types that can marshal
// themselves into valid asterisk configuration settings.
type SettingMarshaler interface {
MarshalAsteriskSetting(w io.Writer) error
}
// PreambleMarshaler is the interface implemented by types that marshal a
// an asterisk configuration preamble in addition to their regular value.
//
// The provided encoder is only valid for the duration of the call. Marshalers
// must not retain a reference to e.
type PreambleMarshaler interface {
MarshalAsteriskPreamble(e *Encoder) error
}
// MarshalerError is returned when a custom marshaling function encounters an error.
type MarshalerError struct {
Type reflect.Type
Err error
call string // The type of marshaler
}
func (e *MarshalerError) Error() string {
return fmt.Sprintf("astconf: error calling %s for type %s: %s", e.call, e.Type, e.Err)
}