-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathnovels.go
65 lines (60 loc) · 1.74 KB
/
novels.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package apis
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
"github.com/howie6879/owllook_api/common"
"github.com/howie6879/owllook_api/config"
)
var (
NovelsRulesMap = config.NovelsRulesMap
)
// SearchAuthors returns all novels resource that you serached
func SearchAuthors(c *gin.Context) {
var currentRule config.NovelRule
var ok bool
novelName := c.Param("name")
novelSource := c.Param("source")
if novelName != "" {
currentRule, ok = NovelsRulesMap[novelSource+"_1"]
log.Println(ok)
if ok == false {
currentRule, ok = NovelsRulesMap[novelSource]
}
log.Println(ok)
if ok {
resultData, err := common.FetchHtml(novelName, currentRule)
if err != nil {
log.Println("Request URL error", err)
c.JSON(http.StatusOK, gin.H{"statue": 0, "msg": "Request error"})
} else {
c.JSON(http.StatusOK, gin.H{"status": 1, "info": resultData})
}
} else {
c.JSON(http.StatusOK, gin.H{"statue": 0, "msg": "Parameter error"})
}
} else {
c.JSON(http.StatusOK, gin.H{"statue": 0, "msg": "Parameter name can't be empty"})
}
}
// SearchNovels returns all novels resource that you serached
func SearchNovels(c *gin.Context) {
novelName := c.Param("name")
novelSource := c.Param("source")
if novelName != "" {
currentRule, ok := NovelsRulesMap[novelSource]
if ok {
resultData, err := common.FetchHtml(novelName, currentRule)
if err != nil {
log.Println("Request URL error", err)
c.JSON(http.StatusOK, gin.H{"statue": 0, "msg": "Request error"})
} else {
c.JSON(http.StatusOK, gin.H{"status": 1, "info": resultData})
}
} else {
c.JSON(http.StatusOK, gin.H{"statue": 0, "msg": "Parameter error"})
}
} else {
c.JSON(http.StatusOK, gin.H{"statue": 0, "msg": "Parameter name can't be empty"})
}
}