-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add common driver service abstraction.
- Loading branch information
Showing
7 changed files
with
89 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package driver | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/bookstairs/bookhunter/internal/client" | ||
) | ||
|
||
type ( | ||
// Source is a net drive disk provider. | ||
Source string | ||
|
||
// Share is an atomic downloadable file. | ||
Share struct { | ||
// FileName is a file name with the file extension. | ||
FileName string | ||
// URL is the downloadable url for this file. | ||
URL string | ||
// Properties could be some metadata, such as the token for this downloadable share. | ||
Properties map[string]string | ||
} | ||
|
||
// Driver is used to resolve the links from a Source. | ||
Driver interface { | ||
// Resolve the given link and return the file name with the download link. | ||
Resolve(shareLink string, passcode string) []Share | ||
|
||
// Download the given link. | ||
Download(share Share) io.ReadCloser | ||
} | ||
) | ||
|
||
const ( | ||
ALIYUN Source = "aliyun" | ||
LANZOU Source = "lanzou" | ||
TELECOM Source = "telecom" | ||
) | ||
|
||
// New will create the basic driver service. | ||
func New(source Source, config *client.Config) (Driver, error) { | ||
switch source { | ||
case ALIYUN: | ||
return nil, errors.New("we don't support aliyun currently") | ||
case TELECOM: | ||
return nil, errors.New("we don't support telecom currently") | ||
case LANZOU: | ||
return nil, errors.New("we don't support lanzou currently") | ||
default: | ||
return nil, fmt.Errorf("invalid driver service %s", source) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters