README.md | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
config/config.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
config/config.yaml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
main.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
model/model.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
service/server.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
README.md
@@ -2,3 +2,10 @@ 重庆项目推送图片 ###功能 定时读取本地es的报警数据,同步到云端 ###部署 /opt/vasystem/procs/esSync-client /opt/vasystem/config/esSync.yaml config/config.go
@@ -1,25 +1,34 @@ package config import ( "github.com/fsnotify/fsnotify" "github.com/spf13/viper" "log" ) type servUrls struct { type common struct { EsUrl string `mapstructure: "esUrl"` ServerUrl string `mapstructure: "serverUrl"` OrgName string `mapstructure: "orgName"` } var ServUrls = &servUrls{} var Options = &common{} func Init(env string) { func Init() { var err error viper.SetConfigType("yaml") viper.SetConfigName(env) viper.SetConfigName("esSync") viper.AddConfigPath("../config") viper.AddConfigPath("config") viper.AddConfigPath("") err = viper.ReadInConfig() if err != nil { log.Fatal("error on parsing configuration file", err) } viper.UnmarshalKey("servUrls", ServUrls) viper.UnmarshalKey("common", Options) viper.WatchConfig() viper.OnConfigChange(func(in fsnotify.Event) { viper.UnmarshalKey("common", Options) }) } config/config.yaml
@@ -1,3 +1,4 @@ servUrls: esUrl: 192.168.20.223:9200 serverUrl: http://192.168.20.119:9696/api-a/device/alarm common: esUrl: 192.168.10.10:9200 serverUrl: http://smartai.com:7012/api-a/device/alarm orgName: Basic main.go
@@ -3,34 +3,21 @@ import ( "data_msg_push_server/config" "data_msg_push_server/service" "flag" "fmt" "time" ) var env = flag.String("config", "config", "read storage info") func init() { config.Init(*env) config.Init() } func main() { fmt.Println("hello!!!") done := make(chan bool) go runEvery(done) //result,err := service.GetData() //if err != nil { // fmt.Println(err) //} //if result != nil{ // //} <-done fmt.Println("程序已退出") //fmt.Println(res) //fmt.Println(err) } func runEvery(done chan<- bool){ @@ -64,7 +51,7 @@ connectStatus := service.ConnectControl() fmt.Println("connectStatus: ",connectStatus) if connectStatus == true { url := config.ServUrls.ServerUrl url := config.Options.ServerUrl result, err1 := service.GetData() if err1 != nil { fmt.Println(err1) model/model.go
@@ -6,5 +6,8 @@ PicSmImages [][]byte `json:"picSmImages"` } var PushDataInfo = &pushDataInfo{SourceData: nil, PicMaxImages: nil, PicSmImages: nil} var PushDataInfo = &pushDataInfo{ SourceData: nil, PicMaxImages: nil, PicSmImages: nil, } service/server.go
@@ -13,7 +13,7 @@ ) func ConnectControl() bool { url := config.ServUrls.ServerUrl url := config.Options.ServerUrl resp, err := http.Get(url) if err != nil { fmt.Println("连接失败", err) @@ -26,7 +26,7 @@ } func GetTotal() (total int, err error) { url := "http://" + config.ServUrls.EsUrl + "/ai_ocean/_search" url := "http://" + config.Options.EsUrl + "/ai_ocean/_search" queryDSL := `{ "size": "1", "query": { @@ -63,9 +63,9 @@ } func GetData() (interface{}, error) { //fmt.Println(config.ServUrls.EsUrl) //fmt.Println(config.ServUrls.ServerUrl) url := "http://" + config.ServUrls.EsUrl + "/ai_ocean/_search" //fmt.Println(config.Options.EsUrl) //fmt.Println(config.Options.ServerUrl) url := "http://" + config.Options.EsUrl + "/ai_ocean/_search" queryDSL := `{ "size": "1", "query": { @@ -132,6 +132,10 @@ picSmImages = append(picSmImages, picSmImageData) } } // 上报机构名称 source[0]["orgName"] = config.Options.OrgName model.PushDataInfo.SourceData = source[0] model.PushDataInfo.PicMaxImages = picMaxImages model.PushDataInfo.PicSmImages = picSmImages @@ -172,7 +176,7 @@ } func DeleteData(id string) bool { url := "http://" + config.ServUrls.EsUrl + "/ai_ocean/_delete_by_query?refresh=true" url := "http://" + config.Options.EsUrl + "/ai_ocean/_delete_by_query?refresh=true" deleteDSL := `{ "query":{ "bool":{ @@ -199,7 +203,7 @@ } func MarkData(id string) bool { url := "http://" + config.ServUrls.EsUrl + "/ai_ocean/_update_by_query?refresh=true" url := "http://" + config.Options.EsUrl + "/ai_ocean/_update_by_query?refresh=true" markDSL := `{ "script": { "source": "ctx._source.isDelete=true"