miniflux-archiver/internal/service/service.go
aleidk b0506c3eab fead: expand archive options
add an option to select how to archive the entries
add an option for what entries to archive
change the concurrentcy limit to a semaphore instead of a ticker
2024-12-20 14:59:43 -03:00

54 lines
1 KiB
Go

package service
import (
"fmt"
)
type ServiceOption string
const (
ServiceLinkding ServiceOption = "linkding"
)
type ServiceArchiveMethod string
const (
ServiceArchiveMethodSeen = "seen"
ServiceArchiveMethodArchive = "archive"
ServiceArchiveMethodBoth = "both"
)
type ServiceConfig struct {
Service ServiceOption
Host string
User string
Token string
Method ServiceArchiveMethod
MaxRequests uint8
}
type Service interface {
IsAvailable() (bool, error)
Archive(string) error
}
func ResolveService(serviceConfig ServiceConfig) (Service, error) {
var service Service
switch serviceConfig.Service {
case ServiceLinkding:
service, _ = NewLinkding(serviceConfig)
default:
return nil, fmt.Errorf("Could not determine service to connect to")
}
if isAvailable, err := service.IsAvailable(); !isAvailable {
return nil, fmt.Errorf(
"Could not connect to the service %v in %v: %v",
serviceConfig.Service,
serviceConfig.Host,
err,
)
}
return service, nil
}