Skip to content

Commit

Permalink
chore: add desc commonts for const, vars and package
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 28, 2022
1 parent 752d3b3 commit ad8ce94
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 53 deletions.
2 changes: 2 additions & 0 deletions cliutil/cmdline/cmdline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package cmdline provide quick build and parse cmd line string.
package cmdline
2 changes: 2 additions & 0 deletions fmtutil/fmtutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package fmtutil provide some format util functions.
package fmtutil
1 change: 1 addition & 0 deletions fsutil/finder/finder.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package finder provide a finder tool for find files
package finder

import (
Expand Down
1 change: 1 addition & 0 deletions fsutil/fsutil.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package fsutil Filesystem util functions, quick create, read and write file. eg: file and dir check, operate
package fsutil

import (
Expand Down
4 changes: 3 additions & 1 deletion fsutil/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ func GlobWithFunc(pattern string, fn func(filePath string) error) (err error) {
return
}

// filter and handle func for FindInDir
type (
// FilterFunc type for FindInDir
FilterFunc func(fPath string, fi os.FileInfo) bool
// HandleFunc type for FindInDir
HandleFunc func(fPath string, fi os.FileInfo) error
)

// FindInDir code refer the go pkg: path/filepath.glob()
//
// filters: return false will skip the file.
func FindInDir(dir string, handleFn HandleFunc, filters ...FilterFunc) (e error) {
fi, err := os.Stat(dir)
Expand Down
1 change: 1 addition & 0 deletions jsonutil/jsonutil.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package jsonutil provide some util functions for quick operate JSON data
package jsonutil

import (
Expand Down
2 changes: 2 additions & 0 deletions maputil/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Map Utils

`maputil` provide map data util functions. eg: convert, sub-value get, simple merge

- use `map[string]any` as Data
- deep get value by key path
- deep set value by key path
Expand Down
1 change: 1 addition & 0 deletions maputil/maputil.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package maputil provide map data util functions. eg: convert, sub-value get, simple merge
package maputil

import (
Expand Down
41 changes: 39 additions & 2 deletions netutil/netutil.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Package netutil provide some network util functions.
package netutil

import (
"net"
"net/netip"
)

// InternalIP get internal IP
func InternalIP() (ip string) {
// InternalIPOld get internal IP buy old logic
func InternalIPOld() (ip string) {
addrs, err := net.InterfaceAddrs()
if err != nil {
panic("Oops: " + err.Error())
Expand All @@ -22,3 +24,38 @@ func InternalIP() (ip string) {
}
return
}

// InternalIP get internal IP
func InternalIP() (ip string) {
addr := netip.IPv4Unspecified()
if addr.IsValid() {
return addr.String()
}

addr = netip.IPv6Unspecified()
if addr.IsValid() {
return addr.String()
}

return ""
}

// InternalIPv4 get internal IPv4
func InternalIPv4() (ip string) {
addr := netip.IPv4Unspecified()

if addr.IsValid() {
return addr.String()
}
return ""
}

// InternalIPv6 get internal IPv6
func InternalIPv6() (ip string) {
addr := netip.IPv6Unspecified()

if addr.IsValid() {
return addr.String()
}
return ""
}
41 changes: 0 additions & 41 deletions netutil/netutil_go118.go

This file was deleted.

4 changes: 0 additions & 4 deletions netutil/netutil_ne118.go

This file was deleted.

2 changes: 2 additions & 0 deletions reflects/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Reflects

`reflects` Provide extends reflect util functions.

- some features

## Install
Expand Down
2 changes: 2 additions & 0 deletions reflects/reflects.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package reflects Provide extends reflect util functions.
package reflects
29 changes: 29 additions & 0 deletions stdio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Stdio

`stdio` provide some standard IO util functions.

## Install

```bash
go get github.com/gookit/goutil/stdio
```

## Go docs

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

## Usage

Please see tests.

## Testings

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

Test limit by regexp:

```shell
go test -v -run ^TestSetByKeys ./stdio/...
```
2 changes: 2 additions & 0 deletions stdio/stdio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package stdio provide some standard IO util functions.
package stdio
2 changes: 1 addition & 1 deletion stdio/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io"
)

// WriteWrapper struct
// WriteWrapper warp io.Writer support more operate methods.
type WriteWrapper struct {
Out io.Writer
}
Expand Down
4 changes: 3 additions & 1 deletion testutil/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Test Utils

`testutil` provide some test help util functions. eg: http test, mock ENV value

- `assert` go tests helper
- env variable mocks
- http request mock

## Install

```bash
go get github.com/gookit/goutil/sysutil
go get github.com/gookit/goutil/testutil
```

## [`assert`](./assert) tests
Expand Down
1 change: 1 addition & 0 deletions testutil/testutil.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package testutil provide some test help util functions. eg: http test, mock ENV value
package testutil

import (
Expand Down
9 changes: 6 additions & 3 deletions testutil/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ func NewTestWriter() *TestWriter {
}

// SetErrOnWrite method
func (w *TestWriter) SetErrOnWrite() {
func (w *TestWriter) SetErrOnWrite() *TestWriter {
w.ErrOnWrite = true
return w
}

// SetErrOnFlush method
func (w *TestWriter) SetErrOnFlush() {
func (w *TestWriter) SetErrOnFlush() *TestWriter {
w.ErrOnFlush = true
return w
}

// SetErrOnClose method
func (w *TestWriter) SetErrOnClose() {
func (w *TestWriter) SetErrOnClose() *TestWriter {
w.ErrOnClose = true
return w
}

// Flush implements
Expand Down

0 comments on commit ad8ce94

Please sign in to comment.