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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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