Skip to content

Commit

Permalink
chore: update some readme and re-generate readme docs
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 9, 2022
1 parent 3587155 commit c3f5086
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 23 deletions.
37 changes: 27 additions & 10 deletions README.md
Expand Up @@ -82,7 +82,7 @@ u64Val = goutil.Uint("2") // 2

## Packages

### Array/Slice
### Array and Slice

> Package `github.com/gookit/goutil/arrutil`
Expand Down Expand Up @@ -153,6 +153,21 @@ ss, err := arrutil.ToStrings([]int{1, 2}) // ss: []string{"1", "2"}
```


### Bytes Utils

> Package `github.com/gookit/goutil/byteutil`
```go
// source at byteutil/buffer.go
func NewBuffer() *Buffer
// source at byteutil/bytex.go
func Md5(src any) []byte
// source at byteutil/encoder.go
func NewStdEncoder(encFn func(src []byte) []byte, decFn func(src []byte) ([]byte, error)) *StdEncoder
// source at byteutil/pool.go
func NewChanPool(maxSize int, width int, capWidth int) *ChanPool
```

### Cflag

> Package `github.com/gookit/goutil/cflag`
Expand Down Expand Up @@ -549,7 +564,7 @@ runtime.goexit()
```
### Formatting
### Format Utils
> Package `github.com/gookit/goutil/fmtutil`
Expand Down Expand Up @@ -906,7 +921,7 @@ func NewValue(val any) *Value
```go
// source at strutil/bytes.go
func NewBuffer() *Buffer
func NewByteChanPool(maxSize int, width int, capWidth int) *ByteChanPool
func NewByteChanPool(maxSize, width, capWidth int) *ByteChanPool
// source at strutil/check.go
func NoCaseEq(s, t string) bool
func IsNumChar(c byte) bool
Expand Down Expand Up @@ -974,15 +989,18 @@ func ToOSArgs(s string) []string
func MustToTime(s string, layouts ...string) time.Time
func ToTime(s string, layouts ...string) (t time.Time, err error)
func ToDuration(s string) (time.Duration, error)
// source at strutil/crypto.go
func Md5(src any) string
func MD5(src any) string { return Md5(src) }
func GenMd5(src any) string { return Md5(src) }
func Md5Bytes(src any) []byte
func HashPasswd(pwd, key string) string
func VerifyPasswd(pwdMAC, pwd, key string) bool
// source at strutil/encode.go
func EscapeJS(s string) string
func EscapeHTML(s string) string
func AddSlashes(s string) string
func StripSlashes(s string) string
func Md5(src any) string
func MD5(src any) string { return Md5(src) }
func GenMd5(src any) string { return Md5(src) }
func Md5Bytes(src any) []byte
func URLEncode(s string) string
func URLDecode(s string) string
func B32Encode(str string) string
Expand Down Expand Up @@ -1081,7 +1099,7 @@ func RenderText(input string, data any, fns template.FuncMap, isFile ...bool) st
func WrapTag(s, tag string) string
```
### System
### System Utils
> Package `github.com/gookit/goutil/sysutil`
Expand Down Expand Up @@ -1142,7 +1160,7 @@ func ChangeUserByName(newUname string) (err error)
func ChangeUserUidGid(newUid int, newGid int) (err error)
```
### Testing
### Testing Utils
> Package `github.com/gookit/goutil/testutil`
Expand Down Expand Up @@ -1383,4 +1401,3 @@ root@xx:/go/work# go test ./...
## License
[MIT](LICENSE)
37 changes: 28 additions & 9 deletions README.zh-CN.md
Expand Up @@ -44,6 +44,7 @@ Go一些常用的string、number、slice、map、struct、env、system等工具
- [`testutil`](testutil) test help 相关操作的函数工具包. eg: http test, mock ENV value
- [assert](testutil/assert) 用于帮助测试的断言函数工具包
- [`timex`](timex) 提供增强的 time.Time 实现。添加更多常用的功能方法
- 提供类似 `Y-m-d H:i:s` 的日期时间格式解析处理
- 例如: DayStart(), DayAfter(), DayAgo(), DateFormat() 等等

## GoDoc
Expand Down Expand Up @@ -80,7 +81,7 @@ u64Val = goutil.Uint("2") // 2

## Packages

### Array/Slice
### Array and Slice

> Package `github.com/gookit/goutil/arrutil`
Expand Down Expand Up @@ -151,6 +152,21 @@ ss, err := arrutil.ToStrings([]int{1, 2}) // ss: []string{"1", "2"}
```


### Bytes Utils

> Package `github.com/gookit/goutil/byteutil`
```go
// source at byteutil/buffer.go
func NewBuffer() *Buffer
// source at byteutil/bytex.go
func Md5(src any) []byte
// source at byteutil/encoder.go
func NewStdEncoder(encFn func(src []byte) []byte, decFn func(src []byte) ([]byte, error)) *StdEncoder
// source at byteutil/pool.go
func NewChanPool(maxSize int, width int, capWidth int) *ChanPool
```

### Cflag

> Package `github.com/gookit/goutil/cflag`
Expand Down Expand Up @@ -549,7 +565,7 @@ runtime.goexit()
```
### Formatting
### Format Utils
> Package `github.com/gookit/goutil/fmtutil`
Expand Down Expand Up @@ -906,7 +922,7 @@ func NewValue(val any) *Value
```go
// source at strutil/bytes.go
func NewBuffer() *Buffer
func NewByteChanPool(maxSize int, width int, capWidth int) *ByteChanPool
func NewByteChanPool(maxSize, width, capWidth int) *ByteChanPool
// source at strutil/check.go
func NoCaseEq(s, t string) bool
func IsNumChar(c byte) bool
Expand Down Expand Up @@ -974,15 +990,18 @@ func ToOSArgs(s string) []string
func MustToTime(s string, layouts ...string) time.Time
func ToTime(s string, layouts ...string) (t time.Time, err error)
func ToDuration(s string) (time.Duration, error)
// source at strutil/crypto.go
func Md5(src any) string
func MD5(src any) string { return Md5(src) }
func GenMd5(src any) string { return Md5(src) }
func Md5Bytes(src any) []byte
func HashPasswd(pwd, key string) string
func VerifyPasswd(pwdMAC, pwd, key string) bool
// source at strutil/encode.go
func EscapeJS(s string) string
func EscapeHTML(s string) string
func AddSlashes(s string) string
func StripSlashes(s string) string
func Md5(src any) string
func MD5(src any) string { return Md5(src) }
func GenMd5(src any) string { return Md5(src) }
func Md5Bytes(src any) []byte
func URLEncode(s string) string
func URLDecode(s string) string
func B32Encode(str string) string
Expand Down Expand Up @@ -1081,7 +1100,7 @@ func RenderText(input string, data any, fns template.FuncMap, isFile ...bool) st
func WrapTag(s, tag string) string
```
### System
### System Utils
> Package `github.com/gookit/goutil/sysutil`
Expand Down Expand Up @@ -1142,7 +1161,7 @@ func ChangeUserByName(newUname string) (err error)
func ChangeUserUidGid(newUid int, newGid int) (err error)
```
### Testing
### Testing Utils
> Package `github.com/gookit/goutil/testutil`
Expand Down
46 changes: 46 additions & 0 deletions byteutil/README.md
@@ -0,0 +1,46 @@
# Bytes Util

Provide some commonly bytes util functions.

## Install

```shell
go get github.com/gookit/goutil/byteutil
```

## Go docs

- [Go docs](https://pkg.go.dev/github.com/gookit/goutil/byteutil)

## Functions API

```go
var HexEncoder = NewStdEncoder(func(src []byte) []byte { ... }, func(src []byte) ([]byte, error) { ... }) ...
func Md5(src any) []byte
type Buffer struct{ ... }
func NewBuffer() *Buffer
type BytesEncoder interface{ ... }
type ChanPool struct{ ... }
func NewChanPool(maxSize int, width int, capWidth int) *ChanPool
type StdEncoder struct{ ... }
func NewStdEncoder(encFn func(src []byte) []byte, decFn func(src []byte) ([]byte, error)) *StdEncoder
```

## Code Check & Testing

```bash
gofmt -w -l ./
golint ./...
```

**Testing**:

```shell
go test -v ./byteutil/...
```

**Test limit by regexp**:

```shell
go test -v -run ^TestSetByKeys ./byteutil/...
```
8 changes: 8 additions & 0 deletions goutil.go
Expand Up @@ -61,3 +61,11 @@ func FuncName(f any) string {
func PkgName(funcName string) string {
return stdutil.PkgName(funcName)
}

// ErrOnFail return input error on cond is false, otherwise return nil
func ErrOnFail(cond bool, err error) error {
if !cond {
return err
}
return nil
}
9 changes: 5 additions & 4 deletions internal/gendoc/main.go
Expand Up @@ -29,13 +29,14 @@ var (
"internal",
}
nameMap = map[string]string{
"arr": "array/Slice",
"arr": "array and Slice",
"str": "strings",
"sys": "system",
"byte": "Bytes Utils",
"sys": "system Utils",
"math": "math/Number",
"fs": "file System",
"fmt": "formatting",
"test": "testing",
"fmt": "format Utils",
"test": "testing Utils",
"dump": "dumper",
"structs": "structs",
"json": "JSON Utils",
Expand Down

0 comments on commit c3f5086

Please sign in to comment.