Skip to content

Commit 0c2345f

Browse files
iamd3vilmr-karan
authored andcommitted
feat: Change any to interface{} to support Go 1.17.
1 parent ad4369d commit 0c2345f

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ name: build
33
on:
44
push:
55
branches:
6-
- 'main'
6+
- "main"
77
tags:
8-
- 'v*'
8+
- "v*"
99
pull_request:
1010

1111
jobs:
1212
build:
1313
strategy:
1414
matrix:
15-
go-version: [~1.18]
16-
os: [ ubuntu-latest, macos-latest, windows-latest ]
15+
go-version: [~1.17, ~1.18]
16+
os: [ubuntu-latest, macos-latest, windows-latest]
1717
runs-on: ${{ matrix.os }}
1818
steps:
1919
- uses: actions/checkout@v3
@@ -37,4 +37,4 @@ jobs:
3737
version: latest
3838
args: release --rm-dist
3939
env:
40-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

benchmark_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func BenchmarkOneField(b *testing.B) {
3131
}
3232

3333
func BenchmarkOneFieldWithDefaultFields(b *testing.B) {
34-
logger := logf.New(logf.Opts{Writer: io.Discard, DefaultFields: []any{"component", "logf"}})
34+
logger := logf.New(logf.Opts{Writer: io.Discard, DefaultFields: []interface{}{"component", "logf"}})
3535
b.ReportAllocs()
3636
b.ResetTimer()
3737
b.RunParallel(func(p *testing.PB) {

log.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Opts struct {
3232
CallerSkipFrameCount int
3333

3434
// These fields will be printed with every log.
35-
DefaultFields []any
35+
DefaultFields []interface{}
3636
}
3737

3838
// Logger is the interface for all log operations
@@ -158,35 +158,35 @@ func LevelFromString(lvl string) (Level, error) {
158158
}
159159

160160
// Debug emits a debug log line.
161-
func (l Logger) Debug(msg string, fields ...any) {
161+
func (l Logger) Debug(msg string, fields ...interface{}) {
162162
l.handleLog(msg, DebugLevel, fields...)
163163
}
164164

165165
// Info emits a info log line.
166-
func (l Logger) Info(msg string, fields ...any) {
166+
func (l Logger) Info(msg string, fields ...interface{}) {
167167
l.handleLog(msg, InfoLevel, fields...)
168168
}
169169

170170
// Warn emits a warning log line.
171-
func (l Logger) Warn(msg string, fields ...any) {
171+
func (l Logger) Warn(msg string, fields ...interface{}) {
172172
l.handleLog(msg, WarnLevel, fields...)
173173
}
174174

175175
// Error emits an error log line.
176-
func (l Logger) Error(msg string, fields ...any) {
176+
func (l Logger) Error(msg string, fields ...interface{}) {
177177
l.handleLog(msg, ErrorLevel, fields...)
178178
}
179179

180180
// Fatal emits a fatal level log line.
181181
// It aborts the current program with an exit code of 1.
182-
func (l Logger) Fatal(msg string, fields ...any) {
182+
func (l Logger) Fatal(msg string, fields ...interface{}) {
183183
l.handleLog(msg, FatalLevel, fields...)
184184
exit()
185185
}
186186

187187
// handleLog emits the log after filtering log level
188188
// and applying formatting of the fields.
189-
func (l Logger) handleLog(msg string, lvl Level, fields ...any) {
189+
func (l Logger) handleLog(msg string, lvl Level, fields ...interface{}) {
190190
// Discard the log if the verbosity is higher.
191191
// For eg, if the lvl is `3` (error), but the incoming message is `0` (debug), skip it.
192192
if lvl < l.Opts.Level {
@@ -210,7 +210,7 @@ func (l Logger) handleLog(msg string, lvl Level, fields ...any) {
210210
count int // to find out if this is the last key in while itering fields.
211211
fieldCount = len(l.DefaultFields) + len(fields)
212212
key string
213-
val any
213+
val interface{}
214214
)
215215

216216
// If there are odd number of fields, ignore the last.
@@ -310,7 +310,7 @@ func writeCallerToBuf(buf *byteBuffer, key string, depth int, lvl Level, color,
310310
}
311311

312312
// writeToBuf takes key, value and additional options to write to the buffer in logfmt.
313-
func writeToBuf(buf *byteBuffer, key string, val any, lvl Level, color, space bool) {
313+
func writeToBuf(buf *byteBuffer, key string, val interface{}, lvl Level, color, space bool) {
314314
if color {
315315
escapeAndWriteString(buf, getColoredKey(key, lvl))
316316
} else {
@@ -354,7 +354,7 @@ func writeToBuf(buf *byteBuffer, key string, val any, lvl Level, color, space bo
354354
}
355355
}
356356

357-
// escapeAndWriteString escapes the string if any unwanted chars are there.
357+
// escapeAndWriteString escapes the string if interface{} unwanted chars are there.
358358
func escapeAndWriteString(buf *byteBuffer, s string) {
359359
idx := strings.IndexFunc(s, checkEscapingRune)
360360
if idx != -1 || s == "null" {

log_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func TestLoggerTypes(t *testing.T) {
156156

157157
func TestLogFormatWithDefaultFields(t *testing.T) {
158158
buf := &bytes.Buffer{}
159-
l := New(Opts{Writer: buf, DefaultFields: []any{"defaultkey", "defaultvalue"}})
159+
l := New(Opts{Writer: buf, DefaultFields: []interface{}{"defaultkey", "defaultvalue"}})
160160

161161
l.Info("hello world")
162162
require.Contains(t, buf.String(), `level=info message="hello world" defaultkey=defaultvalue`)
@@ -237,7 +237,7 @@ func TestOddNumberedFields(t *testing.T) {
237237

238238
func TestOddNumberedFieldsWithDefaultFields(t *testing.T) {
239239
buf := &bytes.Buffer{}
240-
l := New(Opts{Writer: buf, DefaultFields: []any{
240+
l := New(Opts{Writer: buf, DefaultFields: []interface{}{
241241
"defaultkey", "defaultval",
242242
}})
243243

0 commit comments

Comments
 (0)