Commit 020cac6d authored by AlexStocks's avatar AlexStocks

Add: go lint

parent 614f0c73
......@@ -24,7 +24,7 @@ jobs:
# DING_SIGN: SECbcc50d56d7315e57da8469d05da306d6cd825348a781861a42084e9579f1aebb
DING_TOKEN: ${{ secrets.DING_TOKEN }}
DING_SIGN: ${{ secrets.DING_SIGN }}
steps:
- name: Set up Go ${{ matrix.go_version }}
......@@ -59,6 +59,12 @@ jobs:
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` ]]
- 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
run: go mod vendor && go test $(go list ./... | grep -v vendor | grep -v demo) -coverprofile=coverage.txt -covermode=atomic
......@@ -71,7 +77,7 @@ jobs:
uses: zcong1993/actions-ding@v3.0.1
# Whether job is successful or not, always () is always true.
if: |
always() &&
always() &&
github.event_name == 'push' &&
github.repository == 'apache/dubbo-getty'
with:
......@@ -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 }})"
}
}
- name: DingTalk Message Notify only PR
uses: zcong1993/actions-ding@v3.0.1
if: |
always() &&
if: |
always() &&
github.event_name == 'pull_request' &&
github.repository == 'apache/dubbo-getty'
with:
......
......@@ -126,7 +126,7 @@ func NewWSSClient(opts ...ClientOption) Client {
c := newClient(WSS_CLIENT, opts...)
if c.cert == "" {
panic(fmt.Sprintf("@certs:%s", c.cert))
panic(fmt.Sprintf("@cert:%s", c.cert))
}
if !strings.HasPrefix(c.addr, "wss://") {
panic(fmt.Sprintf("the prefix @serverAddr:%s is not wss://", c.addr))
......@@ -135,11 +135,11 @@ func NewWSSClient(opts ...ClientOption) Client {
return c
}
func (c client) ID() EndPointID {
func (c *client) ID() EndPointID {
return c.endPointID
}
func (c client) EndPointType() EndPointType {
func (c *client) EndPointType() EndPointType {
return c.endPointType
}
......@@ -154,7 +154,7 @@ func (c *client) dialTCP() Session {
return nil
}
if c.sslEnabled {
if sslConfig, err := c.tlsConfigBuilder.BuildTlsConfig(); err == nil && sslConfig != nil {
if sslConfig, buildTlsConfErr := c.tlsConfigBuilder.BuildTlsConfig(); buildTlsConfErr == nil && sslConfig != nil {
d := &net.Dialer{Timeout: connectTimeout}
conn, err = tls.DialWithDialer(d, "tcp", c.addr, sslConfig)
}
......@@ -285,7 +285,7 @@ func (c *client) dialWSS() Session {
if c.cert != "" {
certPEMBlock, err := ioutil.ReadFile(c.cert)
if err != nil {
panic(fmt.Sprintf("ioutil.ReadFile(certs:%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
......@@ -307,7 +307,7 @@ func (c *client) dialWSS() Session {
for _, c := range config.Certificates {
roots, err = x509.ParseCertificates(c.Certificate[len(c.Certificate)-1])
if err != nil {
panic(fmt.Sprintf("error parsing server's root certs: %+v\n", perrors.WithStack(err)))
panic(fmt.Sprintf("error parsing server's root cert: %+v\n", perrors.WithStack(err)))
}
for _, root = range roots {
certPool.AddCert(root)
......
......@@ -293,8 +293,10 @@ func TestNewWSClient(t *testing.T) {
assert.Equal(t, beforeWriteBytes+5, atomic.LoadUint32(&conn.writeBytes))
beforeWritePkgNum := atomic.LoadUint32(&conn.writePkgNum)
err = ss.WriteBytes([]byte("hello"))
assert.Nil(t, err)
assert.Equal(t, beforeWritePkgNum+1, atomic.LoadUint32(&conn.writePkgNum))
err = ss.WriteBytesArray([]byte("hello"), []byte("hello"))
assert.Nil(t, err)
assert.Equal(t, beforeWritePkgNum+3, atomic.LoadUint32(&conn.writePkgNum))
err = conn.writePing()
assert.Nil(t, err)
......
......@@ -27,13 +27,14 @@ var (
func ClientRequest() {
for _, session := range Sessions {
ss := session
go func() {
echoTimes := 10
for i := 0; i < echoTimes; i++ {
err := session.WritePkg("hello", WritePkgTimeout)
err := ss.WritePkg("hello", WritePkgTimeout)
if err != nil {
log.Infof("session.WritePkg(session{%s}, error{%v}", session.Stat(), err)
session.Close()
log.Infof("session.WritePkg(session{%s}, error{%v}", ss.Stat(), err)
ss.Close()
}
}
log.Infof("after loop %d times", echoTimes)
......
/*
* 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() {
}
......@@ -29,7 +29,7 @@ type Closer interface {
func WaitCloseSignals(closer Closer) {
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
closer.Close()
}
......@@ -106,20 +106,15 @@ func NewWSSServer(opts ...ServerOption) Server {
return s
}
func (s server) ID() int32 {
func (s *server) ID() int32 {
return s.endPointID
}
func (s server) EndPointType() EndPointType {
func (s *server) EndPointType() EndPointType {
return s.endPointType
}
func (s *server) stop() {
var (
err error
ctx context.Context
)
select {
case <-s.done:
return
......@@ -128,12 +123,13 @@ func (s *server) stop() {
close(s.done)
s.lock.Lock()
if s.server != nil {
ctx, _ = context.WithTimeout(context.Background(), serverFastFailTimeout)
if err = s.server.Shutdown(ctx); err != nil {
ctx, cancel := context.WithTimeout(context.Background(), serverFastFailTimeout)
if err := s.server.Shutdown(ctx); err != nil {
// if the log output is "shutdown ctx: context deadline exceeded", it means that
// there are still some active connections.
log.Errorf("server shutdown ctx:%s error:%v", ctx, err)
}
cancel()
}
s.server = nil
s.lock.Unlock()
......@@ -179,7 +175,7 @@ func (s *server) listenTCP() error {
}
} else {
if s.sslEnabled {
if sslConfig, err := s.tlsConfigBuilder.BuildTlsConfig(); err == nil && sslConfig != nil {
if sslConfig, buildTlsConfErr := s.tlsConfigBuilder.BuildTlsConfig(); buildTlsConfErr == nil && sslConfig != nil {
streamListener, err = tls.Listen("tcp", s.addr, sslConfig)
}
} else {
......@@ -420,7 +416,6 @@ func (s *server) runWSSEventLoop(newSession NewSessionCallback) {
if certificate, err = tls.LoadX509KeyPair(s.cert, s.privateKey); err != nil {
panic(fmt.Sprintf("tls.LoadX509KeyPair(certs{%s}, privateKey{%s}) = err:%+v",
s.cert, s.privateKey, perrors.WithStack(err)))
return
}
config = &tls.Config{
InsecureSkipVerify: true, // do not verify peer certs
......
......@@ -19,6 +19,7 @@ package getty
import (
"bytes"
"context"
"fmt"
"io"
"net"
......@@ -120,7 +121,7 @@ func newSession(endPoint EndPoint, conn Connection) *session {
once: &sync.Once{},
done: make(chan struct{}),
wait: pendingDuration,
attrs: gxcontext.NewValuesContext(nil),
attrs: gxcontext.NewValuesContext(context.Background()),
rDone: make(chan struct{}),
}
......@@ -162,7 +163,7 @@ func (s *session) Reset() {
done: make(chan struct{}),
period: period,
wait: pendingDuration,
attrs: gxcontext.NewValuesContext(nil),
attrs: gxcontext.NewValuesContext(context.Background()),
rDone: make(chan struct{}),
}
}
......
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