feat: add basic linkding connection

This commit is contained in:
Alexander Navarro 2024-12-18 16:54:33 -03:00
parent 43cd24e4d0
commit 43f6340a4a
8 changed files with 163 additions and 16 deletions

View file

@ -0,0 +1,42 @@
package service
import "fmt"
type ServiceOption string
const (
ServiceLinkding ServiceOption = "linkding"
)
type ServiceConfig struct {
Service ServiceOption
Host string
User string
Token string
}
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
}