// Copyright 2022 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package slogimport ()// An Attr is a key-value pair.typeAttrstruct { Key string Value Value}// String returns an Attr for a string value.func (, string) Attr {returnAttr{, StringValue()}}// Int64 returns an Attr for an int64.func ( string, int64) Attr {returnAttr{, Int64Value()}}// Int converts an int to an int64 and returns// an Attr with that value.func ( string, int) Attr {returnInt64(, int64())}// Uint64 returns an Attr for a uint64.func ( string, uint64) Attr {returnAttr{, Uint64Value()}}// Float64 returns an Attr for a floating-point number.func ( string, float64) Attr {returnAttr{, Float64Value()}}// Bool returns an Attr for a bool.func ( string, bool) Attr {returnAttr{, BoolValue()}}// Time returns an Attr for a [time.Time].// It discards the monotonic portion.func ( string, time.Time) Attr {returnAttr{, TimeValue()}}// Duration returns an Attr for a [time.Duration].func ( string, time.Duration) Attr {returnAttr{, DurationValue()}}// Group returns an Attr for a Group [Value].// The first argument is the key; the remaining arguments// are converted to Attrs as in [Logger.Log].//// Use Group to collect several key-value pairs under a single// key on a log line, or as the result of LogValue// in order to log a single value as multiple Attrs.func ( string, ...any) Attr {returnAttr{, GroupValue(argsToAttrSlice()...)}}func argsToAttrSlice( []any) []Attr {var (Attr []Attr )forlen() > 0 { , = argsToAttr() = append(, ) }return}// Any returns an Attr for the supplied value.// See [AnyValue] for how values are treated.func ( string, any) Attr {returnAttr{, AnyValue()}}// Equal reports whether a and b have equal keys and values.func ( Attr) ( Attr) bool {return .Key == .Key && .Value.Equal(.Value)}func ( Attr) () string {return .Key + "=" + .Value.String()}// isEmpty reports whether a has an empty key and a nil value.// That can be written as Attr{} or Any("", nil).func ( Attr) () bool {return .Key == "" && .Value.num == 0 && .Value.any == nil}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.