Updates documentation to follow godoc conventions

This commit is contained in:
Brian Bland 2014-10-29 12:14:19 -07:00
parent ca0084fad1
commit 0e5d41ff9b
9 changed files with 84 additions and 64 deletions

View file

@ -15,7 +15,8 @@ import (
"github.com/docker/libchan/spdy"
)
// Storage Driver implementation using a managed child process communicating over IPC
// StorageDriverClient is a storagedriver.StorageDriver implementation using a managed child process
// communicating over IPC using libchan with a unix domain socket
type StorageDriverClient struct {
subprocess *exec.Cmd
socket *os.File
@ -23,8 +24,9 @@ type StorageDriverClient struct {
sender libchan.Sender
}
// Constructs a new out-of-process storage driver using the driver name and configuration parameters
// Must call Start() on this driver client before remote method calls can be made
// NewDriverClient constructs a new out-of-process storage driver using the driver name and
// configuration parameters
// A user must call Start on this driver client before remote method calls can be made
//
// Looks for drivers in the following locations in order:
// - Storage drivers directory (to be determined, yet not implemented)
@ -54,7 +56,8 @@ func NewDriverClient(name string, parameters map[string]string) (*StorageDriverC
}, nil
}
// Starts the designated child process storage driver and binds a socket to this process for IPC
// Start starts the designated child process storage driver and binds a socket to this process for
// IPC method calls
func (driver *StorageDriverClient) Start() error {
fileDescriptors, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM, 0)
if err != nil {
@ -102,8 +105,8 @@ func (driver *StorageDriverClient) Start() error {
return nil
}
// Stops the child process storage driver
// storagedriver.StorageDriver methods called after Stop() will fail
// Stop stops the child process storage driver
// storagedriver.StorageDriver methods called after Stop will fail
func (driver *StorageDriverClient) Stop() error {
closeSenderErr := driver.sender.Close()
closeTransportErr := driver.transport.Close()

View file

@ -10,7 +10,7 @@ import (
"github.com/docker/libchan"
)
// Defines a remote method call request
// Request defines a remote method call request
// A return value struct is to be sent over the ResponseChannel
type Request struct {
Type string
@ -18,8 +18,9 @@ type Request struct {
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
// noWriteReadWriteCloser is a simple wrapper around an io.ReadCloser that implements the
// io.ReadWriteCloser interface
// Calls to Write are disallowed and will return an error
type noWriteReadWriteCloser struct {
io.ReadCloser
}
@ -28,7 +29,7 @@ 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
// WrapReader wraps an io.Reader as an io.ReadWriteCloser with a nop Close and unsupported Write
// Has no effect when an io.ReadWriteCloser is passed in
func WrapReader(reader io.Reader) io.ReadWriteCloser {
if readWriteCloser, ok := reader.(io.ReadWriteCloser); ok {
@ -45,7 +46,7 @@ type responseError struct {
Message string
}
// Wraps an error in a serializable struct containing the error's type and message
// ResponseError wraps an error in a serializable struct containing the error's type and message
func ResponseError(err error) *responseError {
if err == nil {
return nil
@ -62,35 +63,35 @@ func (err *responseError) Error() string {
// IPC method call response object definitions
// Response for a ReadStream request
// ReadStreamResponse is a response for a ReadStream request
type ReadStreamResponse struct {
Reader io.ReadWriteCloser
Error *responseError
}
// Response for a WriteStream request
// WriteStreamResponse is a response for a WriteStream request
type WriteStreamResponse struct {
Error *responseError
}
// Response for a ResumeWritePosition request
// ResumeWritePositionResponse is a response for a ResumeWritePosition request
type ResumeWritePositionResponse struct {
Position uint64
Error *responseError
}
// Response for a List request
// ListResponse is a response for a List request
type ListResponse struct {
Keys []string
Error *responseError
}
// Response for a Move request
// MoveResponse is a response for a Move request
type MoveResponse struct {
Error *responseError
}
// Response for a Delete request
// DeleteResponse is a response for a Delete request
type DeleteResponse struct {
Error *responseError
}

View file

@ -13,10 +13,13 @@ import (
"github.com/docker/libchan/spdy"
)
// Construct a new IPC server handling requests for the given storagedriver.StorageDriver
// This explicitly uses file descriptor 3 for IPC communication, as storage drivers are spawned in client.go
// StorageDriverServer runs a new IPC server handling requests for the given
// storagedriver.StorageDriver
// This explicitly uses file descriptor 3 for IPC communication, as storage drivers are spawned in
// client.go
//
// To create a new out-of-process driver, create a main package which calls StorageDriverServer with a storagedriver.StorageDriver
// To create a new out-of-process driver, create a main package which calls StorageDriverServer with
// a storagedriver.StorageDriver
func StorageDriverServer(driver storagedriver.StorageDriver) error {
childSocket := os.NewFile(3, "childSocket")
defer childSocket.Close()
@ -39,9 +42,10 @@ func StorageDriverServer(driver storagedriver.StorageDriver) error {
}
}
// Receives new storagedriver.StorageDriver method requests and creates a new goroutine to handle each request
//
// Requests are expected to be of type ipc.Request as the parameters are unknown until the request type is deserialized
// receive receives new storagedriver.StorageDriver method requests and creates a new goroutine to
// handle each request
// Requests are expected to be of type ipc.Request as the parameters are unknown until the request
// type is deserialized
func receive(driver storagedriver.StorageDriver, receiver libchan.Receiver) {
for {
var request Request
@ -53,7 +57,7 @@ func receive(driver storagedriver.StorageDriver, receiver libchan.Receiver) {
}
}
// Handles storagedriver.StorageDriver method requests as defined in client.go
// handleRequest handles storagedriver.StorageDriver method requests as defined in client.go
// Responds to requests using the Request.ResponseChannel
func handleRequest(driver storagedriver.StorageDriver, request Request) {
switch request.Type {