添加mq和controller

master
a7458969 2020-03-25 10:57:25 +08:00
parent e65ac973c7
commit 9e7b384836
6 changed files with 34 additions and 9 deletions

View File

@ -28,7 +28,7 @@ type ConfAPI struct {
init bool
}
type ElasticSearch struct{
Address string `yaml:"string"`
Address string `yaml:"address"`
}
type EntityRedis struct {

View File

@ -1,9 +1,9 @@
package controller
import (
"background/model"
"github.com/gin-gonic/gin"
"qiniupkg.com/x/log.v7"
)
@ -12,7 +12,18 @@ func AddHardware(c *gin.Context) {
defer func() {
c.JSON(200,resp)
}()
var hardware model.Hardware
e := c.BindJSON(&hardware)
if nil != e{
log.Print(e)
print(e)
return
}
if nil != hardware.CreateHardware(){
print(e)
return
}
resp.Data = nil
resp.Msg = "OK"
resp.Status = 0

View File

@ -19,7 +19,6 @@ type ElkEngine struct {
func (p *ElkEngine)Create(index string,types string,id string,data interface{}) (error) {
if nil != p{
if (reflect.TypeOf(data).Kind() != reflect.String) && (reflect.TypeOf(data).Kind() != reflect.Struct){

View File

@ -38,11 +38,13 @@ func Init() {
}else{
gDb = Database{Type: string(""), DB: initMysqlTLS(mysqlconf)}
}
InitELK()
}
func InitELK() {
var e error
elkconf := config.GetElkConfig()
log.Print(elkconf)
gElkEngine.cli,e = elastic.NewClient(
elastic.SetURL(elkconf.Address),
// Must turn off sniff in docker

View File

@ -116,6 +116,8 @@ func main() {
api.POST("/image_upload",fileController.OnUpload) // 上传图片
api.GET("/image_download/:file",fileController.OnDownLoad) // 下载图片
api.GET("/doc_types",controller.ArticlesTypes) // 获取所有的文章类型
api.POST("/hardware",controller.AddHardware) // 新增硬件
}
e := r.Run(":" + strconv.Itoa(config.GetPort()))

View File

@ -1,6 +1,11 @@
package model
import "time"
import (
"background/db"
"github.com/pkg/errors"
"qiniupkg.com/x/log.v7"
"time"
)
// this api is based on elasticsearch
type Hardware struct {
@ -12,8 +17,14 @@ type Hardware struct {
Doc string `json:"doc"` //文档资料
}
func (*Hardware )Create() error{
func (this *Hardware )CreateHardware( ) error{
if nil == this{
return errors.New("null pointer")
}
e := db.GetElastic().Create("hardware","0","",*this)
if nil != e{
log.Print(e.Error())
return e
}
return nil;
}