Skip to content

Commit fb09cb8

Browse files
committed
chore: quick update feat/feature_ext at 2026-01-13 14:51:41
1 parent 5b60ff8 commit fb09cb8

6 files changed

Lines changed: 32 additions & 22 deletions

File tree

config/util.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,12 @@ func evalData(template []byte, cfg *config) []byte {
241241
}
242242

243243
tag = fmt.Sprintf("${%s}", tag)
244-
return w.Write(bytes.TrimSpace([]byte(result.Wrap(envsubst.String(tag)).
244+
return w.Write(result.Wrap(envsubst.Bytes([]byte(tag))).
245+
Map(bytes.TrimSpace).
245246
UnwrapOrLog(func(e result.Event) {
246247
e.Str("env", name)
247248
e.Msg("failed to process env subst")
248-
}))))
249+
}))
249250
}))
250251
}
251252

result/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func MapTo[T, U any](r Result[T], fn func(T) U) Result[U] {
140140
return OK(fn(r.getValue()))
141141
}
142142

143-
func FlatMapTo[T, U any](r Result[T], fn func(T) Result[U]) Result[U] {
143+
func MapValTo[T, U any](r Result[T], fn func(T) Result[U]) Result[U] {
144144
if r.IsErr() {
145145
return Fail[U](errors.WrapCaller(r.getErr(), 1))
146146
}

result/event.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package result
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/pubgo/funk/v2/log"
7+
"github.com/pubgo/funk/v2/log/logfields"
8+
)
9+
10+
type Event struct {
11+
*log.Event
12+
}
13+
14+
func (e Event) Msg(msg string) {
15+
e.Str(logfields.Msg, msg)
16+
}
17+
18+
func (e Event) MsgFunc(createMsg func() string) {
19+
e.Str(logfields.Msg, createMsg())
20+
}
21+
22+
func (e Event) Msgf(format string, v ...any) {
23+
e.Str(logfields.Msg, fmt.Sprintf(format, v...))
24+
}

result/result.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ func (r Result[T]) Map(fn func(val T) T) Result[T] {
300300
return OK(fn(r.getValue()))
301301
}
302302

303-
// FlatMap calls fn with the value if the result is OK, then returns the result unchanged.
304-
func (r Result[T]) FlatMap(fn func(val T) Result[T]) Result[T] {
303+
// MapVal calls fn with the value if the result is OK, then returns the result unchanged.
304+
func (r Result[T]) MapVal(fn func(val T) Result[T]) Result[T] {
305305
if r.IsErr() {
306306
return r
307307
}

result/result_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestMoreReasonableErrorHandling(t *testing.T) {
104104
})
105105

106106
// Apply a function that might fail
107-
finalResult := result.FlatMapTo(strResult, func(s string) result.Result[int] {
107+
finalResult := result.MapValTo(strResult, func(s string) result.Result[int] {
108108
if len(s) > 10 {
109109
return result.Fail[int](fmt.Errorf("string too long"))
110110
}
@@ -123,7 +123,7 @@ func TestMoreReasonableErrorHandling(t *testing.T) {
123123
errResult := result.Fail[string](fmt.Errorf("initial error"))
124124

125125
// Chain operations on an error result
126-
chainedResult := result.FlatMapTo(errResult, func(_ string) result.Result[int] {
126+
chainedResult := result.MapValTo(errResult, func(_ string) result.Result[int] {
127127
return result.OK(100)
128128
})
129129

result/util.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -378,18 +378,3 @@ func logErr(ctx context.Context, skip int, err error, events ...func(e Event)) {
378378
}).
379379
Msgf("%s\n%s", err.Error(), errors.JsonPrint(err))
380380
}
381-
382-
type Event struct {
383-
*log.Event
384-
}
385-
386-
func (e Event) Msg(msg string) {
387-
e.Str(logfields.Msg, msg)
388-
}
389-
func (e Event) MsgFunc(createMsg func() string) {
390-
e.Str(logfields.Msg, createMsg())
391-
}
392-
393-
func (e Event) Msgf(format string, v ...any) {
394-
e.Str(logfields.Msg, fmt.Sprintf(format, v...))
395-
}

0 commit comments

Comments
 (0)