From d5cb0508d2f35b86b21336f3d660e847f5a50cac Mon Sep 17 00:00:00 2001 From: AlexStocks Date: Sun, 13 Dec 2020 22:29:21 +0800 Subject: [PATCH] Add: github action --- .github/workflows/github-actions.yml | 6 ++++++ .golangci.yml | 12 ++++++------ context/context.go | 4 +++- context/context_test.go | 3 ++- log/color.go | 10 +++++----- math/big/decimal.go | 22 +++++++++++++--------- math/big/decimal_test.go | 2 +- runtime/sys.go | 3 +++ 8 files changed, 39 insertions(+), 23 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 53c65c6..f07a153 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -59,6 +59,12 @@ jobs: chmod u+x /tmp/tools/license/license-header-checker /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: Go Test run: GO111MODULE=on && go mod vendor && go test ./... -bench . -race -v -coverprofile=coverage.txt diff --git a/.golangci.yml b/.golangci.yml index ec838c6..7303e36 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,12 +32,12 @@ linters-settings: disabled-checks: - wrapperFunc -linters: - enable-all: true - disable: - - maligned - - prealloc - - gochecknoglobals +# linters: +# enable-all: true +# disable: +# - maligned +# - prealloc +# - gochecknoglobals run: skip-dirs: diff --git a/context/context.go b/context/context.go index 303ca6f..359fbef 100644 --- a/context/context.go +++ b/context/context.go @@ -21,8 +21,10 @@ import ( "context" ) +type ValueContextKeyType int32 + var ( - defaultCtxKey = 1 + defaultCtxKey = ValueContextKeyType(1) ) type Values struct { diff --git a/context/context_test.go b/context/context_test.go index 1049d4c..0e5d542 100644 --- a/context/context_test.go +++ b/context/context_test.go @@ -18,6 +18,7 @@ package gxcontext import ( + "context" "testing" ) @@ -26,7 +27,7 @@ import ( ) func TestValuesContext_General(t *testing.T) { - vc := NewValuesContext(nil) + vc := NewValuesContext(context.Background()) assert.NotNil(t, vc) key := "hello" diff --git a/log/color.go b/log/color.go index a08e674..01f3fbc 100644 --- a/log/color.go +++ b/log/color.go @@ -67,16 +67,16 @@ func funcFileLine() string { func CPrintf(color []byte, format string, args ...interface{}) { if isatty.IsTerminal(os.Stdout.Fd()) { - fmt.Fprintf(os.Stdout, string(color)+funcFileLine()+fmt.Sprintf(format, args...)+string(reset)) + fmt.Fprint(os.Stdout, string(color)+funcFileLine()+fmt.Sprintf(format, args...)+string(reset)) } else { - fmt.Fprintf(os.Stdout, fmt.Sprintf(format, args...)) + fmt.Fprint(os.Stdout, fmt.Sprintf(format, args...)) } } func CPrintfln(color []byte, format string, args ...interface{}) { logStr := fmt.Sprintf(format, args...) if isatty.IsTerminal(os.Stdout.Fd()) { - fmt.Fprintf(os.Stdout, string(color)+funcFileLine()+"%s"+string(reset)+"\n", logStr) + fmt.Fprint(os.Stdout, string(color)+funcFileLine()+"%s"+string(reset)+"\n", logStr) } else { fmt.Fprintf(os.Stdout, "%s\n", logStr) } @@ -85,7 +85,7 @@ func CPrintfln(color []byte, format string, args ...interface{}) { func CEPrintf(color []byte, format string, args ...interface{}) { logStr := fmt.Sprintf(format, args...) if isatty.IsTerminal(os.Stdout.Fd()) { - fmt.Fprintf(os.Stderr, string(color)+funcFileLine()+"%s"+string(reset), logStr) + fmt.Fprint(os.Stderr, string(color)+funcFileLine()+"%s"+string(reset), logStr) } else { fmt.Fprintf(os.Stderr, "%s", logStr) } @@ -94,7 +94,7 @@ func CEPrintf(color []byte, format string, args ...interface{}) { func CEPrintfln(color []byte, format string, args ...interface{}) { logStr := fmt.Sprintf(format, args...) if isatty.IsTerminal(os.Stdout.Fd()) { - fmt.Fprintf(os.Stderr, string(color)+funcFileLine()+"%s"+string(reset)+"\n", logStr) + fmt.Fprint(os.Stderr, string(color)+funcFileLine()+"%s"+string(reset)+"\n", logStr) } else { fmt.Fprintf(os.Stderr, "%s\n", logStr) } diff --git a/math/big/decimal.go b/math/big/decimal.go index 274863a..2b9bdc1 100644 --- a/math/big/decimal.go +++ b/math/big/decimal.go @@ -60,12 +60,12 @@ const ( DivFracIncr = 4 // ModeHalfEven rounds normally. - ModeHalfEven RoundMode = 5 + ModeHalfEven = RoundMode(5) // Truncate just truncates the decimal. - ModeTruncate RoundMode = 10 + ModeTruncate = RoundMode(10) // Ceiling is not supported now. - modeCeiling RoundMode = 0 - maxDecimalScale = 30 + modeCeiling = RoundMode(0) + maxDecimalScale = int32(30) ) var ( @@ -1173,7 +1173,7 @@ with the correct -1/0/+1 result 7E F2 04 C7 2D FB 2D */ func (d *Decimal) ToBin(precision, frac int) ([]byte, error) { - if precision > digitsPerWord*maxWordBufLen || precision < 0 || frac > maxDecimalScale || frac < 0 { + if precision > digitsPerWord*maxWordBufLen || precision < 0 || frac > int(maxDecimalScale) || frac < 0 { return nil, ErrBadNumber } var err error @@ -1773,10 +1773,12 @@ func doAdd(from1, from2, to *Decimal) error { stop = 0 if wordsInt1 > wordsInt2 { idx1 = wordsInt1 - wordsInt2 - dec1, dec2 = from1, from2 + // dec1, dec2 = from1, from2 + dec1 = from1 } else { idx1 = wordsInt2 - wordsInt1 - dec1, dec2 = from2, from1 + // dec1, dec2 = from2, from1 + dec1 = from2 } for idx1 > stop { idxTo-- @@ -1853,7 +1855,8 @@ func DecimalMul(from1, from2, to *Decimal) error { tmp1 = wordsIntTo tmp2 = wordsFracTo ) - to.resultFrac = myMinInt8(from1.resultFrac+from2.resultFrac, maxDecimalScale) + // to.resultFrac = myMinInt8(from1.resultFrac+from2.resultFrac, maxDecimalScale) + to.resultFrac = myMinInt8(from1.resultFrac+from2.resultFrac, int8(30)) wordsIntTo, wordsFracTo, err = fixWordCntError(wordsIntTo, wordsFracTo) to.negative = from1.negative != from2.negative to.digitsFrac = from1.digitsFrac + from2.digitsFrac @@ -1967,7 +1970,8 @@ func DecimalMul(from1, from2, to *Decimal) error { // to - quotient // fracIncr - increment of fraction func DecimalDiv(from1, from2, to *Decimal, fracIncr int) error { - to.resultFrac = myMinInt8(from1.resultFrac+int8(fracIncr), maxDecimalScale) + // to.resultFrac = myMinInt8(from1.resultFrac+int8(fracIncr), int8(maxDecimalScale)) + to.resultFrac = myMinInt8(from1.resultFrac+int8(fracIncr), int8(30)) return doDivMod(from1, from2, to, nil, fracIncr) } diff --git a/math/big/decimal_test.go b/math/big/decimal_test.go index 350d9ea..c3317f9 100644 --- a/math/big/decimal_test.go +++ b/math/big/decimal_test.go @@ -264,7 +264,7 @@ func TestShift(t *testing.T) { for _, ca := range tests { var dec Decimal err := dec.FromBytes([]byte(ca.input)) - //assert.Equal(t, err, IsNil) + assert.Nil(t, err) //origin := dec err = dec.Shift(ca.shift) assert.Equal(t, err, ca.err) diff --git a/runtime/sys.go b/runtime/sys.go index 78b5ee0..ec0f922 100644 --- a/runtime/sys.go +++ b/runtime/sys.go @@ -127,6 +127,9 @@ func GetProcessMemoryStat() (uint64, error) { } memInfo, err := p.MemoryInfo() + if err != nil { + return 0, err + } return memInfo.RSS, nil }