handler.go
1.25 KB
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
package handler
import (
"errors"
"net/http"
"client/bulletin/common"
"client/bulletin/db"
"client/bulletin/model"
"client/bulletin/utils/render"
)
func PingHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok\n"))
return
}
func GetBulletin(w http.ResponseWriter, r *http.Request) {
gameID := r.URL.Query().Get("game_id")
channelName := r.URL.Query().Get("channel")
platformName := r.URL.Query().Get("platform")
userID := r.URL.Query().Get("user_id")
deviceID := r.URL.Query().Get("deviceId")
forceShow := r.URL.Query().Get("force_show")
if !(len(gameID) != 0 && len(channelName) != 0 && len(platformName) != 0) {
render.BindError(w, r, errors.New(" 获取参数错误"))
return
}
if len(userID)+len(deviceID) == 0 {
render.BindError(w, r, errors.New(" 获取参数错误:用户及设备为空"))
return
}
bulletins, err := model.GetBulletinByIDChannelAndPlatform(db.Mysql, gameID, userID, deviceID, channelName, platformName, forceShow)
if err != nil {
render.InternalError(w, r, err)
return
}
if len(bulletins.Notices) == 0 {
render.NullResultError(w, r, errors.New(" 查询结果为空"))
return
}
render.JSON(w, r, http.StatusOK, map[string]interface{}{
"code": common.OK,
"obj": bulletins,
})
return
}