diff --git a/config/config.go b/config/config.go index 299e79f..a792bfa 100644 --- a/config/config.go +++ b/config/config.go @@ -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 + } +} \ No newline at end of file diff --git a/db/elasticEngine.go b/db/elasticEngine.go new file mode 100644 index 0000000..87f0046 --- /dev/null +++ b/db/elasticEngine.go @@ -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 +} + diff --git a/main.go b/main.go index ebed65a..5a4f995 100644 --- a/main.go +++ b/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," +