Skip to content

Commit

Permalink
chore: release v0.5.2 (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
welkeyever authored Feb 2, 2023
2 parents e3dfeba + 12f5756 commit 949f5bf
Show file tree
Hide file tree
Showing 29 changed files with 677 additions and 243 deletions.
22 changes: 7 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Lint
run: |
go vet -stdmethods=false $(go list ./...)
go install mvdan.cc/[email protected]
test -z "$(gofumpt -l -extra .)"
- name: Golangci Lint
# https://golangci-lint.run/
uses: golangci/golangci-lint-action@v3
with:
version: latest
- name: Unit Test
run: go test -race -covermode=atomic -coverprofile=coverage.txt ./...

- name: Codecov
run: bash <(curl -s https://codecov.io/bash)

lint-and-ut-windows:
ut-windows:
strategy:
matrix:
version: [ 1.18, 1.19 ]
Expand All @@ -52,13 +52,5 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Lint
run: |
go vet -stdmethods=false $(go list ./...)
go install mvdan.cc/[email protected]
test -z "$(gofumpt -l -extra .)"
- name: Unit Test
run: go test -race -covermode=atomic -coverprofile=coverage.txt ./...
#
# - name: Codecov
# run: bash <(curl -s https://codecov.io/bash)
run: go test -race -covermode=atomic ./...
35 changes: 35 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Options for analysis running.
run:
# include `vendor` `third_party` `testdata` `examples` `Godeps` `builtin`
skip-dirs-use-default: true
# output configuration options

# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 30m

output:
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
format: colored-line-number
# All available settings of specific linters.
# Refer to https://golangci-lint.run/usage/linters
linters-settings:
govet:
# Disable analyzers by name.
# Run `go tool vet help` to see all analyzers.
disable:
- stdmethods
linters:
enable:
- gofumpt
- goimports
- gofmt
- govet
disable:
- errcheck
- typecheck
- deadcode
- varcheck
- staticcheck
issues:
exclude-use-default: true
3 changes: 2 additions & 1 deletion cmd/hz/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func Init() *cli.App {
verboseFlag := cli.BoolFlag{Name: "verbose,vv", Usage: "turn on verbose mode", Destination: &globalArgs.Verbose}

idlFlag := cli.StringSliceFlag{Name: "idl", Usage: "Specify the IDL file path. (.thrift or .proto)"}
moduleFlag := cli.StringFlag{Name: "module", Aliases: []string{"mod"}, Usage: "Specify the Go module name to generate go.mod.", Destination: &globalArgs.Gomod}
moduleFlag := cli.StringFlag{Name: "module", Aliases: []string{"mod"}, Usage: "Specify the Go module name.", Destination: &globalArgs.Gomod}
serviceNameFlag := cli.StringFlag{Name: "service", Usage: "Specify the service name.", Destination: &globalArgs.ServiceName}
outDirFlag := cli.StringFlag{Name: "out_dir", Usage: "Specify the project path.", Destination: &globalArgs.OutDir}
handlerDirFlag := cli.StringFlag{Name: "handler_dir", Usage: "Specify the handler path.", Destination: &globalArgs.HandlerDir}
Expand Down Expand Up @@ -212,6 +212,7 @@ func Init() *cli.App {
Usage: "Update an existing Hertz project",
Flags: []cli.Flag{
&idlFlag,
&moduleFlag,
&outDirFlag,
&handlerDirFlag,
&modelDirFlag,
Expand Down
2 changes: 1 addition & 1 deletion cmd/hz/meta/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package meta
import "runtime"

// Version hz version
const Version = "v0.5.1"
const Version = "v0.5.2"

// Mode hz run modes
type Mode int
Expand Down
3 changes: 2 additions & 1 deletion cmd/hz/protobuf/api/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions licenses/LICENSE-fsnotify
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright © 2012 The Go Authors. All rights reserved.
Copyright © fsnotify Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of Google Inc. nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 changes: 15 additions & 22 deletions pkg/app/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import (
"errors"
"fmt"
"io"
"math/rand"
"net"
"net/http"
"net/http/httptest"
Expand All @@ -70,7 +69,6 @@ import (
"github.com/cloudwego/hertz/pkg/common/test/assert"
"github.com/cloudwego/hertz/pkg/network"
"github.com/cloudwego/hertz/pkg/network/dialer"
"github.com/cloudwego/hertz/pkg/network/netpoll"
"github.com/cloudwego/hertz/pkg/network/standard"
"github.com/cloudwego/hertz/pkg/protocol"
"github.com/cloudwego/hertz/pkg/protocol/consts"
Expand Down Expand Up @@ -1897,24 +1895,13 @@ func (m *mockDialer) DialConnection(network, address string, timeout time.Durati
return m.Dialer.DialConnection(m.network, m.address, m.timeout, tlsConfig)
}

func newMockDialerWithCustomFunc(network, address string, timeout time.Duration, f func(network, address string, timeout time.Duration, tlsConfig *tls.Config)) network.Dialer {
dialer := standard.NewDialer()
if rand.Intn(2) == 0 {
dialer = netpoll.NewDialer()
}
return &mockDialer{
Dialer: dialer,
customDialerFunc: f,
network: network,
address: address,
timeout: timeout,
}
}

func TestClientRetry(t *testing.T) {
t.Parallel()
client, err := NewClient(
WithDialTimeout(2*time.Second),
// Default dial function performs different in different os. So unit the performance of dial function.
WithDialFunc(func(addr string) (network.Conn, error) {
return nil, fmt.Errorf("dial tcp %s: i/o timeout", addr)
}),
WithRetryConfig(
retry.WithMaxAttemptTimes(3),
retry.WithInitDelay(100*time.Millisecond),
Expand Down Expand Up @@ -1943,7 +1930,9 @@ func TestClientRetry(t *testing.T) {
}

client2, err := NewClient(
WithDialTimeout(2*time.Second),
WithDialFunc(func(addr string) (network.Conn, error) {
return nil, fmt.Errorf("dial tcp %s: i/o timeout", addr)
}),
WithRetryConfig(
retry.WithMaxAttemptTimes(2),
retry.WithInitDelay(500*time.Millisecond),
Expand Down Expand Up @@ -1972,7 +1961,9 @@ func TestClientRetry(t *testing.T) {
}

client3, err := NewClient(
WithDialTimeout(2*time.Second),
WithDialFunc(func(addr string) (network.Conn, error) {
return nil, fmt.Errorf("dial tcp %s: i/o timeout", addr)
}),
WithRetryConfig(
retry.WithMaxAttemptTimes(2),
retry.WithInitDelay(100*time.Millisecond),
Expand Down Expand Up @@ -2002,7 +1993,9 @@ func TestClientRetry(t *testing.T) {
}

client4, err := NewClient(
WithDialTimeout(2*time.Second),
WithDialFunc(func(addr string) (network.Conn, error) {
return nil, fmt.Errorf("dial tcp %s: i/o timeout", addr)
}),
WithRetryConfig(
retry.WithMaxAttemptTimes(2),
retry.WithInitDelay(1*time.Second),
Expand Down Expand Up @@ -2045,12 +2038,12 @@ func TestClientDialerName(t *testing.T) {
t.Errorf("expected 'netpoll', but get %s", dName)
}

client, _ = NewClient(WithDialer(netpoll.NewDialer()))
client, _ = NewClient(WithDialer(&mockDialer{}))
dName, err = client.GetDialerName()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if dName != "netpoll" {
if dName != "client" {
t.Errorf("expected 'standard', but get %s", dName)
}

Expand Down
43 changes: 43 additions & 0 deletions pkg/app/client/client_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 CloudWeGo Authors
//
// Licensed 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.
//

//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris

package client

import (
"crypto/tls"
"math/rand"
"time"

"github.com/cloudwego/hertz/pkg/network"
"github.com/cloudwego/hertz/pkg/network/netpoll"
"github.com/cloudwego/hertz/pkg/network/standard"
)

func newMockDialerWithCustomFunc(network, address string, timeout time.Duration, f func(network, address string, timeout time.Duration, tlsConfig *tls.Config)) network.Dialer {
dialer := standard.NewDialer()
if rand.Intn(2) == 0 {
dialer = netpoll.NewDialer()
}
return &mockDialer{
Dialer: dialer,
customDialerFunc: f,
network: network,
address: address,
timeout: timeout,
}
}
38 changes: 38 additions & 0 deletions pkg/app/client/client_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2023 CloudWeGo Authors
//
// Licensed 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.
//

//go:build windows
// +build windows

package client

import (
"crypto/tls"
"time"

"github.com/cloudwego/hertz/pkg/network"
"github.com/cloudwego/hertz/pkg/network/standard"
)

func newMockDialerWithCustomFunc(network, address string, timeout time.Duration, f func(network, address string, timeout time.Duration, tlsConfig *tls.Config)) network.Dialer {
dialer := standard.NewDialer()
return &mockDialer{
Dialer: dialer,
customDialerFunc: f,
network: network,
address: address,
timeout: timeout,
}
}
3 changes: 1 addition & 2 deletions pkg/app/client/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ type customDialer struct {
dialFunc network.DialFunc
}

func (m *customDialer) DialConnection(network, address string, timeout time.Duration,
tlsConfig *tls.Config) (conn network.Conn, err error) {
func (m *customDialer) DialConnection(network, address string, timeout time.Duration, tlsConfig *tls.Config) (conn network.Conn, err error) {
if m.dialFunc != nil {
return m.dialFunc(address)
}
Expand Down
Loading

0 comments on commit 949f5bf

Please sign in to comment.