Commit c975ece2 by zhengqiuyun86

初始化

parent e3aad5f8
package es
import (
"context"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/conf"
"git.168cad.top/zhengqiuyun/rym-util/exception"
"git.168cad.top/zhengqiuyun/rym-util/log"
"github.com/olivere/elastic/v7"
_log "log"
"os"
"testing"
)
func init() {
conf.Es = conf.EsConf{
ServerHost: "to-chengdu-office.168cad.top",
ServerPort: 50037,
}
}
func TestName(t *testing.T) {
host := "http://to-chengdu-office.168cad.top:50037"
var err error
errorLog := _log.New(os.Stdout, "APP", _log.LstdFlags)
client, err := elastic.NewClient(elastic.SetSniff(false), elastic.SetErrorLog(errorLog), elastic.SetURL(host))
if err != nil {
exception.ThrowsErrS(fmt.Sprintf("ES连接失败:%s", err.Error()))
}
info, code, err := client.Ping(host).Do(context.Background())
if err != nil {
panic(err)
}
log.Info(fmt.Sprintf("Elasticsearch connect %d", code))
log.Info(fmt.Sprintf("Elasticsearch version %s", info.Version.Number))
}
package util
func EncodePwd(loginPwd, loginPwdSalt string) string {
pingPwd := loginPwdSalt + loginPwd
return Md5(pingPwd)
}
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"math/rand" "math/rand"
"strconv" "strconv"
"strings"
) )
// 生成: 时间戳 + 设置前缀 + 随即字符串 // 生成: 时间戳 + 设置前缀 + 随即字符串
...@@ -86,3 +87,20 @@ func IsNil(i interface{}) bool { ...@@ -86,3 +87,20 @@ func IsNil(i interface{}) bool {
} }
return false return false
} }
func ContainsForSplitComma(list, item string) bool {
return containsForSplit(list, item, ",")
}
func containsForSplit(list, item, character string) bool {
if !IsEmpty(&list) {
if strings.Contains(list, character) {
return strings.Index(list, item+character) == 0 ||
strings.Contains(list, character+item+character) ||
strings.Index(list, character+item) == len(list)-len(character+item)
} else {
return list == item
}
}
return false
}
package util
import (
"fmt"
"testing"
)
func TestContainsForSplitComma(t *testing.T) {
a := "15"
b := "14"
fmt.Printf("%s是否包含在[%s]中:%v", a, b, ContainsForSplitComma(b, a))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment