添加elk DB框架
parent
e275a3e2c8
commit
89b31ebf88
|
@ -19,6 +19,7 @@ type ConfAPI struct {
|
|||
Logs LogConfig `yaml:"logs"` // 日志
|
||||
Redis1 EntityRedis `yaml:"redis1"`
|
||||
Mysql MysqlConfig `yaml:"mysql"` // 认证配置
|
||||
ElasticSerach ElasticSearch `yaml:"elasticsearch"`
|
||||
Mysql1 MysqlConfig `yaml:"mysql1"` // 认证配置
|
||||
MongoConf MongoConfig `yaml:"mongo"`
|
||||
CaCert string `yaml:"ca_cert"`
|
||||
|
@ -26,6 +27,9 @@ type ConfAPI struct {
|
|||
ClientKey string `yaml:"client_key"'`
|
||||
init bool
|
||||
}
|
||||
type ElasticSearch struct{
|
||||
Address string `yaml:"string"`
|
||||
}
|
||||
|
||||
type EntityRedis struct {
|
||||
Addr string `yaml:"addr"`
|
||||
|
@ -132,3 +136,10 @@ func GetLogConfig() *LogConfig {
|
|||
}
|
||||
}
|
||||
|
||||
func GetElkConfig() *ElasticSearch{
|
||||
if gConf.init{
|
||||
return &gConf.ElasticSerach
|
||||
}else {
|
||||
return nil
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
7
main.go
7
main.go
|
@ -44,7 +44,12 @@ func InitLogs() {
|
|||
}
|
||||
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-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-Allow-Headers",
|
||||
"X-Requested-With," +
|
||||
|
|
Loading…
Reference in New Issue