Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
5e05089
chore: set version from build info main version
kooksee Sep 7, 2025
3b2b861
feat: add embedded version string and getter
kooksee Sep 7, 2025
e947b5d
refactor(log): improve logger copying and deprecate WithEvent
kooksee Sep 7, 2025
7c0a437
fix: barry quick fix, 2025-09-08 01:09:57
kooksee Sep 7, 2025
54bd373
fix: barry quick fix, 2025-09-12 23:58:36
kooksee Sep 12, 2025
ebc6fb5
refactor(vars): replace expvar with atomic types and fix Result logic
kooksee Sep 13, 2025
a9805a0
fix: barry quick fix, 2025-09-13 09:54:55
kooksee Sep 13, 2025
7726faf
refactor: remove deprecated Result function
kooksee Sep 13, 2025
0a8a1b6
chore: quick update fix/version at 2025-09-15 23:52:18
kooksee Sep 13, 2025
5030e67
chore: quick update fix/version at 2025-09-16 18:31:37
kooksee Sep 13, 2025
b606183
fix: barry quick fix, 2025-09-16 20:42:29
kooksee Sep 16, 2025
82d51f9
fix: barry quick fix, 2025-09-16 20:51:06
kooksee Sep 16, 2025
4aee6c0
chore: quick update fix/version at 2025-09-16 22:00:15
kooksee Sep 16, 2025
5921f06
chore: quick update fix/version at 2025-09-17 17:07:01
kooksee Sep 16, 2025
7c14e8e
Merge branch 'fix/version' of github.com:pubgo/funk into fix/version
kooksee Sep 17, 2025
4781f16
chore: quick update fix/version at 2025-09-17 22:36:02
kooksee Sep 17, 2025
42e184c
chore: quick update fix/version at 2025-09-18 14:28:25
kooksee Sep 17, 2025
bc28ade
Merge branch 'fix/version' of github.com:pubgo/funk into fix/version
kooksee Sep 18, 2025
60706fd
chore: quick update fix/version at 2025-09-19 20:56:03
kooksee Sep 18, 2025
47c1cd2
chore: quick update fix/version at 2025-09-22 11:25:30
kooksee Sep 18, 2025
5f3032e
chore: quick update fix/version at 2025-09-22 11:32:08
kooksee Sep 22, 2025
db141c1
chore: quick update fix/version at 2025-09-23 13:34:47
kooksee Sep 22, 2025
34a5ee7
Merge branch 'fix/version' of github.com:pubgo/funk into fix/version
kooksee Sep 23, 2025
83b32e5
chore: quick update fix/version at 2025-09-23 23:13:48
kooksee Sep 23, 2025
51ec515
chore: quick update fix/version at 2025-09-24 11:45:48
kooksee Sep 23, 2025
c9256fc
Merge branch 'fix/version' of github.com:pubgo/funk into fix/version
kooksee Sep 24, 2025
7571a94
chore: quick update fix/version at 2025-09-24 23:16:29
kooksee Sep 24, 2025
2d5aebe
refactor(log): improve slog level conversion and error handling
kooksee Sep 25, 2025
0fbd459
chore: add merge package placeholder
kooksee Sep 25, 2025
dcc97b1
chore: quick update fix/version at 2025-09-26 15:25:41
kooksee Sep 26, 2025
403889a
refactor: replace Unwrap with Must in config merge calls
kooksee Sep 26, 2025
3e5f4c7
fix: encode error stack as base64 and improve error formatting
kooksee Sep 26, 2025
e41d241
chore: quick update fix/version at 2025-09-26 22:09:29
kooksee Sep 26, 2025
a87a3f9
refactor(assert): improve error logging with stack traces
kooksee Sep 26, 2025
3637372
refactor(result): improve error logging with stack traces
kooksee Sep 26, 2025
75c337f
chore: quick update fix/version at 2025-09-27 19:04:57
kooksee Sep 27, 2025
13870f2
chore(deps): update urfave/cli/v3 to v3.4.1
kooksee Sep 27, 2025
f18214a
chore: quick update fix/version at 2025-09-30 10:01:37
kooksee Sep 26, 2025
2c51cd9
chore: quick update fix/version at 2025-09-30 10:57:58
kooksee Sep 30, 2025
bb06e00
chore: quick update fix/version at 2025-10-08 20:59:34
kooksee Oct 8, 2025
d597c4b
Merge branch 'fix/version' of github.com:pubgo/funk into fix/version
kooksee Oct 8, 2025
5003f5d
chore: quick update fix/version at 2025-10-08 23:20:37
kooksee Oct 8, 2025
d138a1d
chore: quick update fix/version at 2025-10-09 17:55:38
kooksee Oct 8, 2025
5179d86
Merge branch 'fix/version' of github.com:pubgo/funk into fix/version
kooksee Oct 9, 2025
ad63fdd
chore: quick update fix/version at 2025-10-10 20:01:46
kooksee Oct 9, 2025
f278a42
chore: quick update fix/version at 2025-10-11 15:42:00
kooksee Oct 9, 2025
7de4d1a
chore: quick update fix/version at 2025-10-11 15:43:03
kooksee Oct 11, 2025
88b2ba8
chore: quick update fix/version at 2025-10-12 21:20:47
kooksee Oct 11, 2025
4870c3a
Merge branch 'fix/version' of github.com:pubgo/funk into fix/version
kooksee Oct 13, 2025
9c12448
chore: quick update fix/version at 2025-10-15 20:48:23
kooksee Oct 13, 2025
ea17e19
chore: quick update fix/version at 2025-10-17 10:27:45
kooksee Oct 13, 2025
4b2de87
refactor: reorganize buildinfo and update dependencies
kooksee Oct 17, 2025
580ab5d
chore: quick update fix/version at 2025-10-18 20:49:51
kooksee Oct 17, 2025
7557d0d
chore: quick update fix/version at 2025-10-22 09:56:19
kooksee Oct 17, 2025
0b9dfec
Merge branch 'fix/version' of github.com:pubgo/funk into fix/version
kooksee Oct 22, 2025
3d0d368
chore: quick update fix/version at 2025-10-22 18:36:17
kooksee Oct 22, 2025
f4b8776
chore: quick update fix/version at 2025-10-22 20:26:40
kooksee Oct 22, 2025
f8010d8
chore: quick update fix/version at 2025-10-28 18:10:30
kooksee Oct 27, 2025
97e7f35
chore: quick update fix/version at 2025-10-28 19:48:04
kooksee Oct 27, 2025
b6733a9
Merge branch 'fix/version' of github.com:pubgo/funk into fix/version
kooksee Oct 29, 2025
43d3de9
chore: quick update fix/version at 2025-10-29 21:10:38
kooksee Oct 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[url "[email protected]:"]
insteadOf = https://github.com/
53 changes: 53 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: "2"
issues:
fix: true
linters:
default: none
enable:
- govet
exclusions:
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- internal/example
- cmds
- vendor
- third_party$
- builtin$
- examples$
formatters:
enable:
- goimports
- gofmt
- gofumpt
settings:
gofumpt:
extra-rules: true
goimports:
# A list of prefixes, which, if set, checks import paths
# with the given prefixes are grouped after 3rd-party packages.
# Default: []
local-prefixes:
- github.com/pubgo/funk/v2
gofmt:
# Simplify code: gofmt with `-s` option.
# Default: true
simplify: false
# Apply the rewrite rules to the source before reformatting.
# https://pkg.go.dev/cmd/gofmt
# Default: []
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'

exclusions:
paths:
- internal/example
- vendor
- examples$
- proto
29 changes: 0 additions & 29 deletions .golangci.yml

This file was deleted.

1 change: 1 addition & 0 deletions .version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v2.0.0
7 changes: 7 additions & 0 deletions assert/aaa.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package assert

import "github.com/pubgo/funk/v2/features"

const Name = "assert"

var FeatureDebugMode = features.Bool("assert.debug_mode", false, "debug mode, pretty stack and error")
19 changes: 14 additions & 5 deletions assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@ package assert

import (
"fmt"
)

var EnablePrintStack bool
"github.com/google/go-cmp/cmp"
"github.com/k0kubun/pp/v3"
)

func Assert(b bool, format string, a ...interface{}) {
func Assert(b bool, format string, a ...any) {
if b {
must(fmt.Errorf(format, a...))
}
}

func If(b bool, format string, a ...interface{}) {
func MustEqual[T any](a, b T) {
if !cmp.Equal(a, b) {
pp.Println("a: ", a)
pp.Println("b: ", b)
must(fmt.Errorf("a,b not equal"))
Comment on lines +18 to +20

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error message "a,b not equal" is not very descriptive. When an equality check fails, it's very helpful for debugging to see the difference between the two values. The cmp.Diff function is great for this. Also, the pp.Println calls print to standard output, but their output is not part of the error that gets logged or panicked. Including the diff in the error message would make debugging much easier.

Suggested change
pp.Println("a: ", a)
pp.Println("b: ", b)
must(fmt.Errorf("a,b not equal"))
must(fmt.Errorf("a,b not equal (-a +b):\n%s", cmp.Diff(a, b)))

}
}

func If(b bool, format string, a ...any) {
if b {
must(fmt.Errorf(format, a...))
}
}

func T(b bool, format string, a ...interface{}) {
func T(b bool, format string, a ...any) {
if b {
must(fmt.Errorf(format, a...))
}
Expand Down
8 changes: 2 additions & 6 deletions assert/assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ package assert_test
import (
"testing"

"github.com/pubgo/funk/assert"
"github.com/pubgo/funk/recovery"
"github.com/pubgo/funk/v2/assert"
"github.com/pubgo/funk/v2/recovery"
)

func init() {
assert.EnablePrintStack = true
}

func TestCheckNil(t *testing.T) {
var a *int

Expand Down
24 changes: 12 additions & 12 deletions assert/must.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"runtime/debug"
)

func Must(err error, args ...interface{}) {
func Must(err error, args ...any) {
if err == nil {
return
}

must(err, args...)
}

func MustFn(errFn func() error, args ...interface{}) {
func MustFn(errFn func() error, args ...any) {
err := try(errFn)
if err == nil {
return
Expand All @@ -24,56 +24,56 @@ func MustFn(errFn func() error, args ...interface{}) {
must(err, args...)
}

func MustF(err error, msg string, args ...interface{}) {
func MustF(err error, msg string, args ...any) {
if err == nil {
return
}

must(err, fmt.Sprintf(msg, args...))
}

func Must1[T any](ret T, err error, args ...any) T {
func Must1[T any](ret T, err error) T {
if err != nil {
must(err, args...)
must(err)
}

return ret
}

func Exit(err error, args ...interface{}) {
func Exit(err error, args ...any) {
if err == nil {
return
}

slog.Error("os exit with error", "err", err, "msg", fmt.Sprint(args...))
logErr(err, "os exit with error", slog.String("log-msg", fmt.Sprint(args...)))
debug.PrintStack()
os.Exit(1)
}

func ExitFn(errFn func() error, args ...interface{}) {
func ExitFn(errFn func() error, args ...any) {
err := try(errFn)
if err == nil {
return
}

slog.Error("os exit with error func", "err", err, "msg", fmt.Sprint(args...))
logErr(err, "os exit with error func", slog.String("log-msg", fmt.Sprint(args...)))
debug.PrintStack()
os.Exit(1)
}

func ExitF(err error, msg string, args ...interface{}) {
func ExitF(err error, msg string, args ...any) {
if err == nil {
return
}

slog.Error("os exit with error format", "err", err, "msg", fmt.Sprintf(msg, args...))
logErr(err, "os exit with error format", slog.String("log-msg", fmt.Sprintf(msg, args...)))
debug.PrintStack()
os.Exit(1)
}

func Exit1[T any](ret T, err error) T {
if err != nil {
slog.Error("os exit with error unwrap", "err", err)
logErr(err, "os exit with error unwrap")
debug.PrintStack()
os.Exit(1)
}
Expand Down
18 changes: 15 additions & 3 deletions assert/must_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ package assert_test

import (
"fmt"
"log/slog"
"testing"

assert1 "github.com/pubgo/funk/assert"
"github.com/pubgo/funk/errors"
"github.com/stretchr/testify/assert"

assert1 "github.com/pubgo/funk/v2/assert"
"github.com/pubgo/funk/v2/errors"
"github.com/pubgo/funk/v2/log"
)

func init() {
slog.SetDefault(slog.New(log.NewSlog(log.GetLogger(assert1.Name))))
}

type errBase struct {
msg string
}
Expand Down Expand Up @@ -50,11 +57,16 @@ func init1Next() (err error) {
return nil
}

func TestDebugMode(t *testing.T) {
assert1.Exit(assert1.FeatureDebugMode.Set("true"))
assert1.Must(fmt.Errorf("test next"))
}

func BenchmarkNoPanic(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = func() (err error) {
assert1.Must(nil)
return
return err
}()
}
}
Expand Down
Loading
Loading