diff --git a/controller/hardware.go b/controller/hardware.go index a4c38be..bea4dd5 100644 --- a/controller/hardware.go +++ b/controller/hardware.go @@ -1,18 +1,11 @@ package controller import ( + "github.com/gin-gonic/gin" "time" ) -// this api is based on elasticsearch -type Hardware struct { - ID int32 `json:"id"` - BuyDate time.Time `json:"buy_date"` //购入时间 - Name string `json:"name"` // 名字 - Desc string `json:"desc"` // 描述 - Pic string `json:"pic"` // 图片 - Doc string `json:"doc"` //文档资料 -} + func AddHardware(c *gin.Context) { resp := RespBase{"unkown error",-231,nil} diff --git a/db/elasticEngine.go b/db/elasticEngine.go index d0b7d01..d143f77 100644 --- a/db/elasticEngine.go +++ b/db/elasticEngine.go @@ -1,8 +1,7 @@ package db import ( - "background/config" - "background/logs" + "github.com/pkg/errors" "gopkg.in/olivere/elastic.v3" "reflect" @@ -18,20 +17,6 @@ type ElkEngine struct { cli *elastic.Client } -var gElkEngine ElkEngine - -func InitELK() { - var e error - elkconf := config.GetElkConfig() - gElkEngine.cli,e = elastic.NewClient( - elastic.SetURL(elkconf.Address), - // Must turn off sniff in docker - elastic.SetSniff(false),) - if nil != e{ - logs.Error(e.Error()) - gElkEngine.cli = nil - } -} diff --git a/db/sqlManager.go b/db/sqlManager.go index 0a61ce9..7685fbf 100644 --- a/db/sqlManager.go +++ b/db/sqlManager.go @@ -13,11 +13,16 @@ import ( "io/ioutil" "log" "os" -) + "gopkg.in/olivere/elastic.v3" +) +var gEla ElkEngine var gDb Database var blogDb Database var gMongo *mgo.Session +var gElkEngine ElkEngine + + func Init() { mysqlconf := config.GetMysqlConfig() blogConf := config.GetMysqlBlogConfig() @@ -35,6 +40,18 @@ func Init() { } } +func InitELK() { + var e error + elkconf := config.GetElkConfig() + gElkEngine.cli,e = elastic.NewClient( + elastic.SetURL(elkconf.Address), + // Must turn off sniff in docker + elastic.SetSniff(false),) + if nil != e{ + logs.Error(e.Error()) + gElkEngine.cli = nil + } +} func initMysql(mysqlconf *config.MysqlConfig) *sql.DB { cnn := fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8", mysqlconf.UserName, mysqlconf.Password, @@ -128,4 +145,8 @@ func InitMongoDb() { log.Print("error mongo initial") os.Exit(25) } +} +func GetElastic() *ElkEngine{ + + return &gElkEngine } \ No newline at end of file diff --git a/model/hardware.go b/model/hardware.go new file mode 100644 index 0000000..868a58c --- /dev/null +++ b/model/hardware.go @@ -0,0 +1,19 @@ +package model + +import "time" + +// this api is based on elasticsearch +type Hardware struct { + ID int32 `json:"id"` + BuyDate time.Time `json:"buy_date"` //购入时间 + Name string `json:"name"` // 名字 + Desc string `json:"desc"` // 描述 + Pic string `json:"pic"` // 图片 + Doc string `json:"doc"` //文档资料 +} + +func (*Hardware )Create() error{ + + + return nil; +} \ No newline at end of file