Unverified Commit f9499a7e authored by Xin.Zh's avatar Xin.Zh Committed by GitHub

Merge pull request #59 from georgehao/master

feat: format use gofumpt
parents 30e62643 0df9283b
......@@ -54,9 +54,7 @@ var (
// getty tcp client
/////////////////////////////////////////
var (
clientID = EndPointID(0)
)
var clientID = EndPointID(0)
type client struct {
ClientOptions
......@@ -225,7 +223,7 @@ func (c *client) dialUDP() Session {
<-wheel.After(connectInterval)
continue
}
//if err == nil {
// if err == nil {
return newUDPSession(conn, c)
//}
}
......
......@@ -120,11 +120,9 @@ func TestTCPClient(t *testing.T) {
)
assert.NotNil(t, clt)
assert.True(t, clt.ID() > 0)
//assert.Equal(t, clt.endPointType, TCP_CLIENT)
// assert.Equal(t, clt.endPointType, TCP_CLIENT)
var (
msgHandler MessageHandler
)
var msgHandler MessageHandler
cb := func(session Session) error {
return newSessionCallback(session, &msgHandler)
}
......@@ -193,11 +191,9 @@ func TestUDPClient(t *testing.T) {
)
assert.NotNil(t, clt)
assert.True(t, clt.ID() > 0)
//assert.Equal(t, clt.endPointType, UDP_CLIENT)
// assert.Equal(t, clt.endPointType, UDP_CLIENT)
var (
msgHandler MessageHandler
)
var msgHandler MessageHandler
cb := func(session Session) error {
return newSessionCallback(session, &msgHandler)
}
......@@ -256,7 +252,7 @@ func TestUDPClient(t *testing.T) {
assert.True(t, clt.IsClosed())
msgHandler.array[0].Reset()
assert.Nil(t, msgHandler.array[0].Conn())
//ss.WritePkg([]byte("hello"), 0)
// ss.WritePkg([]byte("hello"), 0)
}
func TestNewWSClient(t *testing.T) {
......@@ -283,9 +279,7 @@ func TestNewWSClient(t *testing.T) {
WithConnectionNumber(1),
)
var (
msgHandler MessageHandler
)
var msgHandler MessageHandler
cb := func(session Session) error {
return newSessionCallback(session, &msgHandler)
}
......@@ -437,9 +431,7 @@ func TestNewWSSClient(t *testing.T) {
WithRootCertificateFile(WssClientCRTFile),
)
var (
msgHandler MessageHandler
)
var msgHandler MessageHandler
cb := func(session Session) error {
return newSessionCallback(session, &msgHandler)
}
......@@ -451,7 +443,7 @@ func TestNewWSSClient(t *testing.T) {
client.Close()
assert.True(t, client.IsClosed())
assert.False(t, server.IsClosed())
//time.Sleep(1000e9)
//server.Close()
//assert.True(t, server.IsClosed())
// time.Sleep(1000e9)
// server.Close()
// assert.True(t, server.IsClosed())
}
......@@ -34,19 +34,13 @@ import (
perrors "github.com/pkg/errors"
)
var (
launchTime = time.Now()
// ErrInvalidConnection = perrors.New("connection has been closed.")
)
var launchTime = time.Now() // ErrInvalidConnection = perrors.New("connection has been closed.")
/////////////////////////////////////////
// getty connection
/////////////////////////////////////////
var (
connID uint32
)
var connID uint32
type gettyConn struct {
id uint32
......@@ -260,7 +254,7 @@ func (t *gettyTCPConn) recv(p []byte) (int, error) {
// log.Debugf("now:%s, length:%d, err:%v", currentTime, length, err)
atomic.AddUint32(&t.readBytes, uint32(length))
return length, perrors.WithStack(err)
//return length, err
// return length, err
}
// tcp connection write
......@@ -330,7 +324,6 @@ func (t *gettyTCPConn) close(waitSec int) {
_ = conn.Close()
} else {
_ = t.conn.(*tls.Conn).Close()
}
t.conn = nil
}
......@@ -422,7 +415,7 @@ func (u *gettyUDPConn) recv(p []byte) (int, *net.UDPAddr, error) {
atomic.AddUint32(&u.readBytes, uint32(length))
}
//return length, addr, err
// return length, addr, err
return length, addr, perrors.WithStack(err)
}
......@@ -568,7 +561,7 @@ func (w *gettyWSConn) recv() ([]byte, error) {
}
return b, perrors.WithStack(e)
//return b, e
// return b, e
}
func (w *gettyWSConn) updateWriteDeadline() error {
......
......@@ -21,8 +21,10 @@ import (
"strconv"
)
type EndPointID = int32
type EndPointType int32
type (
EndPointID = int32
EndPointType int32
)
const (
UDP_ENDPOINT EndPointType = 0
......
......@@ -26,6 +26,4 @@ const (
WritePkgTimeout = 1e8
)
var (
log = getty.GetLogger()
)
var log = getty.GetLogger()
......@@ -21,9 +21,7 @@ import (
"github.com/apache/dubbo-getty"
)
var (
Sessions []getty.Session
)
var Sessions []getty.Session
func ClientRequest() {
for _, session := range Sessions {
......@@ -40,5 +38,4 @@ func ClientRequest() {
log.Infof("after loop %d times", echoTimes)
}()
}
}
......@@ -41,9 +41,7 @@ var (
pprofPort = flag.Int("pprof_port", 65431, "pprof http port")
)
var (
taskPool gxsync.GenericTaskPool
)
var taskPool gxsync.GenericTaskPool
func main() {
flag.Parse()
......
......@@ -38,7 +38,7 @@ var (
)
func InitialSession(session getty.Session) (err error) {
//session.SetCompressType(getty.CompressZip)
// session.SetCompressType(getty.CompressZip)
tcpConn, ok := session.Conn().(*net.TCPConn)
if !ok {
......
......@@ -37,9 +37,7 @@ var (
pprofPort = flag.Int("pprof_port", 65432, "pprof http port")
)
var (
taskPool gxsync.GenericTaskPool
)
var taskPool gxsync.GenericTaskPool
func main() {
flag.Parse()
......
......@@ -42,9 +42,7 @@ var (
pprofPort = flag.Int("pprof_port", 65431, "pprof http port")
)
var (
taskPool gxsync.GenericTaskPool
)
var taskPool gxsync.GenericTaskPool
func main() {
flag.Parse()
......
......@@ -38,7 +38,7 @@ var (
// InitialSession init session
func InitialSession(session getty.Session) (err error) {
//session.SetCompressType(getty.CompressZip)
// session.SetCompressType(getty.CompressZip)
_, ok := session.Conn().(*tls.Conn)
if ok {
session.SetName("hello")
......
......@@ -19,8 +19,9 @@ package main
import (
"flag"
tls "github.com/apache/dubbo-getty/demo/hello/tls"
"path/filepath"
tls "github.com/apache/dubbo-getty/demo/hello/tls"
)
import (
......@@ -39,9 +40,7 @@ var (
Sessions []getty.Session
)
var (
taskPool gxsync.GenericTaskPool
)
var taskPool gxsync.GenericTaskPool
func main() {
flag.Parse()
......@@ -62,7 +61,8 @@ func main() {
if *taskPoolMode {
taskPool = gxsync.NewTaskPoolSimple(*taskPoolSize)
}
options := []getty.ServerOption{getty.WithLocalAddress(":8090"),
options := []getty.ServerOption{
getty.WithLocalAddress(":8090"),
getty.WithServerSslEnabled(true),
getty.WithServerTlsConfigBuilder(c),
getty.WithServerTaskPool(taskPool),
......
......@@ -27,7 +27,7 @@ type ServerOption func(*ServerOptions)
type ServerOptions struct {
addr string
//tls
// tls
sslEnabled bool
tlsConfigBuilder TlsConfigBuilder
// websocket
......@@ -106,7 +106,7 @@ type ClientOptions struct {
number int
reconnectInterval int // reConnect Interval
//tls
// tls
sslEnabled bool
tlsConfigBuilder TlsConfigBuilder
......
......@@ -59,9 +59,7 @@ func testTCPServer(t *testing.T, address string) {
assert.True(t, clt.ID() > 0)
assert.Equal(t, clt.endPointType, TCP_CLIENT)
var (
msgHandler MessageHandler
)
var msgHandler MessageHandler
cb := func(session Session) error {
return newSessionCallback(session, &msgHandler)
}
......@@ -129,9 +127,7 @@ func testTCPTlsServer(t *testing.T, address string) {
assert.True(t, clt.ID() > 0)
assert.Equal(t, clt.endPointType, TCP_CLIENT)
var (
msgHandler MessageHandler
)
var msgHandler MessageHandler
cb := func(session Session) error {
return newSessionCallback(session, &msgHandler)
}
......
......@@ -58,9 +58,7 @@ const (
// session
/////////////////////////////////////////
var (
wheel *gxtime.Wheel
)
var wheel *gxtime.Wheel
func init() {
span := 100e6 // 100ms
......@@ -544,9 +542,7 @@ func (s *session) addTask(pkg interface{}) {
}
func (s *session) handlePackage() {
var (
err error
)
var err error
defer func() {
if r := recover(); r != nil {
......@@ -826,9 +822,7 @@ func (s *session) stop() {
}
func (s *session) gc() {
var (
conn Connection
)
var conn Connection
s.lock.Lock()
if s.attrs != nil {
......
......@@ -23,6 +23,7 @@ import (
"fmt"
"io/ioutil"
)
import (
perrors "github.com/pkg/errors"
)
......@@ -88,7 +89,6 @@ type ClientTlsConfigBuilder struct {
// BuildTlsConfig impl TlsConfigBuilder method
func (c *ClientTlsConfigBuilder) BuildTlsConfig() (*tls.Config, error) {
cert, err := tls.LoadX509KeyPair(c.ClientTrustCertCollectionPath, c.ClientPrivateKeyPath)
if err != nil {
log.Error(fmt.Sprintf("Unable to load X509 Key Pair %v", err))
......
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