-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.go
More file actions
33 lines (30 loc) · 824 Bytes
/
build.go
File metadata and controls
33 lines (30 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package storage
import "context"
// Build constructs a single storage backend from a typed driver config without
// a Manager.
// @group Construction
//
// Example: build a single disk
//
// fs, _ := storage.Build(localstorage.Config{
// Root: "/tmp/storage-example",
// Prefix: "assets",
// })
// _ = fs
func Build(cfg DriverConfig) (Storage, error) {
return BuildContext(context.Background(), cfg)
}
// BuildContext constructs a single storage backend from a typed driver config
// using the caller-provided context.
// @group Context
func BuildContext(ctx context.Context, cfg DriverConfig) (Storage, error) {
name, resolved, err := resolveDriverConfig(cfg)
if err != nil {
return nil, err
}
factory, ok := lookupDriver(name)
if !ok {
return nil, errUnknownDriver(name)
}
return factory(ctx, resolved)
}