Adds StorageDriverFactory, unifying creation of StorageDrivers
Custom storage drivers can register a factory to create the driver by name, similar to the database/sql package's Register and Open factory.Create returns an in-process driver if registered or an IPC driver if one can be found, erroring otherwise This standardizes parameter passing for creation of storage drivers Also adds documentation for storagedriver package and children
This commit is contained in:
parent
ff81f3a719
commit
ca0084fad1
15 changed files with 290 additions and 79 deletions
|
@ -10,12 +10,16 @@ import (
|
|||
"github.com/docker/libchan"
|
||||
)
|
||||
|
||||
// Defines a remote method call request
|
||||
// A return value struct is to be sent over the ResponseChannel
|
||||
type Request struct {
|
||||
Type string
|
||||
Parameters map[string]interface{}
|
||||
ResponseChannel libchan.Sender
|
||||
}
|
||||
|
||||
// A simple wrapper around an io.ReadCloser that implements the io.ReadWriteCloser interface
|
||||
// Writes are disallowed and will return an error if ever called
|
||||
type noWriteReadWriteCloser struct {
|
||||
io.ReadCloser
|
||||
}
|
||||
|
@ -24,6 +28,8 @@ func (r noWriteReadWriteCloser) Write(p []byte) (n int, err error) {
|
|||
return 0, errors.New("Write unsupported")
|
||||
}
|
||||
|
||||
// Wraps an io.Reader as an io.ReadWriteCloser with a nop Close and unsupported Write method
|
||||
// Has no effect when an io.ReadWriteCloser is passed in
|
||||
func WrapReader(reader io.Reader) io.ReadWriteCloser {
|
||||
if readWriteCloser, ok := reader.(io.ReadWriteCloser); ok {
|
||||
return readWriteCloser
|
||||
|
@ -39,6 +45,7 @@ type responseError struct {
|
|||
Message string
|
||||
}
|
||||
|
||||
// Wraps an error in a serializable struct containing the error's type and message
|
||||
func ResponseError(err error) *responseError {
|
||||
if err == nil {
|
||||
return nil
|
||||
|
@ -53,29 +60,37 @@ func (err *responseError) Error() string {
|
|||
return fmt.Sprintf("%s: %s", err.Type, err.Message)
|
||||
}
|
||||
|
||||
// IPC method call response object definitions
|
||||
|
||||
// Response for a ReadStream request
|
||||
type ReadStreamResponse struct {
|
||||
Reader io.ReadWriteCloser
|
||||
Error *responseError
|
||||
}
|
||||
|
||||
// Response for a WriteStream request
|
||||
type WriteStreamResponse struct {
|
||||
Error *responseError
|
||||
}
|
||||
|
||||
// Response for a ResumeWritePosition request
|
||||
type ResumeWritePositionResponse struct {
|
||||
Position uint64
|
||||
Error *responseError
|
||||
}
|
||||
|
||||
// Response for a List request
|
||||
type ListResponse struct {
|
||||
Keys []string
|
||||
Error *responseError
|
||||
}
|
||||
|
||||
// Response for a Move request
|
||||
type MoveResponse struct {
|
||||
Error *responseError
|
||||
}
|
||||
|
||||
// Response for a Delete request
|
||||
type DeleteResponse struct {
|
||||
Error *responseError
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue