Commit 262c2a33 authored by wei.xuan's avatar wei.xuan

remove timer

parent 622d6d17
......@@ -31,8 +31,6 @@ import (
"github.com/adamweixuan/gostnops/bytes"
"github.com/adamweixuan/gostnops/net"
gxsync "github.com/adamweixuan/gostnops/sync"
gxtime "github.com/adamweixuan/gostnops/time"
"github.com/gorilla/websocket"
perrors "github.com/pkg/errors"
......@@ -149,7 +147,7 @@ func (c *client) dialTCP() Session {
}
log.Warnf("net.DialTimeout(addr:%s, timeout:%v) = error:%+v", c.addr, connectTimeout, err)
<-gxtime.After(time.Millisecond * time.Duration(c.reconnectInterval))
<-time.After(time.Millisecond * time.Duration(c.reconnectInterval))
}
}
......@@ -180,7 +178,7 @@ func (c *client) dialUDP() Session {
}
if err != nil {
log.Warnf("net.DialTimeout(addr:%s, timeout:%v) = error:%+v", c.addr, perrors.WithStack(err))
<-gxtime.After(connectInterval)
<-time.After(connectInterval)
continue
}
......@@ -189,7 +187,7 @@ func (c *client) dialUDP() Session {
if length, err = conn.Write(connectPingPackage[:]); err != nil {
conn.Close()
log.Warnf("conn.Write(%s) = {length:%d, err:%+v}", string(connectPingPackage), length, perrors.WithStack(err))
<-gxtime.After(connectInterval)
<-time.After(connectInterval)
continue
}
conn.SetReadDeadline(time.Now().Add(1e9))
......@@ -200,7 +198,7 @@ func (c *client) dialUDP() Session {
if err != nil {
log.Infof("conn{%#v}.Read() = {length:%d, err:%+v}", conn, length, perrors.WithStack(err))
conn.Close()
<-gxtime.After(connectInterval)
<-time.After(connectInterval)
continue
}
return newUDPSession(conn, c)
......@@ -236,7 +234,7 @@ func (c *client) dialWS() Session {
}
log.Infof("websocket.dialer.Dial(addr:%s) = error:%+v", c.addr, perrors.WithStack(err))
<-gxtime.After(connectInterval)
<-time.After(connectInterval)
}
}
......@@ -314,7 +312,7 @@ func (c *client) dialWSS() Session {
}
log.Infof("websocket.dialer.Dial(addr:%s) = error:%+v", c.addr, perrors.WithStack(err))
<-gxtime.After(connectInterval)
<-time.After(connectInterval)
}
}
......@@ -418,7 +416,7 @@ func (c *client) reConnect() {
}
rinterval := time.Duration(int64(times) * int64(interval))
log.Infof("==============client reConnect %+v===========", rinterval)
<-gxtime.After(rinterval)
<-time.After(rinterval)
}
}
......
......@@ -3,7 +3,7 @@ module github.com/adamweixuan/getty
go 1.17
require (
github.com/adamweixuan/gostnops v1.11.20-0.20211029124314-3f0589fceea6
github.com/adamweixuan/gostnops v0.0.1
github.com/gorilla/websocket v1.4.2
github.com/pkg/errors v0.9.1
go.uber.org/atomic v1.9.0
......
github.com/adamweixuan/gostnops v1.11.20-0.20211029124314-3f0589fceea6 h1:UGMsACjkGfNRKCz5U8ijtkpKL8o/25rGHxTV1adWjak=
github.com/adamweixuan/gostnops v1.11.20-0.20211029124314-3f0589fceea6/go.mod h1:zZYjPhU2+ujyEOWWE0l1pEdf5H4CyfiMG//rSpNjwcQ=
github.com/adamweixuan/gostnops v0.0.1 h1:oBfrRgBoRyaGjBTfq0DGH07jARS4OqN7jbSv1Mn05Fg=
github.com/adamweixuan/gostnops v0.0.1/go.mod h1:lTe81VUWCpja0NOVqXyi2cH28m2hYezzhTt3MudpDbU=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
......
......@@ -125,3 +125,29 @@ func Online(logfile string) error {
log = zapLogger.Sugar()
return nil
}
func NewLogger(logName string, level LoggerLevel) Logger {
config := zap.NewDevelopmentConfig()
config.EncoderConfig = zapcore.EncoderConfig{
TimeKey: "time",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
MessageKey: "message",
StacktraceKey: "stacktrace",
EncodeLevel: zapcore.CapitalColorLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
}
config.Level = zap.NewAtomicLevelAt(zapcore.Level(level))
config.OutputPaths = []string{logName}
config.Development = false
config.DisableCaller = true
config.DisableStacktrace = true
zapLogger, err := config.Build()
if err != nil {
panic(err)
}
return zapLogger.Sugar()
}
......@@ -31,7 +31,6 @@ import (
gxnet "github.com/adamweixuan/gostnops/net"
gxsync "github.com/adamweixuan/gostnops/sync"
gxtime "github.com/adamweixuan/gostnops/time"
"github.com/gorilla/websocket"
perrors "github.com/pkg/errors"
uatomic "go.uber.org/atomic"
......@@ -287,7 +286,7 @@ func (s *server) runTCPEventLoop(newSession NewSessionCallback) {
return
}
if delay != 0 {
<-gxtime.After(delay)
<-time.After(delay)
}
client, err = s.accept(newSession)
if err != nil {
......
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