forked from CoderfishGzh/Hamster-media
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (51 loc) · 1.4 KB
/
main.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
package main
import (
"getNews/handler"
"getNews/initialization"
"github.com/gin-gonic/gin"
"log"
"net/http"
"time"
)
func main() {
r := gin.Default()
// init default news
initialization.Init()
handler.GetNewsDefault()
httpHandler := handler.NewHandlerServer()
// 定时拉取在线的新闻
go func() {
for {
// 如果爬新闻出错,则使用默认的新闻
NewsTmp, err := handler.GetOnlineMedia()
if err != nil {
log.Println(err)
}
if NewsTmp != nil {
handler.News = NewsTmp
}
time.Sleep(time.Hour * 3)
}
}()
// api
r.GET("/articles", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "ok",
"data": handler.News,
})
})
r.POST("/JoinMiddleware", httpHandler.JoinMiddleware)
api := r.Group("/api")
api.GET("/activity/:id/status", httpHandler.GetActivityStatus)
api.GET("/check/deploy", httpHandler.CheckDeploy)
api.GET("/deploy/info", httpHandler.GetDeployContractInfo)
api.POST("/nft/airdrop", httpHandler.SaveNftAirdrop)
api.GET("/contact/platform", httpHandler.GetContactPlatform)
api.POST("/contact/ecosystems", httpHandler.SaveEcosystemsContact)
api.GET("/navbar", httpHandler.GetNavbarList)
api.GET("/navbar/:id/content", httpHandler.GetNavbarContent)
api.GET("/navbar/faucet", httpHandler.FaucetList)
api.POST("/subscribe/email", httpHandler.SubscribeEmail)
// 监听并在 0.0.0.0:8888 上启动服务
r.Run(":8888")
}