Skip to content

Commit

Permalink
Merge pull request #626 from cloudwego/hotfix/revert_go_16_api
Browse files Browse the repository at this point in the history
hotfix: revert golang 1.16 api for compatibility with lower go version
  • Loading branch information
YangruiEmma authored Aug 30, 2022
2 parents 995948d + 4eefa87 commit 5f0f79e
Show file tree
Hide file tree
Showing 35 changed files with 317 additions and 207 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
unit-benchmark-test:
strategy:
matrix:
go: [ 1.17, 1.18, 1.19 ]
go: [ 1.15, 1.17, 1.18, 1.19 ]
os: [ X64, ARM64 ]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -34,7 +34,7 @@ jobs:
scenario-test:
strategy:
matrix:
go: [ 1.17, 1.18 ]
go: [ 1.15, 1.18 ]
runs-on: [ self-hosted, X64 ]
steps:
- uses: actions/checkout@v3
Expand Down
7 changes: 5 additions & 2 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ header:
copyright-owner: CloudWeGo Authors

paths:
- '**/*.go'
- '**/*.s'
- "**/*.go"
- "**/*.s"

paths-ignore:
- internal/mocks/thrift/test.go
- pkg/remote/codec/thrift/thrift_frugal.go
- pkg/remote/codec/thrift/thrift_frugal_test.go
- pkg/remote/codec/thrift/thrift_others.go
- pkg/remote/trans/nphttp2/codes/codes.go
- pkg/remote/trans/nphttp2/grpc/grpcframe/
- pkg/remote/trans/nphttp2/grpc/bdp_estimator.go
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cloudwego/kitex

go 1.16
go 1.13

require (
github.com/apache/thrift v0.13.0
Expand All @@ -9,7 +9,7 @@ require (
github.com/cloudwego/fastpb v0.0.2
github.com/cloudwego/frugal v0.1.3
github.com/cloudwego/netpoll v0.2.6
github.com/cloudwego/thriftgo v0.2.0
github.com/cloudwego/thriftgo v0.2.1
github.com/golang/mock v1.6.0
github.com/jhump/protoreflect v1.8.2
github.com/json-iterator/go v1.1.12
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ github.com/cloudwego/netpoll v0.2.4/go.mod h1:1T2WVuQ+MQw6h6DpE45MohSvDTKdy2DlzC
github.com/cloudwego/netpoll v0.2.6 h1:vzN8cyayoa9RdCOG87tqkYO/j2hA4SMLC+vkcNUq6uI=
github.com/cloudwego/netpoll v0.2.6/go.mod h1:1T2WVuQ+MQw6h6DpE45MohSvDTKdy2DlzCx2KsnPI4E=
github.com/cloudwego/thriftgo v0.1.2/go.mod h1:LzeafuLSiHA9JTiWC8TIMIq64iadeObgRUhmVG1OC/w=
github.com/cloudwego/thriftgo v0.2.0 h1:gDNxU1CmNkwwe/I9UfuCTIc1DXu5FVFa2cMWwT61e50=
github.com/cloudwego/thriftgo v0.2.0/go.mod h1:aZxiVX7KJdonZwwnapZEMDAAGUGk9WCIkNU3YoVjbpg=
github.com/cloudwego/thriftgo v0.2.1 h1:pKEZDDND14+kG4ILPCq0sqv3gidjxOnf/wLjOwxzBks=
github.com/cloudwego/thriftgo v0.2.1/go.mod h1:8i9AF5uDdWHGqzUhXDlubCjx4MEfKvWXGQlMWyR0tM4=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
3 changes: 2 additions & 1 deletion pkg/generic/httppbthrift_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -168,7 +169,7 @@ func FromHTTPPbRequest(req *http.Request) (*HTTPRequest, error) {
// body == nil if from Get request
return customReq, nil
}
if customReq.RawBody, err = io.ReadAll(b); err != nil {
if customReq.RawBody, err = ioutil.ReadAll(b); err != nil {
return nil, err
}
if len(customReq.RawBody) == 0 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/generic/httpthrift_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"sync/atomic"

Expand Down Expand Up @@ -154,7 +155,7 @@ func FromHTTPRequest(req *http.Request) (*HTTPRequest, error) {
// body == nil if from Get request
return customReq, nil
}
if customReq.RawBody, err = io.ReadAll(b); err != nil {
if customReq.RawBody, err = ioutil.ReadAll(b); err != nil {
return nil, err
}
if len(customReq.RawBody) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/remote/codec/thrift/thrift.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (c thriftCodec) Unmarshal(ctx context.Context, message remote.Message, in r
data := message.Data()

// decode with hyper unmarshal
if c.hyperMarshalEnabled() && hyperMessageUnmarshalAvailable(data, message) {
if c.hyperMessageUnmarshalEnabled() && hyperMessageUnmarshalAvailable(data, message) {
msgBeginLen := bthrift.Binary.MessageBeginLength(methodName, msgType, seqID)
ri := message.RPCInfo()
internal_stats.Record(ctx, ri, stats.WaitReadStart, nil)
Expand Down
4 changes: 2 additions & 2 deletions pkg/remote/codec/thrift/thrift_frugal.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build amd64 && !windows
// +build amd64,!windows
//go:build amd64 && !windows && !go1.13 && !go.14
// +build amd64,!windows,!go1.13,!go.14

/*
* Copyright 2021 CloudWeGo Authors
Expand Down
4 changes: 2 additions & 2 deletions pkg/remote/codec/thrift/thrift_frugal_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build amd64 && !windows
// +build amd64,!windows
//go:build amd64 && !windows && !go1.13 && !go.14
// +build amd64,!windows,!go1.13,!go.14

// Copyright 2022 ByteDance Inc.
//
Expand Down
4 changes: 2 additions & 2 deletions pkg/remote/codec/thrift/thrift_others.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !amd64 || windows
// +build !amd64 windows
//go:build !amd64 || windows || go1.13 || go1.14
// +build !amd64 windows go1.13 go1.14

/*
* Copyright 2021 CloudWeGo Authors
Expand Down
9 changes: 6 additions & 3 deletions pkg/remote/trans/gonet/conn_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"io"
"net"
"strings"
"syscall"

"github.com/cloudwego/netpoll"
Expand Down Expand Up @@ -75,8 +76,10 @@ func (e *gonetConnExtension) IsRemoteClosedErr(err error) bool {
if err == nil {
return false
}
return errors.Is(err, net.ErrClosed) ||
errors.Is(err, netpoll.ErrConnClosed) ||
// strings.Contains(err.Error(), "closed network connection") change to errors.Is(err, net.ErrClosed)
// when support go version >= 1.16
return errors.Is(err, netpoll.ErrConnClosed) ||
errors.Is(err, io.EOF) ||
errors.Is(err, syscall.EPIPE)
errors.Is(err, syscall.EPIPE) ||
strings.Contains(err.Error(), "closed network connection")
}
4 changes: 2 additions & 2 deletions pkg/remote/trans/netpoll/http_client_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"context"
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"path"
Expand Down Expand Up @@ -279,7 +279,7 @@ func getBodyBufReader(buf remote.ByteBuffer) (remote.ByteBuffer, error) {
if hr.StatusCode != http.StatusOK {
return nil, fmt.Errorf("http response not OK, StatusCode: %d", hr.StatusCode)
}
b, err := io.ReadAll(hr.Body)
b, err := ioutil.ReadAll(hr.Body)
hr.Body.Close()
if err != nil {
return nil, fmt.Errorf("read http response body error:%w", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package utils

import (
"io"
"io/ioutil"
"os"
"time"

Expand Down Expand Up @@ -45,7 +45,7 @@ func ReadYamlConfigFile(yamlFile string) (*YamlConfig, error) {
}
defer fd.Close()

b, err := io.ReadAll(fd)
b, err := ioutil.ReadAll(fd)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions tool/internal_pkg/pluginmode/protoc/protoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package protoc
import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -44,7 +44,7 @@ func Run() int {

func run(opts protogen.Options) error {
// unmarshal request from stdin
in, err := io.ReadAll(os.Stdin)
in, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion tool/internal_pkg/pluginmode/thriftgo/convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"go/format"
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -467,7 +468,7 @@ func (c *converter) persist(res *plugin.Response) error {
if err := os.MkdirAll(path, 0o755); err != nil && !os.IsExist(err) {
return fmt.Errorf("failed to create path '%s': %w", path, err)
}
if err := os.WriteFile(full, content, 0o644); err != nil {
if err := ioutil.WriteFile(full, content, 0o644); err != nil {
return fmt.Errorf("failed to write file '%s': %w", full, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions tool/internal_pkg/pluginmode/thriftgo/patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package thriftgo

import (
"fmt"
"os"
"io/ioutil"
"path/filepath"
"reflect"
"sort"
Expand Down Expand Up @@ -205,7 +205,7 @@ func (p *patcher) patch(req *plugin.Request) (patches []*plugin.Generated, err e
})

if p.copyIDL {
content, err := os.ReadFile(ast.Filename)
content, err := ioutil.ReadFile(ast.Filename)
if err != nil {
return nil, fmt.Errorf("read %q: %w", ast.Filename, err)
}
Expand Down
4 changes: 2 additions & 2 deletions tool/internal_pkg/pluginmode/thriftgo/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package thriftgo
import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/cloudwego/thriftgo/plugin"
Expand All @@ -34,7 +34,7 @@ const TheUseOptionMessage = "kitex_gen is not generated due to the -use option"
// Run is an entry of the plugin mode of kitex for thriftgo.
// It reads a plugin request from the standard input and writes out a response.
func Run() int {
data, err := io.ReadAll(os.Stdin)
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
println("Failed to get input:", err.Error())
return 1
Expand Down
39 changes: 39 additions & 0 deletions tool/internal_pkg/tpl/bootstrap.sh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2022 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.

package tpl

// BootstrapTpl is the template for generating bootstrap.sh.
var BootstrapTpl string = `#! /usr/bin/env bash
CURDIR=$(cd $(dirname $0); pwd)
if [ "X$1" != "X" ]; then
RUNTIME_ROOT=$1
else
RUNTIME_ROOT=${CURDIR}
fi
export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT
export KITEX_LOG_DIR="$RUNTIME_ROOT/log"
if [ ! -d "$KITEX_LOG_DIR/app" ]; then
mkdir -p "$KITEX_LOG_DIR/app"
fi
if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then
mkdir -p "$KITEX_LOG_DIR/rpc"
fi
exec "$CURDIR/bin/{{.RealServiceName}}"
`
21 changes: 0 additions & 21 deletions tool/internal_pkg/tpl/bootstrap.sh.tmpl

This file was deleted.

30 changes: 30 additions & 0 deletions tool/internal_pkg/tpl/build.sh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2022 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.

package tpl

// BuildTpl is the template for generating build.sh.
var BuildTpl string = `#!/usr/bin/env bash
RUN_NAME="{{.RealServiceName}}"
mkdir -p output/bin
cp script/* output/
chmod +x output/bootstrap.sh
if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then
go build -o output/bin/${RUN_NAME}
else
go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./...
fi
`
12 changes: 0 additions & 12 deletions tool/internal_pkg/tpl/build.sh.tmpl

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
// Code generated by Kitex {{.Version}}. DO NOT EDIT.
// Copyright 2022 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.

package tpl

// ClientTpl is the template for generating client.go.
var ClientTpl string = `// Code generated by Kitex {{.Version}}. DO NOT EDIT.
package {{ToLower .ServiceName}}
import (
Expand Down Expand Up @@ -77,3 +94,4 @@ func (p *k{{$.ServiceName}}Client) {{.Name}}(ctx context.Context {{range .Args}}
{{- end}}
{{end}}
{{template "@client.go-EOF" .}}
`
Loading

0 comments on commit 5f0f79e

Please sign in to comment.