Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeResponse(resp *http.Response, data interface{}) (err error)
- func EscapeFilename(filename string) string
- func Filename(resp *http.Response) (name string)
- func GenerateUrl(base string, paths ...string) string
- func NewCookieJar(path string) (http.CookieJar, error)
- func NewDownloadConfig() *config
- func NewStorage(start, size int64, path string) (*storage, error)
- func NewTalebook(c *config) *talebook
- func WrapTimeOut(err error) error
- type BookListResponse
- type BookResponse
- type CommonResponse
- type LoginResponse
Constants ¶
const ( DefaultUserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36" SuccessStatus = "ok" BookNotFoundStatus = "not_found" )
const NoBookToDownload = -1
Variables ¶
var ( ErrStartBookID = errors.New("the start book id should start from 1") ErrStartAndEndBookID = errors.New("start book id should below the available book id") ErrStorageFile = errors.New("couldn't create file for storing download process") )
var ErrNeedSignin = errors.New("need user account to download books")
Functions ¶
func DecodeResponse ¶
DecodeResponse would parse the http response into a json based content.
func EscapeFilename ¶
EscapeFilename escape the filename in *nix like systems.
func Filename ¶
Filename parse the file name from Content-Disposition header. If there is no such head, we would return blank string.
func GenerateUrl ¶
GenerateUrl would remove the "/" suffix and add schema prefix to url.
func NewCookieJar ¶
NewCookieJar would create a cookie jar instance. It supports auto saving policy.
func NewDownloadConfig ¶
func NewDownloadConfig() *config
NewDownloadConfig will return a default blank config.
func NewStorage ¶
NewStorage Create a storge for save the download progress.
func NewTalebook ¶
func NewTalebook(c *config) *talebook
NewTalebook will create the download instance.
func WrapTimeOut ¶
WrapTimeOut would convert the timeout error with a better prefix in error message.
Types ¶
type BookListResponse ¶
type BookListResponse struct { CommonResponse Msg string `json:"msg"` Title string `json:"title"` Total int64 `json:"total"` Books []struct { ID int64 `json:"id"` } `json:"books"` }
BookListResponse is used to return recent books.
type BookResponse ¶
type BookResponse struct { CommonResponse Msg string `json:"msg"` KindleSender string `json:"kindle_sender"` Book struct { ID int `json:"id"` Title string `json:"title"` Files []struct { Format string `json:"format"` Size int64 `json:"size"` Href string `json:"href"` } `json:"files"` } `json:"book"` }
BookResponse stands for default book information
type CommonResponse ¶
type CommonResponse struct {
Err string `json:"err"`
}
CommonResponse is the base response for all the requests.
type LoginResponse ¶
type LoginResponse struct { CommonResponse Msg string `json:"msg"` }
LoginResponse is used for login action.