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
|
|
|
|
}
|
2013-08-29 23:39:06 -04:00
|
|
|
case "ftp":
|
|
|
|
storage, err = NewFTPStorage(config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2013-02-11 23:17:12 -05:00
|
|
|
default:
|
2013-08-29 23:39:06 -04:00
|
|
|
return nil, errors.New("Error: storage method '" + storageMethod + "' not found.")
|
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
|
|
|
}
|