Documentation
¶
Overview ¶
Example ¶
package main import ( "context" "fmt" "github.com/PowerDNS/simpleblob" // Register the memory backend plugin _ "github.com/PowerDNS/simpleblob/backends/memory" ) func main() { // Do not forget the: // import _ "github.com/PowerDNS/simpleblob/backends/memory" ctx := context.Background() storage, err := simpleblob.GetBackend(ctx, "memory", map[string]interface{}{}) check(err) err = storage.Store(ctx, "example.txt", []byte("hello")) check(err) data, err := storage.Load(ctx, "example.txt") check(err) fmt.Println("data:", string(data)) list, err := storage.List(ctx, "") check(err) for _, entry := range list { fmt.Println("list:", entry.Name, entry.Size) } } func check(err error) { if err != nil { panic(err) } }
Output: data: hello list: example.txt 5
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterBackend ¶
RegisterBackend registers a new backend.
Types ¶
type BlobList ¶
type BlobList []Blob
BlobList is a slice of Blob structs
func (BlobList) WithPrefix ¶
WithPrefix filters the BlobList to returns only Blob structs where the name starts with the given prefix.
type InitFunc ¶
type InitFunc func(ctx context.Context, p InitParams) (Interface, error)
InitFunc is the type for the backend constructor function used to register backend.
type InitParams ¶
type InitParams struct {
OptionMap OptionMap // map of key-value options for this backend
}
InitParams contains the parameters for the InitFunc. This allows us to pass extra values in the future, without breaking existing backends that do not expect these.
func (InitParams) OptionsThroughYAML ¶
func (ip InitParams) OptionsThroughYAML(dest interface{}) error
OptionsThroughYAML performs a YAML roundtrip for the OptionMap to load them into a struct with yaml tags. dest: pointer to destination struct
type Interface ¶
type Interface interface { List(ctx context.Context, prefix string) (BlobList, error) Load(ctx context.Context, name string) ([]byte, error) Store(ctx context.Context, name string, data []byte) error }
Interface defines the interface storage plugins need to implement. This Interface MUST NOT be extended or changed without bumping the major version number, because it would break any backends in external repos. If you want to provide additional features, you can define additional optional interfaces that a backend can implement.
func GetBackend ¶
func GetBackend(ctx context.Context, typeName string, options map[string]interface{}) (Interface, error)
GetBackend creates a new backend instance of given typeName. This type must have been previously registered with RegisterBackend. A context is passed in case a backend needs to do checks that require remote calls. The options map contains backend dependant key-value options. Some backends take no options, others require some specific options.