mirror of
https://github.com/gmemstr/sliproad.git
synced 2024-09-20 00:21:15 +01:00
49dba732d3
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.
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package files
|
|
|
|
import (
|
|
"io"
|
|
)
|
|
|
|
type FileProvider struct {
|
|
Name string `yaml:"name"`
|
|
Provider string `yaml:"provider"`
|
|
Authentication string `yaml:"authentication"`
|
|
Location string `yaml:"path"`
|
|
Config map[string]string `yaml:"config"`
|
|
}
|
|
|
|
type Directory struct {
|
|
Path string
|
|
Files []FileInfo
|
|
}
|
|
|
|
type FileInfo struct {
|
|
IsDirectory bool
|
|
Name string
|
|
Extension string
|
|
}
|
|
|
|
type FileContents struct {
|
|
Content []byte
|
|
IsUrl bool
|
|
}
|
|
|
|
type FileProviderInterface interface {
|
|
Setup(args map[string]string) bool
|
|
GetDirectory(path string) Directory
|
|
ViewFile(path string, w io.Writer)
|
|
SaveFile(contents []byte, path string) bool
|
|
DetermineType(path string) string
|
|
}
|
|
|
|
/** DO NOT USE THESE DEFAULTS **/
|
|
func (f FileProvider) Setup(args map[string]string) bool {
|
|
return false
|
|
}
|
|
|
|
func (f FileProvider) GetDirectory(path string) Directory {
|
|
return Directory{}
|
|
}
|
|
|
|
func (f FileProvider) ViewFile(path string, w io.Writer) {
|
|
return
|
|
}
|
|
|
|
func (f FileProvider) SaveFile(contents []byte, path string) bool {
|
|
return false
|
|
}
|
|
|
|
func (f FileProvider) DetermineType(path string) string {
|
|
return ""
|
|
}
|
|
|