This commit is contained in:
2021-12-20 19:17:24 +08:00
parent 179c6a3afa
commit 0df3603ef2
11 changed files with 470 additions and 27 deletions

View File

@@ -1,10 +1,13 @@
package main
import (
"github.com/gin-gonic/gin"
"github.com/jageros/hawox/contextx"
"github.com/jageros/hawox/httpx"
"github.com/jageros/hawox/logx"
"github.com/jageros/hawox/sdk/tianapi"
"github.com/jageros/hawox/timer"
"net/http"
"stock/cfg"
"stock/fund"
"stock/msg"
@@ -19,9 +22,10 @@ func main() {
panic(err)
}
logx.Init(logx.InfoLevel, logx.SetCaller()) //日志初始化
msg.Init() // 企业微信或者钉钉群通知初始化即根据配置文件中的配置设置钉钉机器人的密钥URL和企业微信的URL
tianapi.SetKey(cfg.TianApiKey) // 天行数据API初始化
logx.Init(logx.InfoLevel, logx.SetCaller(), logx.SetRequest()) //日志初始化
defer logx.Sync()
msg.Init() // 企业微信或者钉钉群通知初始化即根据配置文件中的配置设置钉钉机器人的密钥URL和企业微信的URL
tianapi.SetKey(cfg.TianApiKey) // 天行数据API初始化
ctx, cancel := contextx.Default()
defer cancel()
@@ -134,6 +138,33 @@ func main() {
}
})
httpx.InitializeHttpServer(ctx, func(engine *gin.Engine) {
r := engine.Group("/api")
r.GET("/sayhello", func(c *gin.Context) {
httpx.PkgMsgWrite(c, map[string]interface{}{"say": "hello world!"})
})
r.POST("/receive", func(c *gin.Context) {
msgs := &msg.RData{}
err := c.BindXML(msgs)
if err != nil {
logx.Error(err)
} else {
logx.Info(msgs)
}
c.String(http.StatusOK, "success")
})
r.GET("/receive", func(c *gin.Context) {
echostr := c.Query("echostr")
logx.Infof("=== %s ===", echostr)
c.String(http.StatusOK, echostr)
})
}, func(s *httpx.Server) {
s.Mode = "debug"
s.Port = 8567
})
err = ctx.Wait() // 等待停止信号
logx.Infof("Application stop with: %v", err)
}