Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"goutil/xmlUtil/gxpath/internal/query"
|
||||
"goutil/xmlUtil/gxpath/xpath"
|
||||
)
|
||||
|
||||
func predicate(q query.Query) func(xpath.NodeNavigator) bool {
|
||||
type Predicater interface {
|
||||
Test(xpath.NodeNavigator) bool
|
||||
}
|
||||
if p, ok := q.(Predicater); ok {
|
||||
return p.Test
|
||||
}
|
||||
return func(xpath.NodeNavigator) bool { return true }
|
||||
}
|
||||
|
||||
// positionFunc is a XPath Node Set functions postion().
|
||||
var positionFunc = func(q query.Query, t query.Iterator) interface{} {
|
||||
var (
|
||||
count = 1
|
||||
node = t.Current()
|
||||
)
|
||||
test := predicate(q)
|
||||
for node.MoveToPrevious() {
|
||||
if test(node) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return float64(count)
|
||||
}
|
||||
|
||||
// lastFunc is a XPath Node Set functions last().
|
||||
var lastFunc = func(q query.Query, t query.Iterator) interface{} {
|
||||
var (
|
||||
count = 0
|
||||
node = t.Current()
|
||||
)
|
||||
node.MoveToFirst()
|
||||
test := predicate(q)
|
||||
for {
|
||||
if test(node) {
|
||||
count++
|
||||
}
|
||||
if !node.MoveToNext() {
|
||||
break
|
||||
}
|
||||
}
|
||||
return float64(count)
|
||||
}
|
||||
|
||||
// countFunc is a XPath Node Set functions count(node-set).
|
||||
var countFunc = func(q query.Query, t query.Iterator) interface{} {
|
||||
var (
|
||||
count = 0
|
||||
node = t.Current()
|
||||
)
|
||||
node.MoveToFirst()
|
||||
test := predicate(q)
|
||||
for {
|
||||
if test(node) {
|
||||
count++
|
||||
}
|
||||
if !node.MoveToNext() {
|
||||
break
|
||||
}
|
||||
}
|
||||
return float64(count)
|
||||
}
|
||||
|
||||
// nameFunc is a XPath functions name([node-set]).
|
||||
var nameFunc = func(q query.Query, t query.Iterator) interface{} {
|
||||
return t.Current().LocalName()
|
||||
}
|
||||
|
||||
// startwithFunc is a XPath functions starts-with(string, string).
|
||||
type startwithFunc struct {
|
||||
arg1, arg2 query.Query
|
||||
}
|
||||
|
||||
func (s *startwithFunc) do(q query.Query, t query.Iterator) interface{} {
|
||||
var (
|
||||
m, n string
|
||||
ok bool
|
||||
)
|
||||
switch typ := s.arg1.Evaluate(t).(type) {
|
||||
case string:
|
||||
m = typ
|
||||
case query.Query:
|
||||
node := typ.Select(t)
|
||||
if node == nil {
|
||||
return false
|
||||
}
|
||||
m = node.Value()
|
||||
default:
|
||||
panic(errors.New("starts-with() function argument type must be string"))
|
||||
}
|
||||
n, ok = s.arg2.Evaluate(t).(string)
|
||||
if !ok {
|
||||
panic(errors.New("starts-with() function argument type must be string"))
|
||||
}
|
||||
return strings.HasPrefix(m, n)
|
||||
}
|
||||
|
||||
// normalizespaceFunc is XPath functions normalize-space(string?)
|
||||
var normalizespaceFunc = func(q query.Query, t query.Iterator) interface{} {
|
||||
var m string
|
||||
switch typ := q.Evaluate(t).(type) {
|
||||
case string:
|
||||
m = typ
|
||||
case query.Query:
|
||||
node := typ.Select(t)
|
||||
if node == nil {
|
||||
return false
|
||||
}
|
||||
m = node.Value()
|
||||
}
|
||||
return strings.TrimSpace(m)
|
||||
}
|
||||
|
||||
// substringFunc is XPath functions substring function returns a part of a given string.
|
||||
type substringFunc struct {
|
||||
arg1, arg2, arg3 query.Query
|
||||
}
|
||||
|
||||
func (f *substringFunc) do(q query.Query, t query.Iterator) interface{} {
|
||||
var m string
|
||||
switch typ := f.arg1.Evaluate(t).(type) {
|
||||
case string:
|
||||
m = typ
|
||||
case query.Query:
|
||||
node := typ.Select(t)
|
||||
if node == nil {
|
||||
return false
|
||||
}
|
||||
m = node.Value()
|
||||
}
|
||||
|
||||
var start, length float64
|
||||
var ok bool
|
||||
|
||||
if start, ok = f.arg2.Evaluate(t).(float64); !ok {
|
||||
panic(errors.New("substring() function first argument type must be int"))
|
||||
}
|
||||
if f.arg3 != nil {
|
||||
if length, ok = f.arg3.Evaluate(t).(float64); !ok {
|
||||
panic(errors.New("substring() function second argument type must be int"))
|
||||
}
|
||||
}
|
||||
if (len(m) - int(start)) < int(length) {
|
||||
panic(errors.New("substring() function start and length argument out of range"))
|
||||
}
|
||||
if length > 0 {
|
||||
return m[int(start):int(length+start)]
|
||||
}
|
||||
return m[int(start):]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package mailUtil
|
||||
|
||||
// 定义SMTPClient接口
|
||||
type SMTPClient interface {
|
||||
// 设置服务器
|
||||
SetServer(host string, port int, isSSL bool)
|
||||
|
||||
// 设置发件箱
|
||||
SetSender(name, address, password string)
|
||||
|
||||
//发送邮件:
|
||||
// mailTo 接收方列表
|
||||
// subject 主题
|
||||
// body 正文
|
||||
// isHtmlBody 正文是否html格式
|
||||
// attachFiles 附件
|
||||
SendMail(mailTo []string, subject, body string, isHtmlBody bool, attachFiles []string) error
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package stringUtil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// test 特殊字符
|
||||
func TestEmoji1(t *testing.T) {
|
||||
tstVal := map[string]string{
|
||||
"中文": "你好啊",
|
||||
"繁体中文": "這是什麼天氣",
|
||||
"泰文": "สวัสดีครับ !",
|
||||
"英文": "helloworld",
|
||||
"越南语": "Đó là gì thời tiết.",
|
||||
"日语": "これは何の天気ですか",
|
||||
"标点符号": "!@#$%^^&*())(__+{}[]|:<>",
|
||||
}
|
||||
|
||||
for key, val := range tstVal {
|
||||
if IfHaveEmoji(val) {
|
||||
t.Errorf("语言处理错误:%s", key)
|
||||
}
|
||||
}
|
||||
|
||||
emojiVal := "☀"
|
||||
if IfHaveEmoji(emojiVal) == false {
|
||||
t.Errorf("表情符号匹配错误:")
|
||||
}
|
||||
|
||||
specialChar := "\\'\""
|
||||
if IfHaveEmoji(specialChar) {
|
||||
t.Errorf("特殊字符匹配错误:")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
// ************************************
|
||||
// @package: handleMgr
|
||||
// @description: 全局操作接口管理
|
||||
// @author:
|
||||
// @revision history:
|
||||
// @create date: 2022-02-21 15:53:59
|
||||
// ************************************
|
||||
|
||||
package handleMgr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"Framework/goroutineMgr"
|
||||
"goutil/logUtil"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
handleData = make(map[string]*HandleObj)
|
||||
)
|
||||
|
||||
// RegisterNewModule
|
||||
// @description: 注册调用方法
|
||||
// parameter:
|
||||
// @logicalId:逻辑实例Id-同一串行错误类的唯一标识
|
||||
// @structObject:模块对象
|
||||
// @monitorTime:监控日志超时时间,传入0是用默认值100
|
||||
// return:
|
||||
func RegisterNewModule(logicalId string, structObject interface{}, monitorTime int64) {
|
||||
// 注册模块,开启线程
|
||||
_, isExists := handleData[logicalId]
|
||||
if isExists == false {
|
||||
newHandleObj := NewHandleObj(logicalId)
|
||||
handleData[logicalId] = newHandleObj
|
||||
|
||||
// 设置监控默认值
|
||||
if monitorTime == 0 {
|
||||
monitorTime = 100
|
||||
}
|
||||
|
||||
// 开启监控-channel
|
||||
go func() {
|
||||
registerName := fmt.Sprintf("handleMgr.RegisterNewModule.logicalId=%s", logicalId)
|
||||
goroutineMgr.MonitorZero(registerName)
|
||||
defer goroutineMgr.ReleaseMonitor(registerName)
|
||||
defer logErrorRecover()
|
||||
|
||||
ret := 0
|
||||
for {
|
||||
select {
|
||||
case c := <-newHandleObj.HandleChannel:
|
||||
start := time.Now().UnixMilli()
|
||||
responseObject := CallFunction(c)
|
||||
end := time.Now().UnixMilli()
|
||||
|
||||
if c.IsHaveResult == true {
|
||||
c.ResultChan <- responseObject
|
||||
}
|
||||
if end-start > monitorTime {
|
||||
message := fmt.Sprintf("方法执行时间超长,logicalId:%s,moduleName:%s,MethodName:%s,消耗时间过程,总耗时:%d,需要检查代码!!!!!", logicalId, c.ModuleName, c.MethodName, end-start)
|
||||
logUtil.ErrorLog(message)
|
||||
}
|
||||
|
||||
ret++
|
||||
if ret == 100 {
|
||||
num := len(newHandleObj.HandleChannel)
|
||||
if num > 500 {
|
||||
message := fmt.Sprintf("时间戳:%d,channel监控,内部待执行操作过多,logicalId:%s,当前待执行数量:%d,需要检查代码!!!!!", time.Now().UnixMilli(), logicalId, num)
|
||||
logUtil.ErrorLog(message)
|
||||
}
|
||||
}
|
||||
default:
|
||||
// 如果找不到数据则休眠5ms
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// 注册对象
|
||||
RegisterFunction(structObject)
|
||||
}
|
||||
|
||||
// Done
|
||||
// @description: 执行访问
|
||||
// parameter:
|
||||
// @logicalId:逻辑实例Id-同一串行错误类的唯一标识
|
||||
// @moduleName:模块名
|
||||
// @funcName:执行方法名称
|
||||
// @parameter:方法参数
|
||||
// @isHaveResult:是否处理返回值
|
||||
// return:
|
||||
// @data:返还对象
|
||||
// @code:错误码-0未无错误
|
||||
// @message:错误说明-空字符串为无错误
|
||||
func Done(logicalId string, moduleName string, funcName string, parameter []interface{}, isHaveResult bool) (data interface{}, code int, message string) {
|
||||
responseObj := NewRequestObject(moduleName, funcName, parameter, isHaveResult)
|
||||
handleObj, isExists := handleData[logicalId]
|
||||
if isExists == false {
|
||||
message := fmt.Sprintf("未注册模块,moduleName:%s", moduleName)
|
||||
logUtil.ErrorLog(message)
|
||||
return nil, -1, message
|
||||
}
|
||||
handleObj.HandleChannel <- responseObj
|
||||
if responseObj.IsHaveResult == false {
|
||||
return nil, 0, ""
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case responseObject := <-responseObj.ResultChan:
|
||||
// 处理返回值
|
||||
return responseObject.Data, 0, responseObject.Message
|
||||
default:
|
||||
// 如果找不到数据则休眠5ms
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// logErrorRecover
|
||||
// @description: 打印日志
|
||||
// parameter:
|
||||
// return:
|
||||
func logErrorRecover() {
|
||||
if err := recover(); err != nil {
|
||||
msg := fmt.Sprintf("err msg:%s stack:%s", err, debug.Stack())
|
||||
logUtil.ErrorLog(msg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user