backy/pkg/configfetcher/configfetcher.go

28 lines
822 B
Go
Raw Normal View History

2025-01-14 15:42:43 +00:00
package configfetcher
import "strings"
type ConfigFetcher interface {
// Fetch retrieves the configuration from the specified URL or source
// Returns the raw data as bytes or an error
Fetch(source string) ([]byte, error)
// Parse decodes the raw data into a Go structure (e.g., Commands, CommandLists)
// Takes the raw data as input and populates the target interface
Parse(data []byte, target interface{}) error
}
func NewConfigFetcher(source string, options ...Option) (ConfigFetcher, error) {
2025-01-14 15:42:43 +00:00
if strings.HasPrefix(source, "http") || strings.HasPrefix(source, "https") {
return NewHTTPFetcher(options...), nil
2025-01-14 15:42:43 +00:00
} else if strings.HasPrefix(source, "s3") {
fetcher, err := NewS3Fetcher(options...)
if err != nil {
return nil, err
}
return fetcher, nil
2025-01-14 15:42:43 +00:00
} else {
return &LocalFetcher{}, nil
2025-01-14 15:42:43 +00:00
}
}