sliproad/files/fileutils.go
Gabriel Simmer 49dba732d3
Implement Setup() function for providers, cleanup
Implemented a much-needed Setup() function for providers to implement,
which (as demonstrated in the backblaze provider) allows for
authentication in advance of needing to make calls to remote locations.
This could also be used to create a directory or perform some other
sanity check required for the provider to work. So far, haven't noticed
any performance impacts from this approach, besides not needing to auth
each time we make a request.
2020-03-21 00:31:24 +00:00

36 lines
831 B
Go

package files
import "fmt"
var ProviderConfig map[string]FileProvider
var Providers map[string]*FileProviderInterface
func TranslateProvider(codename string, i *FileProviderInterface) {
provider := ProviderConfig[codename]
if codename == "disk" {
*i = &DiskProvider{provider,}
return
}
if codename == "backblaze" {
bbProv := &BackblazeProvider{provider, provider.Config["bucket"], ""}
*i = bbProv
return
}
*i = FileProvider{}
}
func SetupProviders() {
Providers = make(map[string]*FileProviderInterface)
for name, provider := range ProviderConfig {
var i FileProviderInterface
TranslateProvider(name, &i)
success := i.Setup(provider.Config)
if !success {
fmt.Printf("%s failed to initialize\n", name)
} else {
Providers[name] = &i
fmt.Printf("%s initialized successfully\n", name)
}
}
}