go-asink/client/storage.go

33 lines
672 B
Go
Raw Normal View History

2013-02-10 23:39:23 -05:00
package main
import (
"code.google.com/p/goconf/conf"
2013-02-11 23:17:12 -05:00
"errors"
2013-02-10 23:39:23 -05:00
)
type Storage interface {
Put(filename string, hash string) error
Get(filename string, hash string) error
}
2013-02-11 23:16:19 -05:00
func GetStorage(config *conf.ConfigFile) (Storage, error) {
2013-02-10 23:39:23 -05:00
storageMethod, err := config.GetString("storage", "method")
if err != nil {
return nil, errors.New("Error: storage method not specified in config file.")
}
var storage Storage
switch storageMethod {
2013-02-11 23:17:12 -05:00
case "local":
storage, err = NewLocalStorage(config)
if err != nil {
return nil, err
}
default:
return nil, errors.New("Error: storage method '" + storageMethod + "' not implemented.")
2013-02-10 23:39:23 -05:00
}
2013-02-11 23:16:19 -05:00
return storage, nil
2013-02-10 23:39:23 -05:00
}