generated from alecodes/base-template
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
54 lines
1 KiB
Go
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
|
|
}
|