Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit

Permalink
improve for error
Browse files Browse the repository at this point in the history
  • Loading branch information
solarhell committed Jan 5, 2019
1 parent a9353b8 commit eefdc19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 3 additions & 4 deletions crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package ZhihuZhuanlanCrawler

import (
"encoding/json"
"errors"
"fmt"
"log"
)

func (c *Client) GetPinnedArticlePidAndAuthor(columnName string) (*PinnedArticleAndAuthor, error) {
if columnName == "" {
return nil, errors.New(ColumnNameCanNotBeEmpty)
return nil, ColumnNameCanNotBeEmpty
}
u := fmt.Sprintf("https://zhuanlan.zhihu.com/api2/columns/%s/pinned-article", columnName)
res, err := c.SendNewZhihuRequest(u)
Expand All @@ -30,7 +29,7 @@ func (c *Client) GetPinnedArticlePidAndAuthor(columnName string) (*PinnedArticle

func (c *Client) GetSingleArticle(pid int) (*Article, error) {
if pid == 0 {
return nil, errors.New(PidCanNotBeEmpty)
return nil, PidCanNotBeEmpty
}
u := fmt.Sprintf("https://zhuanlan.zhihu.com/api/posts/%d", pid)
res, err := c.SendNewZhihuRequest(u)
Expand All @@ -51,7 +50,7 @@ func (c *Client) GetSingleArticle(pid int) (*Article, error) {

func (c *Client) GetArticlesListPids(columnName string) ([]int, error) {
if columnName == "" {
return nil, errors.New(ColumnNameCanNotBeEmpty)
return nil, ColumnNameCanNotBeEmpty
}

var limit = 20
Expand Down
10 changes: 6 additions & 4 deletions error.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ZhihuZhuanlanCrawler

const (
ColumnNameCanNotBeEmpty = "专栏名不能为空"
PidCanNotBeEmpty = "pid 不能为空"
)
import "errors"

var (
ColumnNameCanNotBeEmpty = errors.New("专栏名不能为空")
PidCanNotBeEmpty = errors.New("pid 不能为空")
)

0 comments on commit eefdc19

Please sign in to comment.