go-asink/storage.go

33 lines
679 B
Go
Raw Normal View History

2013-02-10 23:39:23 -05:00
package main
import (
"errors"
"code.google.com/p/goconf/conf"
)
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 {
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-11 23:16:19 -05:00
return storage, nil
2013-02-10 23:39:23 -05:00
}