feat:完善项目
This commit is contained in:
@ -39,7 +39,8 @@ type Account struct{}
|
||||
* "msg": "ok"
|
||||
* "data": {
|
||||
* "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNjM4NjA0NDYwIiwiaWF0IjoiMTYzNjAxMjQ2MCIsInVpZCI6IjIwOTU2MTg2ODk5ODEyMjI5MTIifQ.Q4_peBb9aeGaZAfUFMMzn21cbfhY6_DEocI9xlj9v9g",
|
||||
* "effect_time": 2592000
|
||||
* "effect_time": 2592000,
|
||||
* "ws_url": "",
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
@ -48,9 +49,9 @@ func (a *Account) Login(c *gin.Context) {
|
||||
Account string `json:"account" form:"account" binding:"required"`
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
Captcha struct {
|
||||
Key string `json:"key" form:"key" binding:"required"`
|
||||
Value string `json:"value" form:"value" binding:"required"`
|
||||
} `json:"captcha" form:"captcha" binding:"required"`
|
||||
Key string `json:"key" form:"key"`
|
||||
Value string `json:"value" form:"value"`
|
||||
} `json:"captcha" form:"captcha"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
|
||||
@ -12,6 +12,31 @@ type Config struct{}
|
||||
* @apiDefine Config 配置管理
|
||||
*/
|
||||
|
||||
func (*Config) List(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
PageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := config.NewInstance()().List(form.Kind, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Config) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
Params map[string]interface{} `json:"params" form:"params"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := config.NewInstance()().Form(form.Params)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/v1/config/area 区域信息
|
||||
* @apiVersion 1.0.0
|
||||
@ -47,7 +72,7 @@ func (*Config) Area(c *gin.Context) {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data := config.NewInstance()(getSession()(c).(*service.Session)).Area(form.Key)
|
||||
data := config.NewArea()(getSession()(c).(*service.Session)).List(form.Key)
|
||||
APIResponse(nil, data)(c)
|
||||
}
|
||||
|
||||
|
||||
46
app/api/websocket.go
Normal file
46
app/api/websocket.go
Normal file
@ -0,0 +1,46 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/handle"
|
||||
"ArmedPolice/app/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Websocket struct{}
|
||||
|
||||
var upGrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
}
|
||||
|
||||
func (*Websocket) Ws(c *gin.Context) {
|
||||
conn, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
|
||||
if err != nil {
|
||||
APIFailure(err)(c)
|
||||
return
|
||||
}
|
||||
session := getSession()(c).(*service.Session)
|
||||
|
||||
client := service.NewWebsocket(session.UIDToString(), conn)
|
||||
service.HubMessage.RegisterHandle(client)
|
||||
go client.Write()
|
||||
}
|
||||
|
||||
func (*Websocket) Pong(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "ping"})
|
||||
}
|
||||
|
||||
func (*Websocket) Publish(c *gin.Context) {
|
||||
key := c.Query("key")
|
||||
service.HubMessage.EmitHandle(&service.HubEmit{
|
||||
ID: key,
|
||||
Msg: handle.NewWorkNotice("你有一条待办事项"),
|
||||
})
|
||||
APISuccess()(c)
|
||||
}
|
||||
Reference in New Issue
Block a user