MCPcopy
hub / github.com/perkeep/perkeep / buildStorageForReceive

Function buildStorageForReceive

pkg/blobserver/cond/cond.go:110–148  ·  view source on GitHub ↗
(ld blobserver.Loader, confOrString interface{})

Source from the content-addressed store, hash-verified

108}
109
110func buildStorageForReceive(ld blobserver.Loader, confOrString interface{}) (storageFunc, error) {
111 // Static configuration from a string
112 if s, ok := confOrString.(string); ok {
113 sto, err := ld.GetStorage(s)
114 if err != nil {
115 return nil, err
116 }
117 f := func(br blob.Ref, src io.Reader) (blobserver.Storage, io.Reader, error) {
118 return sto, src, nil
119 }
120 return f, nil
121 }
122
123 conf := jsonconfig.Obj(confOrString.(map[string]interface{}))
124
125 ifStr := conf.RequiredString("if")
126 // TODO: let 'then' and 'else' point to not just strings but either
127 // a string or a JSON object with another condition, and then
128 // call buildStorageForReceive on it recursively
129 thenTarget := conf.RequiredString("then")
130 elseTarget := conf.RequiredString("else")
131 if err := conf.Validate(); err != nil {
132 return nil, err
133 }
134 thenSto, err := ld.GetStorage(thenTarget)
135 if err != nil {
136 return nil, err
137 }
138 elseSto, err := ld.GetStorage(elseTarget)
139 if err != nil {
140 return nil, err
141 }
142
143 switch ifStr {
144 case "isSchema":
145 return isSchemaPicker(thenSto, elseSto), nil
146 }
147 return nil, fmt.Errorf("cond: unsupported 'if' type of %q", ifStr)
148}
149
150func isSchemaPicker(thenSto, elseSto blobserver.Storage) storageFunc {
151 return func(br blob.Ref, src io.Reader) (dest blobserver.Storage, newSrc io.Reader, err error) {

Callers 1

newFromConfigFunction · 0.85

Calls 2

isSchemaPickerFunction · 0.85
GetStorageMethod · 0.65

Tested by

no test coverage detected