Skip to content

Commit 02bb4fa

Browse files
committed
refactor naming and flags to prevent confusion
1 parent 05ec0dc commit 02bb4fa

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

.wakatime-project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
clibgen

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ clibgen search "Eloquent JavaScript"
2222
```
2323

2424
Search for a book using the newer website (useful if for some reason the old website is down or the mirrors are not working)
25-
`-m or -mirror` flag
25+
`-s or -site` flag
2626
```shell
2727
clibgen search -m "new" "Eloquent JavaScript"
2828
```

cmd/search.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
var (
13-
selectedMirror string
13+
selectedSite string
1414
numberOfResults = 10
1515

1616
searchCmd = &cobra.Command{
@@ -26,9 +26,9 @@ var (
2626

2727
var libgenType = api.LibgenNew
2828

29-
if selectedMirror == "old" {
29+
if selectedSite == "old" {
3030
libgenType = api.LibgenOld
31-
} else if selectedMirror == "new" {
31+
} else if selectedSite == "new" {
3232
libgenType = api.LibgenNew
3333
}
3434

@@ -68,7 +68,7 @@ var (
6868
func init() {
6969
searchCmd.
7070
PersistentFlags().
71-
StringVarP(&selectedMirror, "mirror", "m", "old", `select which mirror to use
71+
StringVarP(&selectedSite, "site", "s", "old", `select which site to use
7272
options:
7373
"old" -> libgen.is
7474
"new" -> liggen.li

pkg/api/libgen.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ Currently there are three libgen domains:
2222
These domains might change in the future
2323
*/
2424

25-
type MirrorType int32
25+
type Site int32
2626

2727
const (
28-
LibgenOld MirrorType = 0
29-
LibgenNew MirrorType = 1
28+
LibgenOld Site = 0
29+
LibgenNew Site = 1
3030
)
3131

3232
// Note: Applicable only for libgen.is! (We might need to implemented something like this for libgen.li)
@@ -136,8 +136,8 @@ func getBookDataFromDocumentNew(document *goquery.Document) []Book {
136136
}
137137

138138
// Parse HTML and get the data from the table by parsing and iterating through them.
139-
func getBookDataFromDocument(document *goquery.Document, libgenMirrorType MirrorType) []Book {
140-
switch libgenMirrorType {
139+
func getBookDataFromDocument(document *goquery.Document, libgenSite Site) []Book {
140+
switch libgenSite {
141141
case LibgenOld:
142142
return getBookDataFromDocumentOld(document)
143143
case LibgenNew:
@@ -154,7 +154,7 @@ func getLinkFromDocumentNew(document *goquery.Document) (string, bool) {
154154
return document.Find("#main a").First().Attr("href")
155155
}
156156

157-
func getDirectDownloadLink(link string, libgenType MirrorType) string {
157+
func getDirectDownloadLink(link string, libgenType Site) string {
158158
log.Println("Obtaining direct download link")
159159

160160
resp, err := http.Get(link)
@@ -203,11 +203,11 @@ func getDirectDownloadLink(link string, libgenType MirrorType) string {
203203
return ""
204204
}
205205

206-
func SearchBookByTitle(query string, limit int, libgenMirrorType MirrorType) ([]Book, error) {
206+
func SearchBookByTitle(query string, limit int, libgenSite Site) ([]Book, error) {
207207
log.Println("Searching for:", query)
208208
var e error
209209
var baseUrl string
210-
switch libgenMirrorType {
210+
switch libgenSite {
211211
case LibgenOld:
212212
baseUrl = "https://libgen.is/search.php"
213213
case LibgenNew:
@@ -237,7 +237,7 @@ func SearchBookByTitle(query string, limit int, libgenMirrorType MirrorType) ([]
237237
e = err
238238
}
239239

240-
books := getBookDataFromDocument(document, libgenMirrorType)
240+
books := getBookDataFromDocument(document, libgenSite)
241241

242242
if len(books) >= limit {
243243
books = books[:limit]
@@ -247,14 +247,14 @@ func SearchBookByTitle(query string, limit int, libgenMirrorType MirrorType) ([]
247247
}
248248

249249
// DownloadSelection Downloads the file to current working directory
250-
func DownloadSelection(selectedBook Book, libgenType MirrorType) {
250+
func DownloadSelection(selectedBook Book, libgenType Site) {
251251
log.Println("Initializing download")
252252
link := getDirectDownloadLink(selectedBook.Mirrors[0], libgenType)
253253
req, _ := http.NewRequest("GET", link, nil)
254254
resp, error := http.DefaultClient.Do(req)
255255

256256
if error != nil {
257-
log.Fatal("Failed to download! Please try other mirror")
257+
log.Fatal("Failed to download! Please try the other site")
258258
}
259259

260260
defer resp.Body.Close()

0 commit comments

Comments
 (0)