-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnew.go
35 lines (25 loc) · 1.03 KB
/
new.go
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
34
35
// Package storage deals with files on the disk or whatever storage. It defines the
// Storage interface. It has methods for getting contents of a file, headers of a
// file and methods for removing files. Since every cache zone has its own storage
// it is possible to have different storage implementations running at the same
// time.
// The storageTypes map is in types.go and it is generate with `go generate`.
//go:generate go run ../tools/module_generator/main.go -template "types.go.template" -output "types.go"
package storage
import (
"fmt"
"github.com/ironsmile/nedomi/config"
"github.com/ironsmile/nedomi/types"
)
// New returns a new Storage ready for use. The st argument sets which type of
// storage will be returned.
func New(cfg *config.CacheZone, log types.Logger) (types.Storage, error) {
if cfg == nil {
return nil, fmt.Errorf("empty cache zone configuration supplied")
}
storFunc, ok := storageTypes[cfg.Type]
if !ok {
return nil, fmt.Errorf("no such storage type: %s", cfg.Type)
}
return storFunc(cfg, log)
}