-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💥 refactor: rename the package stdutil to goinfo, and remove some rep…
…eated util func
- Loading branch information
Showing
17 changed files
with
160 additions
and
550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# GoInfo | ||
|
||
`goutil/goinfo` provide some useful info for golang. | ||
|
||
> Github: https://github.com/gookit/goutil | ||
## Install | ||
|
||
```bash | ||
go get github.com/gookit/goutil/goinfo | ||
``` | ||
|
||
## Go docs | ||
|
||
- [Go docs](https://pkg.go.dev/github.com/gookit/goutil) | ||
|
||
## Usage | ||
|
||
```go | ||
gover := goinfo.GoVersion() // eg: "1.15.6" | ||
|
||
``` | ||
|
||
## Testings | ||
|
||
```shell | ||
go test -v ./goinfo/... | ||
``` | ||
|
||
Test limit by regexp: | ||
|
||
```shell | ||
go test -v -run ^TestSetByKeys ./goinfo/... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package goinfo_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gookit/goutil/dump" | ||
"github.com/gookit/goutil/goinfo" | ||
"github.com/gookit/goutil/testutil/assert" | ||
) | ||
|
||
func TestFuncName(t *testing.T) { | ||
name := goinfo.FuncName(goinfo.PkgName) | ||
assert.Eq(t, "github.com/gookit/goutil/goinfo.PkgName", name) | ||
} | ||
|
||
func TestPkgName(t *testing.T) { | ||
name := goinfo.PkgName(goinfo.FuncName(goinfo.GetCallerInfo)) | ||
assert.Eq(t, "github.com/gookit/goutil/goinfo", name) | ||
} | ||
|
||
func TestFullFcName_Parse(t *testing.T) { | ||
fullName := goinfo.FuncName(goinfo.GetCallerInfo) | ||
|
||
ffn := goinfo.FullFcName{FullName: fullName} | ||
ffn.Parse() | ||
assert.Eq(t, fullName, ffn.String()) | ||
assert.Eq(t, "goinfo", ffn.PkgName()) | ||
assert.Eq(t, "GetCallerInfo", ffn.FuncName()) | ||
assert.Eq(t, "github.com/gookit/goutil/goinfo", ffn.PkgPath()) | ||
dump.P(ffn) | ||
|
||
st := goinfo.FullFcName{} | ||
fullName = goinfo.FuncName(st.FuncName) | ||
|
||
ffn = goinfo.FullFcName{FullName: fullName} | ||
ffn.Parse() | ||
assert.Eq(t, "(*FullFcName).FuncName-fm", ffn.FuncName()) | ||
dump.P(ffn) | ||
} | ||
|
||
func TestCutFuncName(t *testing.T) { | ||
fullName := goinfo.FuncName(goinfo.GetCallerInfo) | ||
|
||
pkgPath, funcName := goinfo.CutFuncName(fullName) | ||
assert.Eq(t, "GetCallerInfo", funcName) | ||
assert.Eq(t, "github.com/gookit/goutil/goinfo", pkgPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Package goinfo provide some standard util functions for go. | ||
package goinfo | ||
|
||
import "runtime" | ||
|
||
// GoVersion get go runtime version. eg: "1.18.2" | ||
func GoVersion() string { | ||
return runtime.Version()[2:] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package goinfo_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gookit/goutil/goinfo" | ||
"github.com/gookit/goutil/testutil/assert" | ||
) | ||
|
||
func TestGoVersion(t *testing.T) { | ||
assert.NotEmpty(t, goinfo.GoVersion()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package goinfo_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/gookit/goutil/goinfo" | ||
"github.com/gookit/goutil/testutil/assert" | ||
) | ||
|
||
func TestGetCallStacks(t *testing.T) { | ||
msg := goinfo.GetCallStacks(false) | ||
fmt.Println(string(msg)) | ||
|
||
fmt.Println("-------------full stacks-------------") | ||
msg = goinfo.GetCallStacks(true) | ||
fmt.Println(string(msg)) | ||
} | ||
|
||
func TestGetCallersInfo(t *testing.T) { | ||
cs := someFunc1() | ||
assert.Len(t, cs, 1) | ||
assert.Contains(t, cs[0], "goutil/goinfo_test.someFunc1(),stack_test.go") | ||
|
||
cs = someFunc2() | ||
assert.Len(t, cs, 1) | ||
assert.Contains(t, cs[0], "goutil/goinfo_test.someFunc2(),stack_test.go") | ||
|
||
loc := someFunc3() | ||
assert.NotEmpty(t, loc) | ||
assert.Contains(t, loc, "goutil/goinfo_test.someFunc3(),stack_test.go") | ||
// dump.P(cs) | ||
} | ||
|
||
func someFunc1() []string { | ||
return goinfo.GetCallersInfo(1, 2) | ||
} | ||
|
||
func someFunc2() []string { | ||
return goinfo.SimpleCallersInfo(1, 1) | ||
} | ||
|
||
func someFunc3() string { | ||
return goinfo.GetCallerInfo(1) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.