Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
getty
Commits
020cac6d
Commit
020cac6d
authored
Dec 13, 2020
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add: go lint
parent
614f0c73
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
54 additions
and
28 deletions
+54
-28
github-actions.yml
.github/workflows/github-actions.yml
+11
-5
client.go
client.go
+6
-6
client_test.go
client_test.go
+2
-0
hello.go
demo/hello/hello.go
+4
-3
limit_darwin.go
demo/util/limit_darwin.go
+0
-0
limit_windows.go
demo/util/limit_windows.go
+21
-0
signals.go
demo/util/signals.go
+1
-1
server.go
server.go
+6
-11
session.go
session.go
+3
-2
No files found.
.github/workflows/github-actions.yml
View file @
020cac6d
...
@@ -24,7 +24,7 @@ jobs:
...
@@ -24,7 +24,7 @@ jobs:
# DING_SIGN: SECbcc50d56d7315e57da8469d05da306d6cd825348a781861a42084e9579f1aebb
# DING_SIGN: SECbcc50d56d7315e57da8469d05da306d6cd825348a781861a42084e9579f1aebb
DING_TOKEN
:
${{ secrets.DING_TOKEN }}
DING_TOKEN
:
${{ secrets.DING_TOKEN }}
DING_SIGN
:
${{ secrets.DING_SIGN }}
DING_SIGN
:
${{ secrets.DING_SIGN }}
steps
:
steps
:
-
name
:
Set up Go ${{ matrix.go_version }}
-
name
:
Set up Go ${{ matrix.go_version }}
...
@@ -59,6 +59,12 @@ jobs:
...
@@ -59,6 +59,12 @@ jobs:
go fmt ./... && [[ -z `git status -s` ]]
go fmt ./... && [[ -z `git status -s` ]]
/tmp/tools/license/license-header-checker -v -a -r -i vendor /tmp/tools/license/license.txt . go && [[ -z `git status -s` ]]
/tmp/tools/license/license-header-checker -v -a -r -i vendor /tmp/tools/license/license.txt . go && [[ -z `git status -s` ]]
-
name
:
Install go ci lint
run
:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0
-
name
:
Run Linter
run
:
golangci-lint run --timeout=10m -v --disable-all --enable=govet --enable=staticcheck --enable=ineffassign --enable=misspell
-
name
:
Test
-
name
:
Test
run
:
go mod vendor && go test $(go list ./... | grep -v vendor | grep -v demo) -coverprofile=coverage.txt -covermode=atomic
run
:
go mod vendor && go test $(go list ./... | grep -v vendor | grep -v demo) -coverprofile=coverage.txt -covermode=atomic
...
@@ -71,7 +77,7 @@ jobs:
...
@@ -71,7 +77,7 @@ jobs:
uses
:
zcong1993/actions-ding@v3.0.1
uses
:
zcong1993/actions-ding@v3.0.1
# Whether job is successful or not, always () is always true.
# Whether job is successful or not, always () is always true.
if
:
|
if
:
|
always() &&
always() &&
github.event_name == 'push' &&
github.event_name == 'push' &&
github.repository == 'apache/dubbo-getty'
github.repository == 'apache/dubbo-getty'
with
:
with
:
...
@@ -87,11 +93,11 @@ jobs:
...
@@ -87,11 +93,11 @@ jobs:
"text": "## Github Actions \n - name: CI \n - repository: ${{ github.repository }} \n - trigger: ${{ github.actor }} \n - event: ${{ github.event_name }} \n - ref: ${{ github.ref }} \n - status: [${{ job.status }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) \n - environment: ${{ runner.os }} \n - SHA: [${{ github.sha }}](${{ github.event.compare }})"
"text": "## Github Actions \n - name: CI \n - repository: ${{ github.repository }} \n - trigger: ${{ github.actor }} \n - event: ${{ github.event_name }} \n - ref: ${{ github.ref }} \n - status: [${{ job.status }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) \n - environment: ${{ runner.os }} \n - SHA: [${{ github.sha }}](${{ github.event.compare }})"
}
}
}
}
-
name
:
DingTalk Message Notify only PR
-
name
:
DingTalk Message Notify only PR
uses
:
zcong1993/actions-ding@v3.0.1
uses
:
zcong1993/actions-ding@v3.0.1
if
:
|
if
:
|
always() &&
always() &&
github.event_name == 'pull_request' &&
github.event_name == 'pull_request' &&
github.repository == 'apache/dubbo-getty'
github.repository == 'apache/dubbo-getty'
with
:
with
:
...
...
client.go
View file @
020cac6d
...
@@ -126,7 +126,7 @@ func NewWSSClient(opts ...ClientOption) Client {
...
@@ -126,7 +126,7 @@ func NewWSSClient(opts ...ClientOption) Client {
c
:=
newClient
(
WSS_CLIENT
,
opts
...
)
c
:=
newClient
(
WSS_CLIENT
,
opts
...
)
if
c
.
cert
==
""
{
if
c
.
cert
==
""
{
panic
(
fmt
.
Sprintf
(
"@cert
s
:%s"
,
c
.
cert
))
panic
(
fmt
.
Sprintf
(
"@cert:%s"
,
c
.
cert
))
}
}
if
!
strings
.
HasPrefix
(
c
.
addr
,
"wss://"
)
{
if
!
strings
.
HasPrefix
(
c
.
addr
,
"wss://"
)
{
panic
(
fmt
.
Sprintf
(
"the prefix @serverAddr:%s is not wss://"
,
c
.
addr
))
panic
(
fmt
.
Sprintf
(
"the prefix @serverAddr:%s is not wss://"
,
c
.
addr
))
...
@@ -135,11 +135,11 @@ func NewWSSClient(opts ...ClientOption) Client {
...
@@ -135,11 +135,11 @@ func NewWSSClient(opts ...ClientOption) Client {
return
c
return
c
}
}
func
(
c
client
)
ID
()
EndPointID
{
func
(
c
*
client
)
ID
()
EndPointID
{
return
c
.
endPointID
return
c
.
endPointID
}
}
func
(
c
client
)
EndPointType
()
EndPointType
{
func
(
c
*
client
)
EndPointType
()
EndPointType
{
return
c
.
endPointType
return
c
.
endPointType
}
}
...
@@ -154,7 +154,7 @@ func (c *client) dialTCP() Session {
...
@@ -154,7 +154,7 @@ func (c *client) dialTCP() Session {
return
nil
return
nil
}
}
if
c
.
sslEnabled
{
if
c
.
sslEnabled
{
if
sslConfig
,
err
:=
c
.
tlsConfigBuilder
.
BuildTlsConfig
();
e
rr
==
nil
&&
sslConfig
!=
nil
{
if
sslConfig
,
buildTlsConfErr
:=
c
.
tlsConfigBuilder
.
BuildTlsConfig
();
buildTlsConfE
rr
==
nil
&&
sslConfig
!=
nil
{
d
:=
&
net
.
Dialer
{
Timeout
:
connectTimeout
}
d
:=
&
net
.
Dialer
{
Timeout
:
connectTimeout
}
conn
,
err
=
tls
.
DialWithDialer
(
d
,
"tcp"
,
c
.
addr
,
sslConfig
)
conn
,
err
=
tls
.
DialWithDialer
(
d
,
"tcp"
,
c
.
addr
,
sslConfig
)
}
}
...
@@ -285,7 +285,7 @@ func (c *client) dialWSS() Session {
...
@@ -285,7 +285,7 @@ func (c *client) dialWSS() Session {
if
c
.
cert
!=
""
{
if
c
.
cert
!=
""
{
certPEMBlock
,
err
:=
ioutil
.
ReadFile
(
c
.
cert
)
certPEMBlock
,
err
:=
ioutil
.
ReadFile
(
c
.
cert
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"ioutil.ReadFile(cert
s
:%s) = error:%+v"
,
c
.
cert
,
perrors
.
WithStack
(
err
)))
panic
(
fmt
.
Sprintf
(
"ioutil.ReadFile(cert:%s) = error:%+v"
,
c
.
cert
,
perrors
.
WithStack
(
err
)))
}
}
var
cert
tls
.
Certificate
var
cert
tls
.
Certificate
...
@@ -307,7 +307,7 @@ func (c *client) dialWSS() Session {
...
@@ -307,7 +307,7 @@ func (c *client) dialWSS() Session {
for
_
,
c
:=
range
config
.
Certificates
{
for
_
,
c
:=
range
config
.
Certificates
{
roots
,
err
=
x509
.
ParseCertificates
(
c
.
Certificate
[
len
(
c
.
Certificate
)
-
1
])
roots
,
err
=
x509
.
ParseCertificates
(
c
.
Certificate
[
len
(
c
.
Certificate
)
-
1
])
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"error parsing server's root cert
s
: %+v
\n
"
,
perrors
.
WithStack
(
err
)))
panic
(
fmt
.
Sprintf
(
"error parsing server's root cert: %+v
\n
"
,
perrors
.
WithStack
(
err
)))
}
}
for
_
,
root
=
range
roots
{
for
_
,
root
=
range
roots
{
certPool
.
AddCert
(
root
)
certPool
.
AddCert
(
root
)
...
...
client_test.go
View file @
020cac6d
...
@@ -293,8 +293,10 @@ func TestNewWSClient(t *testing.T) {
...
@@ -293,8 +293,10 @@ func TestNewWSClient(t *testing.T) {
assert
.
Equal
(
t
,
beforeWriteBytes
+
5
,
atomic
.
LoadUint32
(
&
conn
.
writeBytes
))
assert
.
Equal
(
t
,
beforeWriteBytes
+
5
,
atomic
.
LoadUint32
(
&
conn
.
writeBytes
))
beforeWritePkgNum
:=
atomic
.
LoadUint32
(
&
conn
.
writePkgNum
)
beforeWritePkgNum
:=
atomic
.
LoadUint32
(
&
conn
.
writePkgNum
)
err
=
ss
.
WriteBytes
([]
byte
(
"hello"
))
err
=
ss
.
WriteBytes
([]
byte
(
"hello"
))
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
beforeWritePkgNum
+
1
,
atomic
.
LoadUint32
(
&
conn
.
writePkgNum
))
assert
.
Equal
(
t
,
beforeWritePkgNum
+
1
,
atomic
.
LoadUint32
(
&
conn
.
writePkgNum
))
err
=
ss
.
WriteBytesArray
([]
byte
(
"hello"
),
[]
byte
(
"hello"
))
err
=
ss
.
WriteBytesArray
([]
byte
(
"hello"
),
[]
byte
(
"hello"
))
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
beforeWritePkgNum
+
3
,
atomic
.
LoadUint32
(
&
conn
.
writePkgNum
))
assert
.
Equal
(
t
,
beforeWritePkgNum
+
3
,
atomic
.
LoadUint32
(
&
conn
.
writePkgNum
))
err
=
conn
.
writePing
()
err
=
conn
.
writePing
()
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
...
...
demo/hello/hello.go
View file @
020cac6d
...
@@ -27,13 +27,14 @@ var (
...
@@ -27,13 +27,14 @@ var (
func
ClientRequest
()
{
func
ClientRequest
()
{
for
_
,
session
:=
range
Sessions
{
for
_
,
session
:=
range
Sessions
{
ss
:=
session
go
func
()
{
go
func
()
{
echoTimes
:=
10
echoTimes
:=
10
for
i
:=
0
;
i
<
echoTimes
;
i
++
{
for
i
:=
0
;
i
<
echoTimes
;
i
++
{
err
:=
s
ession
.
WritePkg
(
"hello"
,
WritePkgTimeout
)
err
:=
s
s
.
WritePkg
(
"hello"
,
WritePkgTimeout
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Infof
(
"session.WritePkg(session{%s}, error{%v}"
,
s
ession
.
Stat
(),
err
)
log
.
Infof
(
"session.WritePkg(session{%s}, error{%v}"
,
s
s
.
Stat
(),
err
)
s
ession
.
Close
()
s
s
.
Close
()
}
}
}
}
log
.
Infof
(
"after loop %d times"
,
echoTimes
)
log
.
Infof
(
"after loop %d times"
,
echoTimes
)
...
...
demo/util/limit_
other
.go
→
demo/util/limit_
darwin
.go
View file @
020cac6d
File moved
demo/util/limit_windows.go
0 → 100644
View file @
020cac6d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
util
func
SetLimit
()
{
}
demo/util/signals.go
View file @
020cac6d
...
@@ -29,7 +29,7 @@ type Closer interface {
...
@@ -29,7 +29,7 @@ type Closer interface {
func
WaitCloseSignals
(
closer
Closer
)
{
func
WaitCloseSignals
(
closer
Closer
)
{
signals
:=
make
(
chan
os
.
Signal
,
1
)
signals
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
signals
,
os
.
Interrupt
,
os
.
Kill
,
syscall
.
SIGQUIT
,
syscall
.
SIGTERM
,
syscall
.
SIGINT
)
signal
.
Notify
(
signals
,
os
.
Interrupt
,
syscall
.
SIGQUIT
,
syscall
.
SIGTERM
,
syscall
.
SIGINT
)
<-
signals
<-
signals
closer
.
Close
()
closer
.
Close
()
}
}
server.go
View file @
020cac6d
...
@@ -106,20 +106,15 @@ func NewWSSServer(opts ...ServerOption) Server {
...
@@ -106,20 +106,15 @@ func NewWSSServer(opts ...ServerOption) Server {
return
s
return
s
}
}
func
(
s
server
)
ID
()
int32
{
func
(
s
*
server
)
ID
()
int32
{
return
s
.
endPointID
return
s
.
endPointID
}
}
func
(
s
server
)
EndPointType
()
EndPointType
{
func
(
s
*
server
)
EndPointType
()
EndPointType
{
return
s
.
endPointType
return
s
.
endPointType
}
}
func
(
s
*
server
)
stop
()
{
func
(
s
*
server
)
stop
()
{
var
(
err
error
ctx
context
.
Context
)
select
{
select
{
case
<-
s
.
done
:
case
<-
s
.
done
:
return
return
...
@@ -128,12 +123,13 @@ func (s *server) stop() {
...
@@ -128,12 +123,13 @@ func (s *server) stop() {
close
(
s
.
done
)
close
(
s
.
done
)
s
.
lock
.
Lock
()
s
.
lock
.
Lock
()
if
s
.
server
!=
nil
{
if
s
.
server
!=
nil
{
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
serverFastFailTimeout
)
ctx
,
cancel
:
=
context
.
WithTimeout
(
context
.
Background
(),
serverFastFailTimeout
)
if
err
=
s
.
server
.
Shutdown
(
ctx
);
err
!=
nil
{
if
err
:
=
s
.
server
.
Shutdown
(
ctx
);
err
!=
nil
{
// if the log output is "shutdown ctx: context deadline exceeded", it means that
// if the log output is "shutdown ctx: context deadline exceeded", it means that
// there are still some active connections.
// there are still some active connections.
log
.
Errorf
(
"server shutdown ctx:%s error:%v"
,
ctx
,
err
)
log
.
Errorf
(
"server shutdown ctx:%s error:%v"
,
ctx
,
err
)
}
}
cancel
()
}
}
s
.
server
=
nil
s
.
server
=
nil
s
.
lock
.
Unlock
()
s
.
lock
.
Unlock
()
...
@@ -179,7 +175,7 @@ func (s *server) listenTCP() error {
...
@@ -179,7 +175,7 @@ func (s *server) listenTCP() error {
}
}
}
else
{
}
else
{
if
s
.
sslEnabled
{
if
s
.
sslEnabled
{
if
sslConfig
,
err
:=
s
.
tlsConfigBuilder
.
BuildTlsConfig
();
e
rr
==
nil
&&
sslConfig
!=
nil
{
if
sslConfig
,
buildTlsConfErr
:=
s
.
tlsConfigBuilder
.
BuildTlsConfig
();
buildTlsConfE
rr
==
nil
&&
sslConfig
!=
nil
{
streamListener
,
err
=
tls
.
Listen
(
"tcp"
,
s
.
addr
,
sslConfig
)
streamListener
,
err
=
tls
.
Listen
(
"tcp"
,
s
.
addr
,
sslConfig
)
}
}
}
else
{
}
else
{
...
@@ -420,7 +416,6 @@ func (s *server) runWSSEventLoop(newSession NewSessionCallback) {
...
@@ -420,7 +416,6 @@ func (s *server) runWSSEventLoop(newSession NewSessionCallback) {
if
certificate
,
err
=
tls
.
LoadX509KeyPair
(
s
.
cert
,
s
.
privateKey
);
err
!=
nil
{
if
certificate
,
err
=
tls
.
LoadX509KeyPair
(
s
.
cert
,
s
.
privateKey
);
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"tls.LoadX509KeyPair(certs{%s}, privateKey{%s}) = err:%+v"
,
panic
(
fmt
.
Sprintf
(
"tls.LoadX509KeyPair(certs{%s}, privateKey{%s}) = err:%+v"
,
s
.
cert
,
s
.
privateKey
,
perrors
.
WithStack
(
err
)))
s
.
cert
,
s
.
privateKey
,
perrors
.
WithStack
(
err
)))
return
}
}
config
=
&
tls
.
Config
{
config
=
&
tls
.
Config
{
InsecureSkipVerify
:
true
,
// do not verify peer certs
InsecureSkipVerify
:
true
,
// do not verify peer certs
...
...
session.go
View file @
020cac6d
...
@@ -19,6 +19,7 @@ package getty
...
@@ -19,6 +19,7 @@ package getty
import
(
import
(
"bytes"
"bytes"
"context"
"fmt"
"fmt"
"io"
"io"
"net"
"net"
...
@@ -120,7 +121,7 @@ func newSession(endPoint EndPoint, conn Connection) *session {
...
@@ -120,7 +121,7 @@ func newSession(endPoint EndPoint, conn Connection) *session {
once
:
&
sync
.
Once
{},
once
:
&
sync
.
Once
{},
done
:
make
(
chan
struct
{}),
done
:
make
(
chan
struct
{}),
wait
:
pendingDuration
,
wait
:
pendingDuration
,
attrs
:
gxcontext
.
NewValuesContext
(
nil
),
attrs
:
gxcontext
.
NewValuesContext
(
context
.
Background
()
),
rDone
:
make
(
chan
struct
{}),
rDone
:
make
(
chan
struct
{}),
}
}
...
@@ -162,7 +163,7 @@ func (s *session) Reset() {
...
@@ -162,7 +163,7 @@ func (s *session) Reset() {
done
:
make
(
chan
struct
{}),
done
:
make
(
chan
struct
{}),
period
:
period
,
period
:
period
,
wait
:
pendingDuration
,
wait
:
pendingDuration
,
attrs
:
gxcontext
.
NewValuesContext
(
nil
),
attrs
:
gxcontext
.
NewValuesContext
(
context
.
Background
()
),
rDone
:
make
(
chan
struct
{}),
rDone
:
make
(
chan
struct
{}),
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment