进度更新,添加硬件管理接口

master
a7458969 2020-03-23 23:58:39 +08:00
parent 3f2d6707f5
commit 6459690768
4 changed files with 44 additions and 26 deletions

View File

@ -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}

View File

@ -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
}
}

View File

@ -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
}

19
model/hardware.go Normal file
View File

@ -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;
}