123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- package http
- import (
- "go-common/app/interface/openplatform/monitor-end/model"
- "go-common/app/interface/openplatform/monitor-end/model/monitor"
- "go-common/library/ecode"
- bm "go-common/library/net/http/blademaster"
- "go-common/library/net/metadata"
- "strconv"
- )
- func groupList(c *bm.Context) {
- var params = &model.GroupListParams{}
- if err := c.Bind(params); err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(mfSvc.GroupList(c, params))
- }
- func groupAdd(c *bm.Context) {
- var params = &model.Group{}
- if err := c.Bind(params); err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(mfSvc.AddGroup(c, params))
- }
- func groupUpdate(c *bm.Context) {
- var (
- params = &model.Group{}
- err error
- )
- if err = c.Bind(params); err != nil {
- c.JSON(nil, err)
- return
- }
- err = mfSvc.UpdateGroup(c, params)
- c.JSON(nil, err)
- }
- func groupDelete(c *bm.Context) {
- var (
- params = &model.Target{}
- err error
- )
- if err = c.Bind(params); err != nil {
- c.JSON(nil, err)
- return
- }
- err = mfSvc.DeleteGroup(c, params.ID)
- c.JSON(nil, err)
- }
- func targetList(c *bm.Context) {
- var (
- params = &model.Target{}
- pn, ps int
- err error
- form = c.Request.Form
- sort string
- draw int
- res *model.Targets
- )
- if err = c.Bind(params); err != nil {
- c.JSON(nil, err)
- return
- }
- pnStr := form.Get("page")
- psStr := form.Get("pagesize")
- drawStr := form.Get("draw")
- sort = form.Get("sort")
- if sort == "" {
- sort = "ctime,0"
- }
- if drawStr != "" {
- if draw, err = strconv.Atoi(drawStr); err != nil {
- err = ecode.RequestErr
- c.JSON(nil, err)
- return
- }
- pnStr = form.Get("start")
- psStr = form.Get("length")
- }
- if pn, err = strconv.Atoi(pnStr); err != nil || pn < 0 {
- err = ecode.RequestErr
- c.JSON(nil, err)
- return
- }
- if ps, err = strconv.Atoi(psStr); err != nil || ps < 0 {
- err = ecode.RequestErr
- c.JSON(nil, err)
- return
- }
- if ps == 0 {
- ps = 20
- }
- if draw > 0 {
- pn = (pn + ps) / ps
- }
- if pn == 0 {
- pn = 1
- }
- res, err = mfSvc.TargetList(c, params, pn, ps, sort)
- if draw > 0 {
- res.Draw = draw
- }
- c.JSON(res, err)
- }
- func targetAdd(c *bm.Context) {
- var params = &model.Target{}
- if err := c.Bind(params); err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(mfSvc.AddTarget(c, params))
- }
- func targetUpdate(c *bm.Context) {
- var (
- params = &model.Target{}
- err error
- )
- if err = c.Bind(params); err != nil {
- c.JSON(nil, err)
- return
- }
- err = mfSvc.UpdateTarget(c, params)
- c.JSON(nil, err)
- }
- func targetSync(c *bm.Context) {
- var (
- params = &model.Target{}
- err error
- )
- if err = c.Bind(params); err != nil {
- c.JSON(nil, err)
- return
- }
- if params.ID == 0 {
- err = ecode.RequestErr
- c.JSON(nil, err)
- return
- }
- err = mfSvc.TargetSync(c, params.ID, params.State)
- c.JSON(nil, err)
- }
- func productAdd(c *bm.Context) {
- var (
- params = &model.Product{}
- err error
- )
- if err = c.Bind(params); err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(mfSvc.AddProduct(c, params))
- }
- func productUpdate(c *bm.Context) {
- var (
- params = &model.Product{}
- err error
- )
- if err = c.Bind(params); err != nil {
- c.JSON(nil, err)
- return
- }
- err = mfSvc.UpdateProduct(c, params)
- c.JSON(nil, err)
- }
- func productDelete(c *bm.Context) {
- var (
- params = &model.Product{}
- err error
- )
- if err = c.Bind(params); err != nil {
- c.JSON(nil, err)
- return
- }
- if params.ID == 0 {
- err = ecode.RequestErr
- c.JSON(nil, err)
- return
- }
- err = mfSvc.DeleteProduct(c, params.ID)
- c.JSON(nil, err)
- }
- func productList(c *bm.Context) {
- c.JSON(mfSvc.AllProducts(c))
- }
- func collect(c *bm.Context) {
- var (
- params = &monitor.Log{}
- err error
- )
- if err = c.Bind(params); err != nil {
- c.JSON(nil, err)
- return
- }
- midInter, _ := c.Get("mid")
- if midInter != nil {
- params.Mid = strconv.FormatInt(midInter.(int64), 10)
- }
- params.IP = metadata.String(c, metadata.RemoteIP)
- params.Buvid = c.Request.Header.Get("Buvid")
- params.UserAgent = c.Request.Header.Get("User-Agent")
- mfSvc.Collect(c, params)
- c.JSON(nil, nil)
- }
|