Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 0e5d41f

Browse files
committed
Updates documentation to follow godoc conventions
1 parent ca0084f commit 0e5d41f

File tree

9 files changed

+84
-64
lines changed

9 files changed

+84
-64
lines changed

storagedriver/factory/factory.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"github.com/docker/docker-registry/storagedriver/ipc"
88
)
99

10-
// Internal mapping between storage driver names and their respective factories
10+
// driverFactories stores an internal mapping between storage driver names and their respective
11+
// factories
1112
var driverFactories = make(map[string]StorageDriverFactory)
1213

13-
// Factory interface for the storagedriver.StorageDriver interface
14+
// StorageDriverFactory is a factory interface for creating storagedriver.StorageDriver interfaces
1415
// Storage drivers should call Register() with a factory to make the driver available by name
1516
type StorageDriverFactory interface {
16-
// Creates and returns a new storagedriver.StorageDriver with the given parameters
17+
// Create returns a new storagedriver.StorageDriver with the given parameters
1718
// Parameters will vary by driver and may be ignored
1819
// Each parameter key must only consist of lowercase letters and numbers
1920
Create(parameters map[string]string) (storagedriver.StorageDriver, error)
@@ -54,7 +55,7 @@ func Create(name string, parameters map[string]string) (storagedriver.StorageDri
5455
return driverFactory.Create(parameters)
5556
}
5657

57-
// Error returned when attempting to construct an unregistered storage driver
58+
// InvalidStorageDriverError records an attempt to construct an unregistered storage driver
5859
type InvalidStorageDriverError struct {
5960
Name string
6061
}

storagedriver/filesystem/filesystem.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ func init() {
1818
factory.Register(DriverName, &filesystemDriverFactory{})
1919
}
2020

21-
// Implements the factory.StorageDriverFactory interface
21+
// filesystemDriverFactory implements the factory.StorageDriverFactory interface
2222
type filesystemDriverFactory struct{}
2323

2424
func (factory *filesystemDriverFactory) Create(parameters map[string]string) (storagedriver.StorageDriver, error) {
2525
return FromParameters(parameters), nil
2626
}
2727

28-
// Storage Driver backed by a local filesystem
28+
// FilesystemDriver is a storagedriver.StorageDriver implementation backed by a local filesystem
2929
// All provided paths will be subpaths of the RootDirectory
3030
type FilesystemDriver struct {
3131
rootDirectory string
3232
}
3333

34-
// Constructs a new FilesystemDriver with a given parameters map
34+
// FromParameters constructs a new FilesystemDriver with a given parameters map
3535
// Optional Parameters:
3636
// - rootdirectory
3737
func FromParameters(parameters map[string]string) *FilesystemDriver {
@@ -45,11 +45,12 @@ func FromParameters(parameters map[string]string) *FilesystemDriver {
4545
return New(rootDirectory)
4646
}
4747

48-
// Constructs a new FilesystemDriver with a given rootDirectory
48+
// New constructs a new FilesystemDriver with a given rootDirectory
4949
func New(rootDirectory string) *FilesystemDriver {
5050
return &FilesystemDriver{rootDirectory}
5151
}
5252

53+
// subPath returns the absolute path of a key within the FilesystemDriver's storage
5354
func (d *FilesystemDriver) subPath(subPath string) string {
5455
return path.Join(d.rootDirectory, subPath)
5556
}

storagedriver/inmemory/inmemory.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,27 @@ func init() {
1919
factory.Register(DriverName, &inMemoryDriverFactory{})
2020
}
2121

22-
// Implements the factory.StorageDriverFactory interface
22+
// inMemoryDriverFacotry implements the factory.StorageDriverFactory interface
2323
type inMemoryDriverFactory struct{}
2424

2525
func (factory *inMemoryDriverFactory) Create(parameters map[string]string) (storagedriver.StorageDriver, error) {
2626
return New(), nil
2727
}
2828

29-
// InMemory Storage Driver backed by a map
29+
// InMemoryDriver is a storagedriver.StorageDriver implementation backed by a local map
3030
// Intended solely for example and testing purposes
3131
type InMemoryDriver struct {
3232
storage map[string][]byte
3333
mutex sync.RWMutex
3434
}
3535

36-
// Constructs a new InMemoryDriver
36+
// New constructs a new InMemoryDriver
3737
func New() *InMemoryDriver {
3838
return &InMemoryDriver{storage: make(map[string][]byte)}
3939
}
4040

41+
// Implement the storagedriver.StorageDriver interface
42+
4143
func (d *InMemoryDriver) GetContent(path string) ([]byte, error) {
4244
d.mutex.RLock()
4345
defer d.mutex.RUnlock()

storagedriver/ipc/client.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ import (
1515
"github.com/docker/libchan/spdy"
1616
)
1717

18-
// Storage Driver implementation using a managed child process communicating over IPC
18+
// StorageDriverClient is a storagedriver.StorageDriver implementation using a managed child process
19+
// communicating over IPC using libchan with a unix domain socket
1920
type StorageDriverClient struct {
2021
subprocess *exec.Cmd
2122
socket *os.File
2223
transport *spdy.Transport
2324
sender libchan.Sender
2425
}
2526

26-
// Constructs a new out-of-process storage driver using the driver name and configuration parameters
27-
// Must call Start() on this driver client before remote method calls can be made
27+
// NewDriverClient constructs a new out-of-process storage driver using the driver name and
28+
// configuration parameters
29+
// A user must call Start on this driver client before remote method calls can be made
2830
//
2931
// Looks for drivers in the following locations in order:
3032
// - Storage drivers directory (to be determined, yet not implemented)
@@ -54,7 +56,8 @@ func NewDriverClient(name string, parameters map[string]string) (*StorageDriverC
5456
}, nil
5557
}
5658

57-
// Starts the designated child process storage driver and binds a socket to this process for IPC
59+
// Start starts the designated child process storage driver and binds a socket to this process for
60+
// IPC method calls
5861
func (driver *StorageDriverClient) Start() error {
5962
fileDescriptors, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM, 0)
6063
if err != nil {
@@ -102,8 +105,8 @@ func (driver *StorageDriverClient) Start() error {
102105
return nil
103106
}
104107

105-
// Stops the child process storage driver
106-
// storagedriver.StorageDriver methods called after Stop() will fail
108+
// Stop stops the child process storage driver
109+
// storagedriver.StorageDriver methods called after Stop will fail
107110
func (driver *StorageDriverClient) Stop() error {
108111
closeSenderErr := driver.sender.Close()
109112
closeTransportErr := driver.transport.Close()

storagedriver/ipc/ipc.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ import (
1010
"github.com/docker/libchan"
1111
)
1212

13-
// Defines a remote method call request
13+
// Request defines a remote method call request
1414
// A return value struct is to be sent over the ResponseChannel
1515
type Request struct {
1616
Type string
1717
Parameters map[string]interface{}
1818
ResponseChannel libchan.Sender
1919
}
2020

21-
// A simple wrapper around an io.ReadCloser that implements the io.ReadWriteCloser interface
22-
// Writes are disallowed and will return an error if ever called
21+
// noWriteReadWriteCloser is a simple wrapper around an io.ReadCloser that implements the
22+
// io.ReadWriteCloser interface
23+
// Calls to Write are disallowed and will return an error
2324
type noWriteReadWriteCloser struct {
2425
io.ReadCloser
2526
}
@@ -28,7 +29,7 @@ func (r noWriteReadWriteCloser) Write(p []byte) (n int, err error) {
2829
return 0, errors.New("Write unsupported")
2930
}
3031

31-
// Wraps an io.Reader as an io.ReadWriteCloser with a nop Close and unsupported Write method
32+
// WrapReader wraps an io.Reader as an io.ReadWriteCloser with a nop Close and unsupported Write
3233
// Has no effect when an io.ReadWriteCloser is passed in
3334
func WrapReader(reader io.Reader) io.ReadWriteCloser {
3435
if readWriteCloser, ok := reader.(io.ReadWriteCloser); ok {
@@ -45,7 +46,7 @@ type responseError struct {
4546
Message string
4647
}
4748

48-
// Wraps an error in a serializable struct containing the error's type and message
49+
// ResponseError wraps an error in a serializable struct containing the error's type and message
4950
func ResponseError(err error) *responseError {
5051
if err == nil {
5152
return nil
@@ -62,35 +63,35 @@ func (err *responseError) Error() string {
6263

6364
// IPC method call response object definitions
6465

65-
// Response for a ReadStream request
66+
// ReadStreamResponse is a response for a ReadStream request
6667
type ReadStreamResponse struct {
6768
Reader io.ReadWriteCloser
6869
Error *responseError
6970
}
7071

71-
// Response for a WriteStream request
72+
// WriteStreamResponse is a response for a WriteStream request
7273
type WriteStreamResponse struct {
7374
Error *responseError
7475
}
7576

76-
// Response for a ResumeWritePosition request
77+
// ResumeWritePositionResponse is a response for a ResumeWritePosition request
7778
type ResumeWritePositionResponse struct {
7879
Position uint64
7980
Error *responseError
8081
}
8182

82-
// Response for a List request
83+
// ListResponse is a response for a List request
8384
type ListResponse struct {
8485
Keys []string
8586
Error *responseError
8687
}
8788

88-
// Response for a Move request
89+
// MoveResponse is a response for a Move request
8990
type MoveResponse struct {
9091
Error *responseError
9192
}
9293

93-
// Response for a Delete request
94+
// DeleteResponse is a response for a Delete request
9495
type DeleteResponse struct {
9596
Error *responseError
9697
}

storagedriver/ipc/server.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ import (
1313
"github.com/docker/libchan/spdy"
1414
)
1515

16-
// Construct a new IPC server handling requests for the given storagedriver.StorageDriver
17-
// This explicitly uses file descriptor 3 for IPC communication, as storage drivers are spawned in client.go
16+
// StorageDriverServer runs a new IPC server handling requests for the given
17+
// storagedriver.StorageDriver
18+
// This explicitly uses file descriptor 3 for IPC communication, as storage drivers are spawned in
19+
// client.go
1820
//
19-
// To create a new out-of-process driver, create a main package which calls StorageDriverServer with a storagedriver.StorageDriver
21+
// To create a new out-of-process driver, create a main package which calls StorageDriverServer with
22+
// a storagedriver.StorageDriver
2023
func StorageDriverServer(driver storagedriver.StorageDriver) error {
2124
childSocket := os.NewFile(3, "childSocket")
2225
defer childSocket.Close()
@@ -39,9 +42,10 @@ func StorageDriverServer(driver storagedriver.StorageDriver) error {
3942
}
4043
}
4144

42-
// Receives new storagedriver.StorageDriver method requests and creates a new goroutine to handle each request
43-
//
44-
// Requests are expected to be of type ipc.Request as the parameters are unknown until the request type is deserialized
45+
// receive receives new storagedriver.StorageDriver method requests and creates a new goroutine to
46+
// handle each request
47+
// Requests are expected to be of type ipc.Request as the parameters are unknown until the request
48+
// type is deserialized
4549
func receive(driver storagedriver.StorageDriver, receiver libchan.Receiver) {
4650
for {
4751
var request Request
@@ -53,7 +57,7 @@ func receive(driver storagedriver.StorageDriver, receiver libchan.Receiver) {
5357
}
5458
}
5559

56-
// Handles storagedriver.StorageDriver method requests as defined in client.go
60+
// handleRequest handles storagedriver.StorageDriver method requests as defined in client.go
5761
// Responds to requests using the Request.ResponseChannel
5862
func handleRequest(driver storagedriver.StorageDriver, request Request) {
5963
switch request.Type {

storagedriver/s3/s3.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,33 @@ import (
1515

1616
const DriverName = "s3"
1717

18-
// Chunks need to be at least 5MB to store with a multipart upload on S3
18+
// minChunkSize defines the minimum multipart upload chunk size
19+
// S3 API requires multipart upload chunks to be at least 5MB
1920
const minChunkSize = uint64(5 * 1024 * 1024)
2021

21-
// The largest amount of parts you can request from S3
22+
// listPartsMax is the largest amount of parts you can request from S3
2223
const listPartsMax = 1000
2324

2425
func init() {
2526
factory.Register(DriverName, &s3DriverFactory{})
2627
}
2728

28-
// Implements the factory.StorageDriverFactory interface
29+
// s3DriverFactory implements the factory.StorageDriverFactory interface
2930
type s3DriverFactory struct{}
3031

3132
func (factory *s3DriverFactory) Create(parameters map[string]string) (storagedriver.StorageDriver, error) {
3233
return FromParameters(parameters)
3334
}
3435

35-
// Storage Driver backed by Amazon S3
36+
// S3Driver is a storagedriver.StorageDriver implementation backed by Amazon S3
3637
// Objects are stored at absolute keys in the provided bucket
3738
type S3Driver struct {
3839
S3 *s3.S3
3940
Bucket *s3.Bucket
4041
Encrypt bool
4142
}
4243

43-
// Constructs a new S3Driver with a given parameters map
44+
// FromParameters constructs a new S3Driver with a given parameters map
4445
// Required parameters:
4546
// - accesskey
4647
// - secretkey
@@ -84,7 +85,8 @@ func FromParameters(parameters map[string]string) (*S3Driver, error) {
8485
return New(accessKey, secretKey, region, encryptBool, bucket)
8586
}
8687

87-
// Constructs a new S3Driver with the given AWS credentials, region, encryption flag, and bucketName
88+
// New constructs a new S3Driver with the given AWS credentials, region, encryption flag, and
89+
// bucketName
8890
func New(accessKey string, secretKey string, region aws.Region, encrypt bool, bucketName string) (*S3Driver, error) {
8991
auth := aws.Auth{AccessKey: accessKey, SecretKey: secretKey}
9092
s3obj := s3.New(auth, region)
@@ -100,6 +102,8 @@ func New(accessKey string, secretKey string, region aws.Region, encrypt bool, bu
100102
return &S3Driver{s3obj, bucket, encrypt}, nil
101103
}
102104

105+
// Implement the storagedriver.StorageDriver interface
106+
103107
func (d *S3Driver) GetContent(path string) ([]byte, error) {
104108
return d.Bucket.Get(path)
105109
}

storagedriver/storagedriver.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,45 @@ import (
55
"io"
66
)
77

8-
// Defines methods that a Storage Driver must implement for a filesystem-like key/value object storage
8+
// StorageDriver defines methods that a Storage Driver must implement for a filesystem-like
9+
// key/value object storage
910
type StorageDriver interface {
10-
// Retrieve the content stored at "path" as a []byte
11+
// GetContent retrieves the content stored at "path" as a []byte
1112
// Should primarily be used for small objects
1213
GetContent(path string) ([]byte, error)
1314

14-
// Store the []byte content at a location designated by "path"
15+
// PutContent stores the []byte content at a location designated by "path"
1516
// Should primarily be used for small objects
1617
PutContent(path string, content []byte) error
1718

18-
// Retrieve an io.ReadCloser for the content stored at "path" with a given byte offset
19+
// ReadStream retrieves an io.ReadCloser for the content stored at "path" with a given byte
20+
// offset
1921
// May be used to resume reading a stream by providing a nonzero offset
2022
ReadStream(path string, offset uint64) (io.ReadCloser, error)
2123

22-
// Store the contents of the provided io.ReadCloser at a location designated by "path"
24+
// WriteStream stores the contents of the provided io.ReadCloser at a location designated by
25+
// the given path
2326
// The driver will know it has received the full contents when it has read "size" bytes
2427
// May be used to resume writing a stream by providing a nonzero offset
2528
// The offset must be no larger than the number of bytes already written to this path
2629
WriteStream(path string, offset, size uint64, readCloser io.ReadCloser) error
2730

28-
// Retrieve the byte offset at which it is safe to continue writing at "path"
31+
// ResumeWritePosition retrieves the byte offset at which it is safe to continue writing at the
32+
// given path
2933
ResumeWritePosition(path string) (uint64, error)
3034

31-
// Recursively lists the objects stored at a subpath of the given prefix
35+
// List recursively lists the objects stored at a subpath of the given prefix
3236
List(prefix string) ([]string, error)
3337

34-
// Moves an object stored at sourcePath to destPath, removing the original object
38+
// Move moves an object stored at sourcePath to destPath, removing the original object
3539
// Note: This may be no more efficient than a copy followed by a delete for many implementations
3640
Move(sourcePath string, destPath string) error
3741

38-
// Recursively deletes all objects stored at "path" and its subpaths
42+
// Delete recursively deletes all objects stored at "path" and its subpaths
3943
Delete(path string) error
4044
}
4145

42-
// Error returned when operating on a nonexistent path
46+
// PathNotFoundError is returned when operating on a nonexistent path
4347
type PathNotFoundError struct {
4448
Path string
4549
}
@@ -48,7 +52,7 @@ func (err PathNotFoundError) Error() string {
4852
return fmt.Sprintf("Path not found: %s", err.Path)
4953
}
5054

51-
// Error returned when attempting to read or write from an invalid offset
55+
// InvalidOffsetError is returned when attempting to read or write from an invalid offset
5256
type InvalidOffsetError struct {
5357
Path string
5458
Offset uint64

0 commit comments

Comments
 (0)