Skip to content

Commit

Permalink
chore: upgrade go version to go1.19 (#46)
Browse files Browse the repository at this point in the history
* chore: upgrade go version to go1.19

* chore: upgrade github actions
  • Loading branch information
DarthPestilane authored Oct 31, 2022
1 parent 38ded5d commit fbbc97b
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
name: release
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v3
if: success() && startsWith(github.ref, 'refs/tags/')
with:
version: latest
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.15.x
go-version: 1.19.x

- name: Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: cache-go-${{ runner.os }}-1.15.x-${{ github.run_number }}
restore-keys: |
cache-go-${{ runner.os}}-1.15.x-
cache-go-${{ runner.os}}-1.19.x-
- name: Build
run: make build-all

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.45
version: v1.50
skip-pkg-cache: true
skip-build-cache: true

Expand All @@ -52,20 +52,20 @@ jobs:
GO111MODULE: on
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go-version: [ 1.16.x, 1.17.x, 1.18.x ]
os: [ubuntu-latest, macos-12, windows-latest]
go-version: [1.17.x, 1.18.x, 1.19.x]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Go ${{ matrix.go-version}}
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version}}

- name: Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
Expand All @@ -80,7 +80,7 @@ jobs:
run: make test-v

- name: Upload coverage
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: .testCoverage.txt
7 changes: 1 addition & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ run:
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
skip-dirs: [ 'examples', 'internal/mock' ]
skip-dirs: ['examples', 'internal/mock']

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
Expand All @@ -43,10 +43,7 @@ linters:
- staticcheck
- unused
- gosimple
- structcheck
- varcheck
- ineffassign
- deadcode
- typecheck
- goconst
- gofmt
Expand All @@ -55,6 +52,4 @@ linters:
- unparam
- exportloopref
- godot

#- scopelint deprecated, use exportloopref instead.
fast: true
7 changes: 5 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//go:build go1.16
// +build go1.16

package easytcp

import (
"fmt"
"io/ioutil"
"io"
"log"
"os"
)
Expand All @@ -26,7 +29,7 @@ func newLogger() *DefaultLogger {

func newMuteLogger() *DefaultLogger {
return &DefaultLogger{
rawLogger: log.New(ioutil.Discard, "easytcp", log.LstdFlags),
rawLogger: log.New(io.Discard, "easytcp", log.LstdFlags),
}
}

Expand Down
55 changes: 55 additions & 0 deletions logger_before_1.16.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//go:build !go1.16
// +build !go1.16

package easytcp

import (
"fmt"
"io/ioutil"
"log"
"os"
)

var _ Logger = &DefaultLogger{}

// Log is the instance of Logger interface.
var Log Logger = newMuteLogger()

// Logger is the generic interface for log recording.
type Logger interface {
Errorf(format string, args ...interface{})
Tracef(format string, args ...interface{})
}

func newLogger() *DefaultLogger {
return &DefaultLogger{
rawLogger: log.New(os.Stdout, "easytcp ", log.Ldate|log.Ltime|log.Lmicroseconds|log.Lmsgprefix),
}
}

func newMuteLogger() *DefaultLogger {
return &DefaultLogger{
rawLogger: log.New(ioutil.Discard, "easytcp", log.LstdFlags),
}
}

// DefaultLogger is the default logger instance for this package.
// DefaultLogger uses the built-in log.Logger.
type DefaultLogger struct {
rawLogger *log.Logger
}

// Errorf implements Logger Errorf method.
func (d *DefaultLogger) Errorf(format string, args ...interface{}) {
d.rawLogger.Printf("[ERROR] %s", fmt.Sprintf(format, args...))
}

// Tracef implements Logger Tracef method.
func (d *DefaultLogger) Tracef(format string, args ...interface{}) {
d.rawLogger.Printf("[TRACE] %s", fmt.Sprintf(format, args...))
}

// SetLogger sets the package logger.
func SetLogger(lg Logger) {
Log = lg
}
13 changes: 7 additions & 6 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ type HandlerFunc func(ctx Context)
// MiddlewareFunc is the function type for middlewares.
// A common pattern is like:
//
// var mf MiddlewareFunc = func(next HandlerFunc) HandlerFunc {
// return func(ctx Context) {
// next(ctx)
// }
// }
// var mf MiddlewareFunc = func(next HandlerFunc) HandlerFunc {
// return func(ctx Context) {
// next(ctx)
// }
// }
type MiddlewareFunc func(next HandlerFunc) HandlerFunc

var nilHandler HandlerFunc = func(ctx Context) {}
Expand Down Expand Up @@ -77,7 +77,8 @@ func (r *Router) handleRequest(ctx Context) {

// wrapHandlers wraps handler and middlewares into a right order call stack.
// Makes something like:
// var wrapped HandlerFunc = m1(m2(m3(handle)))
//
// var wrapped HandlerFunc = m1(m2(m3(handle)))
func (r *Router) wrapHandlers(handler HandlerFunc, middles []MiddlewareFunc) (wrapped HandlerFunc) {
if handler == nil {
handler = r.notFoundHandler
Expand Down

0 comments on commit fbbc97b

Please sign in to comment.