This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalue.go
109 lines (91 loc) · 3 KB
/
value.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// 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.
//go:build go1.21
package slog
import (
"log/slog"
"time"
)
// A Value can represent any Go value, but unlike type any,
// it can represent most small values without an allocation.
// The zero Value corresponds to nil.
type Value = slog.Value
// Kind is the kind of a Value.
type Kind = slog.Kind
// The following list is sorted alphabetically, but it's also important that
// KindAny is 0 so that a zero Value represents nil.
const (
KindAny = slog.KindAny
KindBool = slog.KindBool
KindDuration = slog.KindDuration
KindFloat64 = slog.KindFloat64
KindInt64 = slog.KindInt64
KindString = slog.KindString
KindTime = slog.KindTime
KindUint64 = slog.KindUint64
KindGroup = slog.KindGroup
KindLogValuer = slog.KindLogValuer
)
//////////////// Constructors
// StringValue returns a new Value for a string.
func StringValue(value string) Value {
return slog.StringValue(value)
}
// IntValue returns a Value for an int.
func IntValue(v int) Value {
return slog.IntValue(v)
}
// Int64Value returns a Value for an int64.
func Int64Value(v int64) Value {
return slog.Int64Value(v)
}
// Uint64Value returns a Value for a uint64.
func Uint64Value(v uint64) Value {
return slog.Uint64Value(v)
}
// Float64Value returns a Value for a floating-point number.
func Float64Value(v float64) Value {
return slog.Float64Value(v)
}
// BoolValue returns a Value for a bool.
func BoolValue(v bool) Value {
return slog.BoolValue(v)
}
// TimeValue returns a Value for a time.Time.
// It discards the monotonic portion.
func TimeValue(v time.Time) Value {
return slog.TimeValue(v)
}
// DurationValue returns a Value for a time.Duration.
func DurationValue(v time.Duration) Value {
return slog.DurationValue(v)
}
// GroupValue returns a new Value for a list of Attrs.
// The caller must not subsequently mutate the argument slice.
func GroupValue(as ...Attr) Value {
return slog.GroupValue(as...)
}
// AnyValue returns a Value for the supplied value.
//
// If the supplied value is of type Value, it is returned
// unmodified.
//
// Given a value of one of Go's predeclared string, bool, or
// (non-complex) numeric types, AnyValue returns a Value of kind
// String, Bool, Uint64, Int64, or Float64. The width of the
// original numeric type is not preserved.
//
// Given a time.Time or time.Duration value, AnyValue returns a Value of kind
// KindTime or KindDuration. The monotonic time is not preserved.
//
// For nil, or values of all other types, including named types whose
// underlying type is numeric, AnyValue returns a value of kind KindAny.
func AnyValue(v any) Value {
return slog.AnyValue(v)
}
// A LogValuer is any Go value that can convert itself into a Value for logging.
//
// This mechanism may be used to defer expensive operations until they are
// needed, or to expand a single value into a sequence of components.
type LogValuer = slog.LogValuer