perf: 优化代码结构,去除无用代码,去除重复代码
This commit is contained in:
parent
a23e48b087
commit
47b8a333eb
|
@ -122,12 +122,6 @@ func (slf *Activity[PlayerID, ActivityData, PlayerData]) IsInvalid() bool {
|
|||
current := activityOffset.Now()
|
||||
if slf.beforeShow.IsZero() && !slf.afterShow.IsZero() {
|
||||
return current.After(slf.afterShow) || current.Equal(slf.afterShow)
|
||||
} else if !slf.beforeShow.IsZero() && slf.afterShow.IsZero() {
|
||||
end := slf.GetEnd()
|
||||
return current.After(end) || current.Equal(end)
|
||||
} else if !slf.beforeShow.IsZero() && !slf.afterShow.IsZero() {
|
||||
end := slf.GetEnd()
|
||||
return current.After(end) || current.Equal(end)
|
||||
} else {
|
||||
end := slf.GetEnd()
|
||||
return current.After(end) || current.Equal(end)
|
||||
|
|
|
@ -2,6 +2,11 @@ package server
|
|||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
serverMultipleMark = "Minotaur Multiple Server"
|
||||
serverMark = "Minotaur Server"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultMessageBufferSize = 1024
|
||||
DefaultMessageChannelSize = 1024 * 4096
|
||||
|
|
|
@ -11,6 +11,10 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
nasMark = "Cross.Nats"
|
||||
)
|
||||
|
||||
func NewNats(url string, options ...NatsOption) *Nats {
|
||||
n := &Nats{
|
||||
url: url,
|
||||
|
@ -43,10 +47,10 @@ func (slf *Nats) Init(server *server.Server, packetHandle func(serverId int64, p
|
|||
nats.ReconnectWait(time.Second*5),
|
||||
nats.MaxReconnects(-1),
|
||||
nats.DisconnectErrHandler(func(conn *nats.Conn, err error) {
|
||||
log.Error("Cross.Nats", zap.String("info", "disconnect"), zap.Error(err))
|
||||
log.Error(nasMark, zap.String("info", "disconnect"), zap.Error(err))
|
||||
}),
|
||||
nats.ReconnectHandler(func(conn *nats.Conn) {
|
||||
log.Info("Cross.Nats", zap.String("info", "reconnect"))
|
||||
log.Info(nasMark, zap.String("info", "reconnect"))
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
@ -59,7 +63,7 @@ func (slf *Nats) Init(server *server.Server, packetHandle func(serverId int64, p
|
|||
message := slf.messagePool.Get()
|
||||
defer slf.messagePool.Release(message)
|
||||
if err := json.Unmarshal(msg.Data, &message); err != nil {
|
||||
log.Error("Cross.Nats", zap.Error(err))
|
||||
log.Error(nasMark, zap.Error(err))
|
||||
return
|
||||
}
|
||||
packetHandle(message.ServerId, message.Packet)
|
||||
|
|
|
@ -60,14 +60,14 @@ func (slf *MultipleServer) Run() {
|
|||
}
|
||||
wait.Wait()
|
||||
|
||||
log.Info("Server", zap.String("Minotaur Multiple Server", "===================================================================="))
|
||||
log.Info("Server", zap.String(serverMultipleMark, "===================================================================="))
|
||||
for _, server := range slf.servers {
|
||||
log.Info("Server", zap.String("Minotaur Multiple Server", "RunningInfo"),
|
||||
log.Info("Server", zap.String(serverMultipleMark, "RunningInfo"),
|
||||
zap.Any("network", server.network),
|
||||
zap.String("listen", server.addr),
|
||||
)
|
||||
}
|
||||
log.Info("Server", zap.String("Minotaur Multiple Server", "===================================================================="))
|
||||
log.Info("Server", zap.String(serverMultipleMark, "===================================================================="))
|
||||
|
||||
systemSignal := make(chan os.Signal, 1)
|
||||
signal.Notify(systemSignal, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||
|
|
|
@ -259,7 +259,7 @@ func (slf *Server) Run(addr string) error {
|
|||
conn := newWebsocketConn(slf, ws, ip)
|
||||
for k, v := range request.URL.Query() {
|
||||
if len(v) == 1 {
|
||||
conn.SetData(k, v)
|
||||
conn.SetData(k, v[0])
|
||||
} else {
|
||||
conn.SetData(k, v)
|
||||
}
|
||||
|
@ -307,12 +307,12 @@ func (slf *Server) Run(addr string) error {
|
|||
}
|
||||
|
||||
if slf.multiple == nil {
|
||||
log.Info("Server", zap.String("Minotaur Server", "===================================================================="))
|
||||
log.Info("Server", zap.String("Minotaur Server", "RunningInfo"),
|
||||
log.Info("Server", zap.String(serverMark, "===================================================================="))
|
||||
log.Info("Server", zap.String(serverMark, "RunningInfo"),
|
||||
zap.Any("network", slf.network),
|
||||
zap.String("listen", slf.addr),
|
||||
)
|
||||
log.Info("Server", zap.String("Minotaur Server", "===================================================================="))
|
||||
log.Info("Server", zap.String(serverMark, "===================================================================="))
|
||||
slf.OnStartFinishEvent()
|
||||
|
||||
signal.Notify(slf.systemSignal, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||
|
|
|
@ -48,10 +48,6 @@ func (slf *Map[Key, Value]) GetExist(key Key) (Value, bool) {
|
|||
return value, exist
|
||||
}
|
||||
|
||||
func (slf *Map[Key, Value]) Length() int {
|
||||
return len(slf.data)
|
||||
}
|
||||
|
||||
func (slf *Map[Key, Value]) Delete(key Key) {
|
||||
delete(slf.data, key)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package geometry
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
// ErrUnexplainedDirection 错误的方向
|
||||
ErrUnexplainedDirection = errors.New("unexplained direction")
|
||||
)
|
|
@ -48,7 +48,7 @@ func GetDirectionNextWithCoordinate[V generic.SignedNumber](direction Direction,
|
|||
case DirectionRight:
|
||||
nx, ny = x+1, y
|
||||
default:
|
||||
panic("unexplained direction")
|
||||
panic(ErrUnexplainedDirection)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func GetDirectionNextWithPoint[V generic.SignedNumber](direction Direction, poin
|
|||
case DirectionRight:
|
||||
return NewPoint(x+1, y)
|
||||
default:
|
||||
panic("unexplained direction")
|
||||
panic(ErrUnexplainedDirection)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ func GetDirectionNextWithPos[V generic.SignedNumber](direction Direction, width,
|
|||
case DirectionRight:
|
||||
return pos + 1
|
||||
default:
|
||||
panic("unexplained direction")
|
||||
panic(ErrUnexplainedDirection)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ type MapReadonly[Key comparable, Value any] interface {
|
|||
Get(key Key) Value
|
||||
Exist(key Key) bool
|
||||
GetExist(key Key) (Value, bool)
|
||||
Length() int
|
||||
Range(handle func(key Key, value Value))
|
||||
RangeSkip(handle func(key Key, value Value) bool)
|
||||
RangeBreakout(handle func(key Key, value Value) bool)
|
||||
|
|
|
@ -17,12 +17,12 @@ func HideSensitivity(str string) (result string) {
|
|||
if len(res[0]) < 3 {
|
||||
resString := "***"
|
||||
result = resString + "@" + res[1]
|
||||
} else {
|
||||
resRs := []rune(str)
|
||||
res2 := string(resRs[0:3])
|
||||
resString := res2 + "***"
|
||||
result = resString + "@" + res[1]
|
||||
return result
|
||||
}
|
||||
resRs := []rune(str)
|
||||
res2 := string(resRs[0:3])
|
||||
resString := res2 + "***"
|
||||
result = resString + "@" + res[1]
|
||||
return result
|
||||
} else {
|
||||
reg := `^1[0-9]\d{9}$`
|
||||
|
@ -31,22 +31,21 @@ func HideSensitivity(str string) (result string) {
|
|||
if mobileMatch {
|
||||
rs := []rune(str)
|
||||
result = string(rs[0:5]) + "****" + string(rs[7:11])
|
||||
return
|
||||
}
|
||||
nameRune := []rune(str)
|
||||
lens := len(nameRune)
|
||||
|
||||
} else {
|
||||
nameRune := []rune(str)
|
||||
lens := len(nameRune)
|
||||
|
||||
if lens <= 1 {
|
||||
result = "***"
|
||||
} else if lens == 2 {
|
||||
result = string(nameRune[:1]) + "*"
|
||||
} else if lens == 3 {
|
||||
result = string(nameRune[:1]) + "*" + string(nameRune[2:3])
|
||||
} else if lens == 4 {
|
||||
result = string(nameRune[:1]) + "**" + string(nameRune[lens-1:lens])
|
||||
} else if lens > 4 {
|
||||
result = string(nameRune[:2]) + "***" + string(nameRune[lens-2:lens])
|
||||
}
|
||||
if lens <= 1 {
|
||||
result = "***"
|
||||
} else if lens == 2 {
|
||||
result = string(nameRune[:1]) + "*"
|
||||
} else if lens == 3 {
|
||||
result = string(nameRune[:1]) + "*" + string(nameRune[2:3])
|
||||
} else if lens == 4 {
|
||||
result = string(nameRune[:1]) + "**" + string(nameRune[lens-1:lens])
|
||||
} else if lens > 4 {
|
||||
result = string(nameRune[:2]) + "***" + string(nameRune[lens-2:lens])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -74,14 +74,6 @@ func (slf *Map[Key, Value]) GetExist(key Key) (Value, bool) {
|
|||
return value, exist
|
||||
}
|
||||
|
||||
func (slf *Map[Key, Value]) Length() int {
|
||||
if !slf.atom {
|
||||
slf.lock.RLock()
|
||||
defer slf.lock.RUnlock()
|
||||
}
|
||||
return len(slf.data)
|
||||
}
|
||||
|
||||
func (slf *Map[Key, Value]) Delete(key Key) {
|
||||
if !slf.atom {
|
||||
slf.lock.Lock()
|
||||
|
|
|
@ -87,12 +87,6 @@ func (slf *MapSegment[Key, Value]) GetExist(key Key) (value Value, exist bool) {
|
|||
return slf.segments[s].GetExist(key)
|
||||
}
|
||||
|
||||
func (slf *MapSegment[Key, Value]) Length() int {
|
||||
slf.lock.RLock()
|
||||
defer slf.lock.RUnlock()
|
||||
return len(slf.cache)
|
||||
}
|
||||
|
||||
func (slf *MapSegment[Key, Value]) Delete(key Key) {
|
||||
slf.lock.Lock()
|
||||
s, exist := slf.cache[key]
|
||||
|
|
Loading…
Reference in New Issue