Skip to content

Commit

Permalink
💡 chore: add comment for exported vars, methods.
Browse files Browse the repository at this point in the history
- re-generate readme docs
- use os and io func instead io/ioutil
  • Loading branch information
inhere committed Dec 12, 2022
1 parent 179afea commit bc0a0b8
Show file tree
Hide file tree
Showing 12 changed files with 1,619 additions and 1,345 deletions.
1,463 changes: 798 additions & 665 deletions README.md

Large diffs are not rendered by default.

1,452 changes: 788 additions & 664 deletions README.zh-CN.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dump/dump.go
Expand Up @@ -19,7 +19,6 @@ const (
)

const defaultSkip = 3
const defaultSkip2 = 2

var (
// valid flag for print caller info
Expand Down
2 changes: 1 addition & 1 deletion fsutil/finder/finder.go
Expand Up @@ -270,7 +270,7 @@ func (f *FileFinder) findInDir(dirPath string) {
ok := true
for _, df := range f.dirFilters {
ok = df.FilterDir(fullPath, baseName)
if true == ok { // 有一个满足即可
if ok { // 有一个满足即可
break
}
}
Expand Down
10 changes: 4 additions & 6 deletions fsutil/operate.go
Expand Up @@ -4,7 +4,6 @@ import (
"archive/zip"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand All @@ -27,12 +26,12 @@ func MkParentDir(fpath string) error {

// DiscardReader anything from the reader
func DiscardReader(src io.Reader) {
_, _ = io.Copy(ioutil.Discard, src)
_, _ = io.Copy(io.Discard, src)
}

// MustReadFile read file contents, will panic on error
func MustReadFile(filePath string) []byte {
bs, err := ioutil.ReadFile(filePath)
bs, err := os.ReadFile(filePath)
if err != nil {
panic(err)
}
Expand All @@ -42,8 +41,7 @@ func MustReadFile(filePath string) []byte {

// MustReadReader read contents from io.Reader, will panic on error
func MustReadReader(r io.Reader) []byte {
// TODO go 1.16+ bs, err := io.ReadAll(r)
bs, err := ioutil.ReadAll(r)
bs, err := io.ReadAll(r)
if err != nil {
panic(err)
}
Expand All @@ -66,7 +64,7 @@ func GetContents(in any) []byte {
// ReadExistFile read file contents if existed, will panic on error
func ReadExistFile(filePath string) []byte {
if IsFile(filePath) {
bs, err := ioutil.ReadFile(filePath)
bs, err := os.ReadFile(filePath)
if err != nil {
panic(err)
}
Expand Down
7 changes: 6 additions & 1 deletion internal/gendoc/main.go
Expand Up @@ -242,7 +242,12 @@ func collectPgkFunc(ms []string, basePkg string) *bytes.Buffer {
if len(lines) > 0 {
bufWriteln(buf, "// source at", filename)
for _, line := range lines {
bufWriteln(buf, strings.TrimRight(line, "{ "))
idx := strings.IndexByte(line, '{')
if idx > 0 {
bufWriteln(buf, line[:idx])
} else {
bufWriteln(buf, line)
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions jsonutil/jsonutil.go
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"os"
"regexp"
"strings"
Expand All @@ -18,7 +17,7 @@ func WriteFile(filePath string, data any) error {
if err != nil {
return err
}
return ioutil.WriteFile(filePath, jsonBytes, 0664)
return os.WriteFile(filePath, jsonBytes, 0664)
}

// ReadFile Read JSON file data
Expand Down
1 change: 1 addition & 0 deletions stdutil/conv_test.go
Expand Up @@ -66,5 +66,6 @@ func TestBaseTypeVal(t *testing.T) {
assert.Err(t, err)

val, err = stdutil.BaseTypeVal2(reflect.ValueOf(int32(2)))
assert.NoErr(t, err)
assert.Eq(t, int64(2), val)
}
2 changes: 1 addition & 1 deletion structs/setval.go
Expand Up @@ -163,7 +163,7 @@ func SetValues(ptr any, data map[string]any, optFns ...SetOptFunc) error {
}

func setValues(rv reflect.Value, data map[string]any, opt *SetOptions) error {
if data == nil || len(data) == 0 {
if len(data) == 0 {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions strutil/secutil/aes_crypt.go
Expand Up @@ -46,9 +46,9 @@ type AesCrypt struct {
iv []byte
key []byte

init bool
keyLen int
padding string
init bool
keyLen int
// padding string

encryptType string
}
Expand Down
8 changes: 8 additions & 0 deletions testutil/assert/assertions_methods.go
Expand Up @@ -13,48 +13,56 @@ func (as *Assertions) NotNil(val any, fmtAndArgs ...any) *Assertions {
return as
}

// True check, please see True()
func (as *Assertions) True(give bool, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = True(as.t, give, fmtAndArgs...)
return as
}

// False check, please see False()
func (as *Assertions) False(give bool, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = False(as.t, give, fmtAndArgs...)
return as
}

// Empty check, please see Empty()
func (as *Assertions) Empty(give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Empty(as.t, give, fmtAndArgs...)
return as
}

// NotEmpty check, please see NotEmpty()
func (as *Assertions) NotEmpty(give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NotEmpty(as.t, give, fmtAndArgs...)
return as
}

// Panics check, please see Panics()
func (as *Assertions) Panics(fn PanicRunFunc, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Panics(as.t, fn, fmtAndArgs...)
return as
}

// NotPanics check, please see NotPanics()
func (as *Assertions) NotPanics(fn PanicRunFunc, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NotPanics(as.t, fn, fmtAndArgs...)
return as
}

// PanicsMsg check, please see PanicsMsg()
func (as *Assertions) PanicsMsg(fn PanicRunFunc, wantVal any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = PanicsMsg(as.t, fn, wantVal, fmtAndArgs...)
return as
}

// PanicsErrMsg check, please see PanicsErrMsg()
func (as *Assertions) PanicsErrMsg(fn PanicRunFunc, errMsg string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = PanicsErrMsg(as.t, fn, errMsg, fmtAndArgs...)
Expand Down
9 changes: 8 additions & 1 deletion testutil/assert/util.go
Expand Up @@ -58,7 +58,14 @@ func truncatingFormat(data any) string {
return "<nil>"
}

value := fmt.Sprintf("%T(%v)", data, data)
var value string
switch data.(type) {
case string:
value = fmt.Sprintf("string(%q)", data)
default:
value = fmt.Sprintf("%T(%v)", data, data)
}

// Give us some space the type info too if needed.
max := bufio.MaxScanTokenSize - 100
if len(value) > max {
Expand Down

0 comments on commit bc0a0b8

Please sign in to comment.