Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compressor ¶
type Compressor interface {
// Compress compresses the provided data and returns the result or an error if compression fails.
Compress([]byte) ([]byte, error)
// Decompress decompresses the provided data and returns the result or an error if decompression fails.
Decompress([]byte) ([]byte, error)
// Name returns the name of the compressor.
Name() string
}
Compressor defines an interface for data compression and decompression algorithms. It provides methods to compress and decompress byte slices, as well as a method to retrieve the compressor's name.
type Encoder ¶
type Encoder interface {
// Encode serializes the given value into a byte slice.
//
// Example:
// data, err := encoder.Encode("hello world")
// if err != nil {
// log.Fatal(err)
// }
// fmt.Println("Encoded:", data)
Encode(ctx context.Context, v any) ([]byte, error)
// Decode deserializes the given byte slice into the provided destination.
//
// Example:
// var s string
// err := encoder.Decode([]byte(`"hello world"`), &s)
// if err != nil {
// log.Fatal(err)
// }
// fmt.Println("Decoded:", s)
Decode(ctx context.Context, data []byte, v any) error
}
Encoder defines how values are serialized and deserialized when stored or retrieved from a backend in KiviGo.
KiviGo uses encoders to convert Go values (structs, strings, etc.) into a byte slice for storage, and to decode byte slices back into Go values when reading from the backend. This allows you to use different formats (JSON, YAML, etc.) or implement your own encoding logic.
Example: using the JSON encoder, a struct will be marshaled to JSON before being saved in the database.