mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-01-23 02:40:23 +08:00
perf: 根据golangci检测结果,优化部分代码
This commit is contained in:
parent
5c3bcaf6cc
commit
9133afb864
@ -103,7 +103,7 @@ func (e *tagElement) write(bf *formattedBuffer, isPreviousNodeInline bool) bool
|
||||
}
|
||||
}
|
||||
|
||||
if e.isInline() || bytes.IndexAny(condensedBuffer.buffer.Bytes()[1:], "\n") == -1 {
|
||||
if e.isInline() || bytes.ContainsAny(condensedBuffer.buffer.Bytes()[1:], "\n") {
|
||||
// If we're an inline tag, or there were no newlines were in the buffer,
|
||||
// replace the original with the condensed version
|
||||
condensedBuffer.buffer = bytes.NewBuffer(bytes.Join([][]byte{
|
||||
|
@ -97,5 +97,5 @@ func (bf *formattedBuffer) writeToken(token string, kind formatterTokenType) {
|
||||
|
||||
// unifyLineFeed unifies line feeds.
|
||||
func unifyLineFeed(s string) string {
|
||||
return strings.Replace(strings.Replace(s, "\r\n", "\n", -1), "\r", "\n", -1)
|
||||
return strings.ReplaceAll(strings.ReplaceAll(s, "\r\n", "\n"), "\r", "\n")
|
||||
}
|
||||
|
@ -8,14 +8,6 @@ package views
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"golang.org/x/tools/imports"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/hggen/views/gohtml"
|
||||
"hotgo/internal/model"
|
||||
@ -27,6 +19,15 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"golang.org/x/tools/imports"
|
||||
)
|
||||
|
||||
// parseServFunName 解析业务服务名称
|
||||
@ -242,9 +243,10 @@ func CheckTreeTableFields(columns []*sysin.GenCodesColumnListModel) (err error)
|
||||
|
||||
// CheckIllegalName 检查命名是否合理
|
||||
func CheckIllegalName(errPrefix string, names ...string) (err error) {
|
||||
reg, _ := regexp.Compile("^[a-z_][a-z0-9_]*$")
|
||||
for _, name := range names {
|
||||
name = strings.ToLower(name)
|
||||
match, _ := regexp.MatchString("^[a-z_][a-z0-9_]*$", name)
|
||||
match := reg.MatchString(name)
|
||||
if !match {
|
||||
err = gerror.Newf("%v存在格式不正确,必须全部小写且由字母、数字和下划线组成:%v", errPrefix, name)
|
||||
return
|
||||
|
@ -7,10 +7,11 @@ package hgorm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/utility/tree"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// TenantRelation 租户关系
|
||||
@ -85,7 +86,7 @@ func GetTenantRelation(ctx context.Context, memberId int64) (tr *TenantRelation,
|
||||
}
|
||||
tr.UserId = memberId
|
||||
default:
|
||||
err = gerror.Newf("未找到用户[%]的租户关系,部门类型[%v] 无效", memberId, tr.DeptType)
|
||||
err = gerror.Newf("未找到用户[%v]的租户关系,部门类型[%v] 无效", memberId, tr.DeptType)
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
|
@ -8,6 +8,13 @@ package location
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"hotgo/utility/validate"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gcharset"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@ -15,12 +22,6 @@ import (
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/kayon/iploc"
|
||||
"hotgo/utility/validate"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -72,7 +73,7 @@ func WhoisLocation(ctx context.Context, ip string, retry ...int64) (*IpLocationD
|
||||
|
||||
// 利用重试机制缓解高并发情况下限流的影响
|
||||
// 毕竟这是一个免费的接口,如果你对IP归属地定位要求毕竟高,可以考虑换个付费接口
|
||||
if response.StatusCode != 200 {
|
||||
if response.StatusCode != http.StatusOK {
|
||||
retryCount := defaultRetry
|
||||
if len(retry) > 0 {
|
||||
retryCount = retry[0]
|
||||
|
@ -7,6 +7,12 @@ package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/utility/simple"
|
||||
"hotgo/utility/validate"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/apache/rocketmq-client-go/v2"
|
||||
"github.com/apache/rocketmq-client-go/v2/admin"
|
||||
"github.com/apache/rocketmq-client-go/v2/consumer"
|
||||
@ -16,11 +22,6 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/grpool"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/utility/simple"
|
||||
"hotgo/utility/validate"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RocketMq struct {
|
||||
@ -191,7 +192,7 @@ func (r *RocketMq) ListenReceiveMsgDo(topic string, receiveDo func(mqMsg MqMsg))
|
||||
|
||||
err = r.consumerIns.Subscribe(topic, consumer.MessageSelector{}, func(ctx context.Context, msgs ...*primitive.MessageExt) (consumer.ConsumeResult, error) {
|
||||
for _, item := range msgs {
|
||||
rocketManager.goPool.Add(ctx, func(ctx context.Context) {
|
||||
_ = rocketManager.goPool.Add(ctx, func(ctx context.Context) {
|
||||
receiveDo(MqMsg{
|
||||
RunType: ReceiveMsg,
|
||||
Topic: item.Topic,
|
||||
|
Loading…
Reference in New Issue
Block a user