book18api

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 4 Imported by: 0

README

Book18 API Documentation

This documentation provides an overview of the book18api package, which is a Go library for interacting with the Book18 website (https://www.book18.org). The library allows you to retrieve book chapters, book indexes, search for books, and more.

Installation

To use the book18api package in your Go project, you need to install it using the following command:

go get github.com/hhhBooksLib/book18api

Usage

Import the book18api package in your Go code:

import "github.com/hhhBooksLib/book18api"
ClientBook18 Interface

The ClientBook18 interface defines the methods for interacting with the Book18 API:

type ClientBook18 interface {
	GetChapterByChapterId(chapterId string) *Chapter
	GetBookIndexByPage(page int) []IndexBook
	SearchBookInfoByKeyword(keyword string, page int) []SearchBook
	LongBookChapterIndex(bookName string) []BookCatalog
}
ClientApi

The ClientApi struct implements the ClientBook18 interface and provides methods for accessing the Book18 API:

type ClientApi struct {
Get func (url string, params any) *goquery.Document
}
NewBook18Client

The NewBook18Client function creates a new instance of the ClientApi struct:

func NewBook18Client() ClientBook18 {
	return &ClientApi{
	Get: func (url string, params any) *goquery.Document {
		return client.NewClient(20).UrlSite("https://www.book18.org").UrlPoint(url).GetMethod().Query(params).
	NewRequest().Document()},
}
}
GetChapterByChapterId

The GetChapterByChapterId method retrieves a specific chapter by its ID:

func (book *ClientApi) GetChapterByChapterId(chapterId string) *Chapter {
// Implementation details...
}
GetBookIndexByPage

The GetBookIndexByPage method retrieves the book index for a specific page:

func (book *ClientApi) GetBookIndexByPage(page int) []IndexBook {
// Implementation details...
}
SearchBookInfoByKeyword

The SearchBookInfoByKeyword method searches for books based on a keyword and page number:

func (book *ClientApi) SearchBookInfoByKeyword(keyword string, page int) []SearchBook {
// Implementation details...
}
LongBookChapterIndex

The LongBookChapterIndex method retrieves the chapter index for a long book:

func (book *ClientApi) LongBookChapterIndex(bookName string) []BookCatalog {
// Implementation details...
}
ClientShortApi

The ClientShortApi struct implements the ClientBook18 interface for short articles:

type ClientShortApi struct {
Get func (url string, params any) *goquery.Document
}
NewBook18ShortClient

The NewBook18ShortClient function creates a new instance of the ClientShortApi struct:

func NewBook18ShortClient() ClientBook18 {
    return &ClientShortApi{
        Get: func (url string, params any) *goquery.Document {
            return client.NewClient(20).UrlSite("https://www.book18.org").UrlPoint(url).GetMethod().Query(params).
                NewRequest().Document()
	},
    }
}
GetChapterByChapterId

The GetChapterByChapterId method retrieves a specific chapter for a short article by its ID:

func (book *ClientShortApi) GetChapterByChapterId(chapterId string) *Chapter {
// Implementation details...
}
DownloadLongBookChapters

The DownloadLongBookChapters function downloads all chapters of a long book concurrently:

func DownloadLongBookChapters(bookName string) chan *Chapter {
// Implementation details...
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProxyIP string
View Source
var ProxyPassword string
View Source
var ProxyPort string
View Source
var ProxyUserName string

Functions

func DownloadLongBookChapters

func DownloadLongBookChapters(bookName string) chan *Chapter

Types

type BookCatalog

type BookCatalog struct {
	Index        int    `json:"index"`
	BookId       string `json:"book_id"`
	BookName     string `json:"book_name"`
	OriginBookId string `json:"origin_book_id"`
}

type Chapter

type Chapter struct {
	BookId         string `json:"book_id"`
	ChapterTitle   string `json:"chapter_title"`
	ChapterContent string `json:"chapter_content"`
	OriginUrl      string `json:"origin_url"`
}

type ClientApi added in v1.1.0

type ClientApi struct {
	// contains filtered or unexported fields
}

func (*ClientApi) GetBookIndexByPage added in v1.1.0

func (book *ClientApi) GetBookIndexByPage(page int) []IndexBook

func (*ClientApi) GetChapterByChapterId added in v1.1.0

func (book *ClientApi) GetChapterByChapterId(chapterId string) *Chapter

func (*ClientApi) LongBookChapterIndex added in v1.1.0

func (book *ClientApi) LongBookChapterIndex(bookName string) []BookCatalog

func (*ClientApi) SearchBookInfoByKeyword added in v1.1.0

func (book *ClientApi) SearchBookInfoByKeyword(keyword string, page int) []SearchBook

type ClientBook18 added in v1.1.0

type ClientBook18 interface {
	GetChapterByChapterId(chapterId string) *Chapter
	GetBookIndexByPage(page int) []IndexBook
	SearchBookInfoByKeyword(keyword string, page int) []SearchBook
	LongBookChapterIndex(bookName string) []BookCatalog
}

func NewBook18Client added in v1.1.0

func NewBook18Client() ClientBook18

func NewBook18ShortClient added in v1.1.0

func NewBook18ShortClient() ClientBook18

type ClientShortApi added in v1.1.0

type ClientShortApi struct {
	// contains filtered or unexported fields
}

func (*ClientShortApi) GetBookIndexByPage added in v1.1.0

func (book *ClientShortApi) GetBookIndexByPage(page int) []IndexBook

func (*ClientShortApi) GetChapterByChapterId added in v1.1.0

func (book *ClientShortApi) GetChapterByChapterId(chapterId string) *Chapter

func (*ClientShortApi) LongBookChapterIndex added in v1.1.0

func (book *ClientShortApi) LongBookChapterIndex(bookName string) []BookCatalog

func (*ClientShortApi) SearchBookInfoByKeyword added in v1.1.0

func (book *ClientShortApi) SearchBookInfoByKeyword(keyword string, page int) []SearchBook

type IndexBook

type IndexBook struct {
	Index    int    `json:"index"`
	BookId   string `json:"book_id"`
	BookName string `json:"book_name"`
	Short    bool   `json:"short"`
}

type SearchBook

type SearchBook struct {
	Index    int    `json:"index"`
	BookId   string `json:"book_id"`
	BookName string `json:"book_name"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL