@cryptotaxi247 / kubo / commits / 6438fc74f

Add documentation.

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Jul 14, 2017 at 15:10 UTC 6438fc74f97e7596d380e29cc726c025e57100e9
1 file changed +15 -2
repo/fsrepo/datastores.go
+15 -2
@@ -19,8 +19,9 @@ import (
19 // ConfigFromMap creates a new datastore config from a map
20 type ConfigFromMap func(map[string]interface{}) (DatastoreConfig, error)
21
22 -type DiskSpec map[string]interface{}
23 -
22 +// DatastoreConfig is an abstraction of a datastore config. A "spec"
23 +// is first converted to a DatastoreConfig and then Create() is called
24 +// to instantiate a new datastore
25 type DatastoreConfig interface {
26 // DiskSpec returns a minimal configuration of the datastore
27 // represting what is stored on disk. Run time values are
@@ -31,6 +32,10 @@ type DatastoreConfig interface {
32 Create(path string) (repo.Datastore, error)
33 }
34
35 +// DiskSpec is the type returned by the DatastoreConfig's DiskSpec method
36 +type DiskSpec map[string]interface{}
37 +
38 +// Bytes returns a minimal JSON encoding of the DiskSpec
39 func (spec DiskSpec) Bytes() []byte {
40 b, err := json.Marshal(spec)
41 if err != nil {
@@ -40,6 +45,7 @@ func (spec DiskSpec) Bytes() []byte {
45 return bytes.TrimSpace(b)
46 }
47
48 +// String returns a minimal JSON encoding of the DiskSpec
49 func (spec DiskSpec) String() string {
50 return string(spec.Bytes())
51 }
@@ -57,6 +63,8 @@ func init() {
63 }
64 }
65
66 +// AnyDatastoreConfig returns a DatastoreConfig from a spec based on
67 +// the "type" parameter
68 func AnyDatastoreConfig(params map[string]interface{}) (DatastoreConfig, error) {
69 which, ok := params["type"].(string)
70 if !ok {
@@ -78,6 +86,7 @@ type premount struct {
86 prefix ds.Key
87 }
88
89 +// MountDatastoreConfig returns a mount DatastoreConfig from a spec
90 func MountDatastoreConfig(params map[string]interface{}) (DatastoreConfig, error) {
91 var res mountDatastoreConfig
92 mounts, ok := params["mounts"].([]interface{})
@@ -143,6 +152,7 @@ type flatfsDatastoreConfig struct {
152 syncField bool
153 }
154
155 +// FlatfsDatastoreConfig returns a flatfs DatastoreConfig from a spec
156 func FlatfsDatastoreConfig(params map[string]interface{}) (DatastoreConfig, error) {
157 var c flatfsDatastoreConfig
158 var ok bool
@@ -191,6 +201,7 @@ type leveldsDatastoreConfig struct {
201 compression ldbopts.Compression
202 }
203
204 +// LeveldsDatastoreConfig returns a levelds DatastoreConfig from a spec
205 func LeveldsDatastoreConfig(params map[string]interface{}) (DatastoreConfig, error) {
206 var c leveldsDatastoreConfig
207 var ok bool
@@ -253,6 +264,7 @@ type logDatastoreConfig struct {
264 name string
265 }
266
267 +// LogDatastoreConfig returns a log DatastoreConfig from a spec
268 func LogDatastoreConfig(params map[string]interface{}) (DatastoreConfig, error) {
269 childField, ok := params["child"].(map[string]interface{})
270 if !ok {
@@ -287,6 +299,7 @@ type measureDatastoreConfig struct {
299 prefix string
300 }
301
302 +// MeasureDatastoreConfig returns a measure DatastoreConfig from a spec
303 func MeasureDatastoreConfig(params map[string]interface{}) (DatastoreConfig, error) {
304 childField, ok := params["child"].(map[string]interface{})
305 if !ok {