添加elk DB框架

master
a7458969 2020-03-13 17:40:00 +08:00
parent e275a3e2c8
commit 89b31ebf88
3 changed files with 50 additions and 1 deletions

View File

@ -19,6 +19,7 @@ type ConfAPI struct {
Logs LogConfig `yaml:"logs"` // 日志 Logs LogConfig `yaml:"logs"` // 日志
Redis1 EntityRedis `yaml:"redis1"` Redis1 EntityRedis `yaml:"redis1"`
Mysql MysqlConfig `yaml:"mysql"` // 认证配置 Mysql MysqlConfig `yaml:"mysql"` // 认证配置
ElasticSerach ElasticSearch `yaml:"elasticsearch"`
Mysql1 MysqlConfig `yaml:"mysql1"` // 认证配置 Mysql1 MysqlConfig `yaml:"mysql1"` // 认证配置
MongoConf MongoConfig `yaml:"mongo"` MongoConf MongoConfig `yaml:"mongo"`
CaCert string `yaml:"ca_cert"` CaCert string `yaml:"ca_cert"`
@ -26,6 +27,9 @@ type ConfAPI struct {
ClientKey string `yaml:"client_key"'` ClientKey string `yaml:"client_key"'`
init bool init bool
} }
type ElasticSearch struct{
Address string `yaml:"string"`
}
type EntityRedis struct { type EntityRedis struct {
Addr string `yaml:"addr"` Addr string `yaml:"addr"`
@ -132,3 +136,10 @@ func GetLogConfig() *LogConfig {
} }
} }
func GetElkConfig() *ElasticSearch{
if gConf.init{
return &gConf.ElasticSerach
}else {
return nil
}
}

33
db/elasticEngine.go Normal file
View File

@ -0,0 +1,33 @@
package db
import (
"background/config"
"background/logs"
"gopkg.in/olivere/elastic.v3"
)
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
}
}
func (*ElkEngine)Search() (error) {
return nil
}

View File

@ -44,7 +44,12 @@ func InitLogs() {
} }
func CORSMiddleware(c *gin.Context) { func CORSMiddleware(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
c.Writer.Header().Set("Access-Control-Allow-Origin", "http://localhost:8080,https://www.testingcloud.club/,https://testingcloud.club/") if config.ApiConfig().RunMode == "release"{
c.Writer.Header().Set("Access-Control-Allow-Origin", "https://testingcloud.club")
}else{
c.Writer.Header().Set("Access-Control-Allow-Origin", "http://localhost:8080")
}
c.Writer.Header().Set("Access-Control-Max-Age", "86400") c.Writer.Header().Set("Access-Control-Max-Age", "86400")
c.Writer.Header().Set("Access-Control-Allow-Headers", c.Writer.Header().Set("Access-Control-Allow-Headers",
"X-Requested-With," + "X-Requested-With," +