generated from alecodes/base-template
feat: add basic linkding connection
This commit is contained in:
parent
43cd24e4d0
commit
43f6340a4a
8 changed files with 163 additions and 16 deletions
42
internal/service/service.go
Normal file
42
internal/service/service.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue