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 }