Skip to content

Commit bb97154

Browse files
committed
add base64 method
1 parent cd771f5 commit bb97154

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

logger_go1.22.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//go:build go1.22
2+
// +build go1.22
3+
4+
package log
5+
6+
import (
7+
"encoding/base64"
8+
)
9+
10+
// Base64 adds base64 encoding of the value to the entry.
11+
func (e *Entry) Base64(key string, value []byte) *Entry {
12+
if e == nil {
13+
return nil
14+
}
15+
16+
e.buf = append(e.buf, ',', '"')
17+
e.buf = append(e.buf, key...)
18+
e.buf = append(e.buf, '"', ':', '"')
19+
e.buf = base64.StdEncoding.AppendEncode(e.buf, value)
20+
e.buf = append(e.buf, '"')
21+
return e
22+
}
23+
24+
// Base64URL adds base64 encoding of the value to the entry.
25+
func (e *Entry) Base64URL(key string, value []byte) *Entry {
26+
if e == nil {
27+
return nil
28+
}
29+
30+
e.buf = append(e.buf, ',', '"')
31+
e.buf = append(e.buf, key...)
32+
e.buf = append(e.buf, '"', ':', '"')
33+
e.buf = base64.URLEncoding.AppendEncode(e.buf, value)
34+
e.buf = append(e.buf, '"')
35+
return e
36+
}

0 commit comments

Comments
 (0)