new
This commit is contained in:
xiexiaojun
2019-05-14 21:18:51 +08:00
parent 42b203ac2d
commit 64b3211d38
9 changed files with 50 additions and 17 deletions

26
dev/dev.go Normal file
View File

@@ -0,0 +1,26 @@
package dev
import (
"os"
"strings"
)
var _isDev = true
//是否开发模式
func OnSetDev(isDev bool) {
_isDev = isDev
}
//OnIsDev ... 是否是开发版本
func OnIsDev() bool {
return _isDev
}
//判断是否在测试环境下使用
func IsRunTesting() bool {
if len(os.Args) > 1 {
return strings.HasPrefix(os.Args[1], "-test")
}
return false
}

View File

@@ -101,12 +101,12 @@ func (es *MyElastic) SortQuery(index_name string, builder []elastic.Sorter, quer
}
//log.Println("Found a total of %d entity\n", es_result.TotalHits())
if es_result.Hits.TotalHits > 0 {
if es_result.Hits.TotalHits.Value > 0 {
var result []string
//log.Println("Found a total of %d entity\n", searchResult.Hits.TotalHits)
for _, hit := range es_result.Hits.Hits {
result = append(result, string(*hit.Source))
result = append(result, string(hit.Source))
}
return true, result
@@ -148,7 +148,7 @@ func (es *MyElastic) SortQueryReturnHits(index_name string, from, size int, buil
}
// log.Println("wwwwww", es_result.Aggregations)
if es_result.Hits.TotalHits > 0 {
if es_result.Hits.TotalHits.Value > 0 {
return true, es_result.Hits.Hits
} else {
@@ -218,7 +218,7 @@ func (es *MyElastic) SearchMap(index_name, type_name string, query interface{},
for _, hit := range es_result.Hits.Hits {
tmp := make(map[string]interface{})
err := json.Unmarshal(*hit.Source, &tmp)
err := json.Unmarshal(hit.Source, &tmp)
if err != nil {
log.Println(es.Err)
} else {
@@ -268,7 +268,7 @@ func (es *MyElastic) Search(index_name, type_name string, query interface{}, out
newValue := reflect.New(sliceElementType)
item := make(map[string]interface{})
err := json.Unmarshal(*hit.Source, &item)
err := json.Unmarshal(hit.Source, &item)
//fmt.Println(string(*hit.Source))
err = scanMapIntoStruct(newValue.Interface(), item)

View File

@@ -1,16 +1,17 @@
package mylog
import (
"data/config"
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"public/myelastic"
"public/myqueue"
"time"
"github.com/xie1xiao1jun/public/dev"
"github.com/xie1xiao1jun/public/myelastic"
"github.com/xie1xiao1jun/public/myqueue"
)
var ptr_que *myqueue.MyQueue = nil
@@ -21,7 +22,7 @@ var local_Log_file string = "log" //默认存放文件的目录
var exe_path string
func init() {
if config.IsRunTesting() { //测试时候不创建
if dev.IsRunTesting() { //测试时候不创建
return
}
@@ -31,7 +32,7 @@ func init() {
BuildDir(local_Log_file)
ptr_que = myqueue.NewSyncQueue()
es_path := config.GetEsAddrUrl()
es_path := ""
if len(es_path) > 0 {
elastic = myelastic.OnInitES(es_path)
elastic.CreateIndex(Http_log_index, mapping)

View File

@@ -1,7 +1,6 @@
package mylog
import (
"data/config"
"fmt"
"log"
"os"
@@ -9,6 +8,8 @@ import (
"path/filepath"
"runtime/debug"
"time"
"github.com/xie1xiao1jun/public/dev"
)
func init() {
@@ -81,7 +82,7 @@ func SaveError(errstring, flag string) {
//
func Debug(describ ...interface{}) {
if config.OnIsDev() {
if dev.OnIsDev() {
for _, e := range describ {
switch v := e.(type) {
case string:

View File

@@ -2,7 +2,8 @@ package mysqldb
import (
"fmt"
"public/mylog"
"github.com/xie1xiao1jun/public/mylog"
"github.com/jinzhu/gorm"
)

View File

@@ -2,7 +2,8 @@ package mysqldb
import (
"fmt"
"public/mylog"
"github.com/xie1xiao1jun/public/mylog"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"

View File

@@ -6,11 +6,12 @@ import (
"encoding/json"
"errors"
"fmt"
"public/mylog"
"regexp"
"strconv"
"strings"
"time"
"github.com/xie1xiao1jun/public/mylog"
)
type RawBytes []byte

View File

@@ -5,7 +5,8 @@ import (
"os"
"os/exec"
"path/filepath"
"public/mylog"
"github.com/xie1xiao1jun/public/mylog"
)
//检查目录是否存在

View File

@@ -5,8 +5,9 @@ import (
"io/ioutil"
"net"
"net/http"
"public/mylog"
"strings"
"github.com/xie1xiao1jun/public/mylog"
)
///*