Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump go versions to 1.18+ #203

Merged
merged 2 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/apidiff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version: 1.18.x
go-version: 1.20.x
- name: Add GOBIN to PATH
run: echo "PATH=$(go env GOPATH)/bin:$PATH" >>$GITHUB_ENV
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
test:
strategy:
matrix:
version: [ '1.15', '1.16', '1.17', '1.18' ]
version: [ '1.18', '1.19', '1.20', '1.21.0-rc.4' ]
platform: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func doErrorValue(b *testing.B, log logr.Logger) {

type Tmarshaler struct{ s string }

func (t Tmarshaler) MarshalLog() interface{} {
func (t Tmarshaler) MarshalLog() any {
return t.s
}

Expand Down
2 changes: 1 addition & 1 deletion example_marshaler_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ComplexObjectRef struct {
Secret string
}

func (ref ComplexObjectRef) MarshalLog() interface{} {
func (ref ComplexObjectRef) MarshalLog() any {
return struct {
Name, Namespace string
}{
Expand Down
2 changes: 1 addition & 1 deletion example_marshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (ref ObjectRef) String() string {
return ref.Name
}

func (ref ObjectRef) MarshalLog() interface{} {
func (ref ObjectRef) MarshalLog() any {
// We implement fmt.Stringer for non-structured logging, but we want the
// raw struct when using structured logs. Some logr implementations call
// String if it is present, so we want to convert this struct to something
Expand Down
10 changes: 5 additions & 5 deletions examples/tab_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// It's terribly inefficient, and is only a basic example.
type tabLogSink struct {
name string
keyValues map[string]interface{}
keyValues map[string]any
writer *tabwriter.Writer
}

Expand All @@ -43,7 +43,7 @@ func (_ tabLogSink) Enabled(level int) bool {
return true
}

func (l tabLogSink) Info(level int, msg string, kvs ...interface{}) {
func (l tabLogSink) Info(level int, msg string, kvs ...any) {
fmt.Fprintf(l.writer, "%s\t%s\t", l.name, msg)
for k, v := range l.keyValues {
fmt.Fprintf(l.writer, "%s: %+v ", k, v)
Expand All @@ -55,7 +55,7 @@ func (l tabLogSink) Info(level int, msg string, kvs ...interface{}) {
l.writer.Flush()
}

func (l tabLogSink) Error(err error, msg string, kvs ...interface{}) {
func (l tabLogSink) Error(err error, msg string, kvs ...any) {
kvs = append(kvs, "error", err)
l.Info(0, msg, kvs...)
}
Expand All @@ -68,8 +68,8 @@ func (l tabLogSink) WithName(name string) logr.LogSink {
}
}

func (l tabLogSink) WithValues(kvs ...interface{}) logr.LogSink {
newMap := make(map[string]interface{}, len(l.keyValues)+len(kvs)/2)
func (l tabLogSink) WithValues(kvs ...any) logr.LogSink {
newMap := make(map[string]any, len(l.keyValues)+len(kvs)/2)
for k, v := range l.keyValues {
newMap[k] = v
}
Expand Down
8 changes: 4 additions & 4 deletions examples/usage_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ import (
// (but a bit trickier) to use file-level "base" loggers.

var objectMap = map[string]Object{
"obj1": Object{
"obj1": {
Name: "obj1",
Kind: "one",
Details: 33,
},
"obj2": Object{
"obj2": {
Name: "obj2",
Kind: "two",
Details: "hi",
},
"obj3": Object{
"obj3": {
Name: "obj3",
Kind: "one",
Details: 1,
Expand All @@ -54,7 +54,7 @@ var objectMap = map[string]Object{
type Object struct {
Name string
Kind string
Details interface{}
Details any
}

type Client struct {
Expand Down
6 changes: 3 additions & 3 deletions funcr/example_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (l stdoutlogger) WithName(name string) logr.LogSink {
return &l
}

func (l stdoutlogger) WithValues(kvList ...interface{}) logr.LogSink {
func (l stdoutlogger) WithValues(kvList ...any) logr.LogSink {
l.Formatter.AddValues(kvList)
return &l
}
Expand All @@ -55,12 +55,12 @@ func (l stdoutlogger) WithCallDepth(depth int) logr.LogSink {
return &l
}

func (l stdoutlogger) Info(level int, msg string, kvList ...interface{}) {
func (l stdoutlogger) Info(level int, msg string, kvList ...any) {
prefix, args := l.FormatInfo(level, msg, kvList)
l.write("INFO", prefix, args)
}

func (l stdoutlogger) Error(err error, msg string, kvList ...interface{}) {
func (l stdoutlogger) Error(err error, msg string, kvList ...any) {
prefix, args := l.FormatError(err, msg, kvList)
l.write("ERROR", prefix, args)
}
Expand Down
8 changes: 4 additions & 4 deletions funcr/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func ExampleOptions() {

func ExampleOptions_renderHooks() {
// prefix all builtin keys with "log:"
prefixSpecialKeys := func(kvList []interface{}) []interface{} {
prefixSpecialKeys := func(kvList []any) []any {
for i := 0; i < len(kvList); i += 2 {
k, _ := kvList[i].(string)
kvList[i] = "log:" + k
Expand All @@ -83,8 +83,8 @@ func ExampleOptions_renderHooks() {
}

// present saved values as a single JSON object
valuesAsObject := func(kvList []interface{}) []interface{} {
return []interface{}{"labels", funcr.PseudoStruct(kvList)}
valuesAsObject := func(kvList []any) []any {
return []any{"labels", funcr.PseudoStruct(kvList)}
}

var log logr.Logger = funcr.NewJSON(
Expand All @@ -104,7 +104,7 @@ func ExamplePseudoStruct() {
var log logr.Logger = funcr.NewJSON(
func(obj string) { fmt.Println(obj) },
funcr.Options{})
kv := []interface{}{
kv := []any{
"field1", 12345,
"field2", true,
}
Expand Down
44 changes: 22 additions & 22 deletions funcr/funcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ type Options struct {
// Equivalent hooks are offered for key-value pairs saved via
// logr.Logger.WithValues or Formatter.AddValues (see RenderValuesHook) and
// for user-provided pairs (see RenderArgsHook).
RenderBuiltinsHook func(kvList []interface{}) []interface{}
RenderBuiltinsHook func(kvList []any) []any

// RenderValuesHook is the same as RenderBuiltinsHook, except that it is
// only called for key-value pairs saved via logr.Logger.WithValues. See
// RenderBuiltinsHook for more details.
RenderValuesHook func(kvList []interface{}) []interface{}
RenderValuesHook func(kvList []any) []any

// RenderArgsHook is the same as RenderBuiltinsHook, except that it is only
// called for key-value pairs passed directly to Info and Error. See
// RenderBuiltinsHook for more details.
RenderArgsHook func(kvList []interface{}) []interface{}
RenderArgsHook func(kvList []any) []any

// MaxLogDepth tells funcr how many levels of nested fields (e.g. a struct
// that contains a struct, etc.) it may log. Every time it finds a struct,
Expand Down Expand Up @@ -163,7 +163,7 @@ func (l fnlogger) WithName(name string) logr.LogSink {
return &l
}

func (l fnlogger) WithValues(kvList ...interface{}) logr.LogSink {
func (l fnlogger) WithValues(kvList ...any) logr.LogSink {
l.Formatter.AddValues(kvList)
return &l
}
Expand All @@ -173,12 +173,12 @@ func (l fnlogger) WithCallDepth(depth int) logr.LogSink {
return &l
}

func (l fnlogger) Info(level int, msg string, kvList ...interface{}) {
func (l fnlogger) Info(level int, msg string, kvList ...any) {
prefix, args := l.FormatInfo(level, msg, kvList)
l.write(prefix, args)
}

func (l fnlogger) Error(err error, msg string, kvList ...interface{}) {
func (l fnlogger) Error(err error, msg string, kvList ...any) {
prefix, args := l.FormatError(err, msg, kvList)
l.write(prefix, args)
}
Expand Down Expand Up @@ -229,7 +229,7 @@ func newFormatter(opts Options, outfmt outputFormat) Formatter {
type Formatter struct {
outputFormat outputFormat
prefix string
values []interface{}
values []any
valuesStr string
depth int
opts *Options
Expand All @@ -246,10 +246,10 @@ const (
)

// PseudoStruct is a list of key-value pairs that gets logged as a struct.
type PseudoStruct []interface{}
type PseudoStruct []any

// render produces a log line, ready to use.
func (f Formatter) render(builtins, args []interface{}) string {
func (f Formatter) render(builtins, args []any) string {
// Empirically bytes.Buffer is faster than strings.Builder for this.
buf := bytes.NewBuffer(make([]byte, 0, 1024))
if f.outputFormat == outputJSON {
Expand Down Expand Up @@ -292,7 +292,7 @@ func (f Formatter) render(builtins, args []interface{}) string {
// This function returns a potentially modified version of kvList, which
// ensures that there is a value for every key (adding a value if needed) and
// that each key is a string (substituting a key if needed).
func (f Formatter) flatten(buf *bytes.Buffer, kvList []interface{}, continuing bool, escapeKeys bool) []interface{} {
func (f Formatter) flatten(buf *bytes.Buffer, kvList []any, continuing bool, escapeKeys bool) []any {
// This logic overlaps with sanitize() but saves one type-cast per key,
// which can be measurable.
if len(kvList)%2 != 0 {
Expand Down Expand Up @@ -334,7 +334,7 @@ func (f Formatter) flatten(buf *bytes.Buffer, kvList []interface{}, continuing b
return kvList
}

func (f Formatter) pretty(value interface{}) string {
func (f Formatter) pretty(value any) string {
return f.prettyWithFlags(value, 0, 0)
}

Expand All @@ -343,7 +343,7 @@ const (
)

// TODO: This is not fast. Most of the overhead goes here.
func (f Formatter) prettyWithFlags(value interface{}, flags uint32, depth int) string {
func (f Formatter) prettyWithFlags(value any, flags uint32, depth int) string {
if depth > f.opts.MaxLogDepth {
return `"<max-log-depth-exceeded>"`
}
Expand Down Expand Up @@ -614,7 +614,7 @@ func isEmpty(v reflect.Value) bool {
return false
}

func invokeMarshaler(m logr.Marshaler) (ret interface{}) {
func invokeMarshaler(m logr.Marshaler) (ret any) {
defer func() {
if r := recover(); r != nil {
ret = fmt.Sprintf("<panic: %s>", r)
Expand Down Expand Up @@ -675,12 +675,12 @@ func (f Formatter) caller() Caller {

const noValue = "<no-value>"

func (f Formatter) nonStringKey(v interface{}) string {
func (f Formatter) nonStringKey(v any) string {
return fmt.Sprintf("<non-string-key: %s>", f.snippet(v))
}

// snippet produces a short snippet string of an arbitrary value.
func (f Formatter) snippet(v interface{}) string {
func (f Formatter) snippet(v any) string {
const snipLen = 16

snip := f.pretty(v)
Expand All @@ -693,7 +693,7 @@ func (f Formatter) snippet(v interface{}) string {
// sanitize ensures that a list of key-value pairs has a value for every key
// (adding a value if needed) and that each key is a string (substituting a key
// if needed).
func (f Formatter) sanitize(kvList []interface{}) []interface{} {
func (f Formatter) sanitize(kvList []any) []any {
if len(kvList)%2 != 0 {
kvList = append(kvList, noValue)
}
Expand Down Expand Up @@ -727,8 +727,8 @@ func (f Formatter) GetDepth() int {
// FormatInfo renders an Info log message into strings. The prefix will be
// empty when no names were set (via AddNames), or when the output is
// configured for JSON.
func (f Formatter) FormatInfo(level int, msg string, kvList []interface{}) (prefix, argsStr string) {
args := make([]interface{}, 0, 64) // using a constant here impacts perf
func (f Formatter) FormatInfo(level int, msg string, kvList []any) (prefix, argsStr string) {
args := make([]any, 0, 64) // using a constant here impacts perf
prefix = f.prefix
if f.outputFormat == outputJSON {
args = append(args, "logger", prefix)
Expand All @@ -747,8 +747,8 @@ func (f Formatter) FormatInfo(level int, msg string, kvList []interface{}) (pref
// FormatError renders an Error log message into strings. The prefix will be
// empty when no names were set (via AddNames), or when the output is
// configured for JSON.
func (f Formatter) FormatError(err error, msg string, kvList []interface{}) (prefix, argsStr string) {
args := make([]interface{}, 0, 64) // using a constant here impacts perf
func (f Formatter) FormatError(err error, msg string, kvList []any) (prefix, argsStr string) {
args := make([]any, 0, 64) // using a constant here impacts perf
prefix = f.prefix
if f.outputFormat == outputJSON {
args = append(args, "logger", prefix)
Expand All @@ -761,7 +761,7 @@ func (f Formatter) FormatError(err error, msg string, kvList []interface{}) (pre
args = append(args, "caller", f.caller())
}
args = append(args, "msg", msg)
var loggableErr interface{}
var loggableErr any
if err != nil {
loggableErr = err.Error()
}
Expand All @@ -781,7 +781,7 @@ func (f *Formatter) AddName(name string) {

// AddValues adds key-value pairs to the set of saved values to be logged with
// each log line.
func (f *Formatter) AddValues(kvList []interface{}) {
func (f *Formatter) AddValues(kvList []any) {
// Three slice args forces a copy.
n := len(f.values)
f.values = append(f.values[:n:n], kvList...)
Expand Down