forked from axiaoxin-com/investool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery_fund_by_stock.go
46 lines (40 loc) · 1.07 KB
/
query_fund_by_stock.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
// 根据股票查基金
package routes
import (
"net/http"
"github.com/axiaoxin-com/goutils"
"github.com/axiaoxin-com/investool/core"
"github.com/axiaoxin-com/investool/version"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)
// ParamQueryFundByStock QueryFundByStock 请求参数
type ParamQueryFundByStock struct {
Keywords string `form:"keywords" binding:"required"`
}
// QueryFundByStock 股票选基
func QueryFundByStock(c *gin.Context) {
data := gin.H{
"Env": viper.GetString("env"),
"Version": version.Version,
"PageTitle": "InvesTool | 基金 | 股票选基",
"Error": "",
}
param := ParamQueryFundByStock{}
if err := c.ShouldBind(¶m); err != nil {
data["Error"] = err.Error()
c.JSON(http.StatusOK, data)
return
}
keywords := goutils.SplitStringFields(param.Keywords)
searcher := core.NewSearcher(c)
dlist, err := searcher.SearchFundByStock(c, keywords...)
if err != nil {
data["Error"] = err.Error()
c.JSON(http.StatusOK, data)
return
}
data["Funds"] = dlist
c.HTML(http.StatusOK, "hold_stock_fund.html", data)
return
}