Skip to content

Commit

Permalink
fix: 2024-04-02 12:22:17
Browse files Browse the repository at this point in the history
  • Loading branch information
kooksee committed Apr 2, 2024
1 parent 261f737 commit 0be5ebc
Show file tree
Hide file tree
Showing 66 changed files with 226 additions and 201 deletions.
4 changes: 2 additions & 2 deletions assert/must.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Must(err error, args ...interface{}) {
}

func MustFn(errFn func() error, args ...interface{}) {
var err = try.Try(errFn)
err := try.Try(errFn)
if generic.IsNil(err) {
return
}
Expand Down Expand Up @@ -54,7 +54,7 @@ func Exit(err error, args ...interface{}) {
}

func ExitFn(errFn func() error, args ...interface{}) {
var err = try.Try(errFn)
err := try.Try(errFn)
if generic.IsNil(err) {
return
}
Expand Down
8 changes: 4 additions & 4 deletions assert/must_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ func panicNoErr() (*errBase, error) {
}

func TestPanicErr(t *testing.T) {
var is = assert.New(t)
is := assert.New(t)
is.Panics(func() {
var ret = Must1(panicErr())
ret := Must1(panicErr())
fmt.Println(ret == nil)
})

is.NotPanics(func() {
var ret = Must1(panicNoErr())
ret := Must1(panicNoErr())
fmt.Println(ret.msg)
})
}
Expand All @@ -45,7 +45,7 @@ func TestRespNext(t *testing.T) {
}

func testPanic1(t *testing.T) {
//xerrImpl.Must(xerrImpl.New("ok"))
// xerrImpl.Must(xerrImpl.New("ok"))
Must(init1Next())
}

Expand Down
6 changes: 3 additions & 3 deletions async/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (
func Async[T any](fn func() (T, error)) *Future[T] {
assert.If(fn == nil, "[Async] [fn] is nil")

var f = newFuture[T]()
f := newFuture[T]()
go func() {
defer recovery.Recovery(func(err error) {
err = errors.WrapKV(err, "fn_stack", stack.CallerWithFunc(fn).String())
f.setErr(err)
})

var t, e = fn()
t, e := fn()
if e != nil {
f.setErr(e)
} else {
Expand Down Expand Up @@ -87,7 +87,7 @@ func Timeout(dur time.Duration, fn func() error) (gErr error) {
assert.If(fn == nil, "[Timeout] [fn] is nil")
assert.If(dur <= 0, "[Timeout] [dur] should not be less than zero")

var done = make(chan struct{})
done := make(chan struct{})
go func() {
defer close(done)
gErr = try.Try(fn)
Expand Down
10 changes: 5 additions & 5 deletions async/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ func httpGetList() *Iterator[*http.Response] {
}

func TestGoChan(t *testing.T) {
var now = time.Now()
now := time.Now()
defer func() {
fmt.Println(time.Since(now))
}()

var val1 = Async(func() (string, error) {
val1 := Async(func() (string, error) {
time.Sleep(time.Millisecond)
fmt.Println("2")
//return WithErr(errors.New("error"))
// return WithErr(errors.New("error"))
return "hello", nil
})

var val2 = Async(func() (string, error) {
val2 := Async(func() (string, error) {
time.Sleep(time.Millisecond)
fmt.Println("3")
//return WithErr(errors.New("error"))
// return WithErr(errors.New("error"))
return "hello", nil
})

Expand Down
2 changes: 1 addition & 1 deletion async/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func TestName(t *testing.T) {
var ch = make(chan string, 10)
ch := make(chan string, 10)
ch <- "hello"
ch <- "hello"
ch <- "hello"
Expand Down
8 changes: 4 additions & 4 deletions async/promise.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func Promise[T any](fn func(resolve func(T), reject func(err error))) *Future[T] {
assert.If(fn == nil, "[fn] is nil")

var f = newFuture[T]()
f := newFuture[T]()
go func() {
defer recovery.Recovery(func(err error) {
err = errors.WrapKV(err, "fn", stack.CallerWithFunc(fn).String())
Expand All @@ -27,7 +27,7 @@ func Promise[T any](fn func(resolve func(T), reject func(err error))) *Future[T]
func Group[T any](do func(async func(func() (T, error))) error) *Iterator[T] {
assert.If(do == nil, "[Async] [fn] is nil")

var rr = iteratorOf[T]()
rr := iteratorOf[T]()
go func() {
var wg sync.WaitGroup
defer rr.setDone()
Expand All @@ -41,7 +41,7 @@ func Group[T any](do func(async func(func() (T, error))) error) *Iterator[T] {
rr.setErr(err)
})

var t, e = f()
t, e := f()
if e == nil {
rr.setValue(t)
} else {
Expand All @@ -55,7 +55,7 @@ func Group[T any](do func(async func(func() (T, error))) error) *Iterator[T] {
}

func Yield[T any](do func(yield func(T)) error) *Iterator[T] {
var dd = iteratorOf[T]()
dd := iteratorOf[T]()
go func() {
defer dd.setDone()
defer recovery.Recovery(func(err error) {
Expand Down
2 changes: 1 addition & 1 deletion build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func Run(BuildFlags, Packages string) error {
var pwd, err = os.Getwd()
pwd, err := os.Getwd()
if err != nil {
return err
}
Expand Down
8 changes: 5 additions & 3 deletions clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"github.com/huandu/go-clone"
)

type Func = clone.Func
type Allocator = clone.Allocator
type AllocatorMethods = clone.AllocatorMethods
type (
Func = clone.Func
Allocator = clone.Allocator
AllocatorMethods = clone.AllocatorMethods
)

func Clone[T any](t T) T {
return clone.Clone(t).(T)
Expand Down
2 changes: 1 addition & 1 deletion cmds/protoc-gen-go-enum/internal/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func GenerateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
g := gen.NewGeneratedFile(filename, file.GoImportPath)
g.Skip()

var genEnum = func(enum *protogen.Enum) {
genEnum := func(enum *protogen.Enum) {
genFile.
Func().Id(enum.GoIdent.GoName + "Values").
Params().
Expand Down
8 changes: 4 additions & 4 deletions cmds/protoc-gen-go-errors/internal/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func GenerateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
g.Unskip()

for _, codeName := range m.Values {
var name = strings.ToLower(fmt.Sprintf("%s.%s",
name := strings.ToLower(fmt.Sprintf("%s.%s",
file.Desc.Package(),
strcase.ToSnake(string(codeName.Desc.Name())),
))

var statusName = "OK"
statusName := "OK"
if tag.DefaultCode != 0 && int32(codeName.Desc.Number()) != 0 {
statusName = tag.DefaultCode.String()
}
Expand All @@ -61,7 +61,7 @@ func GenerateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
}

// comment
var rr = string(codeName.Desc.Name())
rr := string(codeName.Desc.Name())
if codeName.Comments.Leading.String() != "" {
rr = codeName.Comments.Leading.String()
rr = strings.Trim(strings.TrimSpace(rr), "/")
Expand All @@ -75,7 +75,7 @@ func GenerateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
rr = strings.ReplaceAll(rr, "_", " ")
rr = strings.TrimSpace(strings.ReplaceAll(rr, " ", " "))

var num = int32(codeName.Desc.Number())
num := int32(codeName.Desc.Number())
genFile.Var().
Id("ErrCode"+string(codeName.Desc.Name())).
Id("=").
Expand Down
2 changes: 1 addition & 1 deletion cmds/protoc-gen-go-sql/internal/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func GenerateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
return
}

//if val==nil{
// if val==nil{
// return nil
// }
g.Unskip()
Expand Down
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package config

import (
"log"
"os"
"path/filepath"

"github.com/a8m/envsubst"
"github.com/pubgo/funk/assert"
"github.com/pubgo/funk/pathutil"
"github.com/pubgo/funk/vars"
"gopkg.in/yaml.v3"
"log"
"os"
"path/filepath"
)

const (
Expand Down
8 changes: 5 additions & 3 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"gopkg.in/yaml.v3"
)

var _ yaml.Unmarshaler = (*Node)(nil)
var _ yaml.Marshaler = (*Node)(nil)
var _ json.Marshaler = (*Node)(nil)
var (
_ yaml.Unmarshaler = (*Node)(nil)
_ yaml.Marshaler = (*Node)(nil)
_ json.Marshaler = (*Node)(nil)
)

type Node struct {
maps map[string]any
Expand Down
8 changes: 4 additions & 4 deletions config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func getConfigPath(name, typ string, configDir ...string) (string, string) {
typ = defaultConfigType
}

var configName = fmt.Sprintf("%s.%s", name, typ)
configName := fmt.Sprintf("%s.%s", name, typ)
var notFoundPath []string
for _, path := range getPathList() {
for _, dir := range configDir {
var cfgPath = filepath.Join(path, dir, configName)
cfgPath := filepath.Join(path, dir, configName)
if pathutil.IsNotExist(cfgPath) {
notFoundPath = append(notFoundPath, cfgPath)
} else {
Expand Down Expand Up @@ -77,7 +77,7 @@ func MergeR[A any, B any | *any](dst *A, src ...B) (ret result.Result[*A]) {
return ret.WithVal(dst)
}

var err = Merge(dst, src...)
err := Merge(dst, src...)
if err != nil {
return ret.WithErr(err)
}
Expand Down Expand Up @@ -115,7 +115,7 @@ func (s *transformer) Transformer(t reflect.Type) func(dst, src reflect.Value) e
return nil
}

var dstMap = make(map[string]NamedConfig)
dstMap := make(map[string]NamedConfig)
for i := 0; i < dst.Len(); i++ {
c := dst.Index(i).Interface().(NamedConfig)
dstMap[c.ConfigUniqueName()] = c
Expand Down
2 changes: 1 addition & 1 deletion convert/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func ByteSize(bytes uint64) string {

// ToString Change arg to string
func ToString(arg any, timeFormat ...string) string {
var tmp = reflect.Indirect(reflect.ValueOf(arg)).Interface()
tmp := reflect.Indirect(reflect.ValueOf(arg)).Interface()
switch v := tmp.(type) {
case int:
return strconv.Itoa(v)
Expand Down
4 changes: 2 additions & 2 deletions convert/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
)

func TestMap(t *testing.T) {
var vv = Map(map[string]int{"a": 1, "b": 100}, func(s int) string { return fmt.Sprintf("%v", s) })
vv := Map(map[string]int{"a": 1, "b": 100}, func(s int) string { return fmt.Sprintf("%v", s) })
assert.Equal(t, vv, map[string]string{"a": "1", "b": "100"})
}

func TestMapL(t *testing.T) {
var vv = MapL([]int{1, 2, 3, 4}, func(s int) string { return fmt.Sprintf("%v", s*2) })
vv := MapL([]int{1, 2, 3, 4}, func(s int) string { return fmt.Sprintf("%v", s*2) })
assert.Equal(t, vv, []string{"2", "4", "6", "8"})
}
4 changes: 2 additions & 2 deletions cryptoutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func SecureKey() *[32]byte {

// SecureToken create a new random token
func SecureToken(lengths ...int) string {
var length = 16
length := 16
if len(lengths) > 0 {
length = lengths[0]
}
Expand Down Expand Up @@ -121,7 +121,7 @@ func Hmac(key, data string) string {
}

func HmacSha256(key, data string) string {
hash := hmac.New(sha256.New, []byte(key)) //创建对应的sha256哈希加密算法
hash := hmac.New(sha256.New, []byte(key)) // 创建对应的sha256哈希加密算法
hash.Write([]byte(data))
return hex.EncodeToString(hash.Sum([]byte("")))
}
Expand Down
9 changes: 4 additions & 5 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func GetWith(val *string, names ...string) {
}

func GetBoolVal(val *bool, names ...string) {
var dt = trim(Get(names...))
dt := trim(Get(names...))
if dt == "" {
return
}
Expand All @@ -60,7 +60,7 @@ func GetBoolVal(val *bool, names ...string) {
}

func GetIntVal(val *int, names ...string) {
var dt = trim(Get(names...))
dt := trim(Get(names...))
if dt == "" {
return
}
Expand All @@ -75,7 +75,7 @@ func GetIntVal(val *int, names ...string) {
}

func GetFloatVal(val *float64, names ...string) {
var dt = trim(Get(names...))
dt := trim(Get(names...))
if dt == "" {
return
}
Expand All @@ -98,12 +98,11 @@ func Delete(key string) error {
}

func Expand(value string) result.Result[string] {

return result.Of(envsubst.String(value))
}

func Map() map[string]string {
var data = make(map[string]string, len(os.Environ()))
data := make(map[string]string, len(os.Environ()))
for _, env := range os.Environ() {
envs := strings.SplitN(env, "=", 2)
data[envs[0]] = envs[1]
Expand Down
2 changes: 1 addition & 1 deletion env/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Normalize(env string) (k, v string, ok bool) {
}

envs := strings.SplitN(env, "=", 2)
var key = trim(envs[0])
key := trim(envs[0])
if len(envs) != 2 || key == "" || strings.HasPrefix(key, "_") {
return key, "", false
}
Expand Down
Loading

0 comments on commit 0be5ebc

Please sign in to comment.