Documentation
¶
Index ¶
- Constants
- func MarshalJSON(s Serializable) ([]byte, error)
- type BufferedSerializer
- type JsonSerializer
- func (j *JsonSerializer) Begin()
- func (j *JsonSerializer) BeginBlock(optionalTitle string)
- func (j *JsonSerializer) BeginList(optionalTitle string)
- func (j *JsonSerializer) End()
- func (j *JsonSerializer) EndBlock()
- func (j *JsonSerializer) EndList()
- func (j *JsonSerializer) Error() error
- func (j *JsonSerializer) KeyBool(k string, v bool)
- func (j *JsonSerializer) KeyFloat(k string, v float64)
- func (j *JsonSerializer) KeyInt(k string, v int)
- func (j *JsonSerializer) KeyRaw(k string, v json.RawMessage, compact bool)
- func (j *JsonSerializer) KeyString(k, v string)
- func (j *JsonSerializer) Param(s string)
- func (j *JsonSerializer) Setup(w Writer, params map[string]string)
- func (j *JsonSerializer) String(v string, compact bool)
- type Serializable
- type Serializer
- type Writer
Constants ¶
const MinIndent = " "
Variables ¶
This section is empty.
Functions ¶
func MarshalJSON ¶
func MarshalJSON(s Serializable) ([]byte, error)
Types ¶
type BufferedSerializer ¶
type BufferedSerializer struct {
JsonSerializer
// We buffer the writer to prepend locals later
Original Writer
Buffer bytes.Buffer
Buffered *bufio.Writer
}
Serializer that collects output into a buffer
type JsonSerializer ¶
type JsonSerializer struct {
Writer Writer // Where to write
SupportParams bool // True to support parameter matching
ReverseParams map[string]string // match strings and turn into parameters
Matched map[string]string // Which params were matched
Depth int // indentation depth, if -1 then do not indent
Err error
// contains filtered or unexported fields
}
Serializes a JSON object to a string.
func (*JsonSerializer) BeginBlock ¶
func (j *JsonSerializer) BeginBlock(optionalTitle string)
BeginBlock opens a block with an optional key
func (*JsonSerializer) BeginList ¶
func (j *JsonSerializer) BeginList(optionalTitle string)
BeginList opens a list with an optional key
func (*JsonSerializer) Error ¶
func (j *JsonSerializer) Error() error
Error accumulates errors while encoding to check at the end
func (*JsonSerializer) KeyBool ¶
func (j *JsonSerializer) KeyBool(k string, v bool)
KeyBool dumps a key and value pair, value is bool
func (*JsonSerializer) KeyFloat ¶
func (j *JsonSerializer) KeyFloat(k string, v float64)
KeyFloat dumps a key and value pair, value is float
func (*JsonSerializer) KeyInt ¶
func (j *JsonSerializer) KeyInt(k string, v int)
KeyInt dumps a key and value pair, value is int
func (*JsonSerializer) KeyRaw ¶
func (j *JsonSerializer) KeyRaw(k string, v json.RawMessage, compact bool)
KeyRaw dumps a key and value pair, value is json.RawMessage
func (*JsonSerializer) KeyString ¶
func (j *JsonSerializer) KeyString(k, v string)
KeyString dumps a key and value pair, value is string
func (*JsonSerializer) Param ¶
func (j *JsonSerializer) Param(s string)
Param called on every string, to check if it must be replaced
func (*JsonSerializer) Setup ¶
func (j *JsonSerializer) Setup(w Writer, params map[string]string)
Setup must be called before starting serializing
func (*JsonSerializer) String ¶
func (j *JsonSerializer) String(v string, compact bool)
KeyString dumps a string
type Serializable ¶
type Serializable interface {
Serialize(Serializer)
}
Interfaz que permite serializar un objeto
type Serializer ¶
type Serializer interface {
KeyString(k, v string) // , "key": "val"
String(v string, compact bool) // , "val"
KeyInt(k string, v int) // , "key": val
KeyFloat(k string, v float64) // , "key": val
KeyBool(k string, v bool) // , "key": val
KeyRaw(k string, v json.RawMessage, compact bool) // , "key": val
BeginBlock(string) // { + omit first ","
EndBlock() // }
BeginList(string) // [ + omit first ","
EndList() // ]
Error() error // If it failed at any step
}