mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 17:34:11 -05:00
792b4dba2c
* update github.com/blevesearch/bleve v2.0.2 -> v2.0.3 * github.com/denisenkom/go-mssqldb v0.9.0 -> v0.10.0 * github.com/editorconfig/editorconfig-core-go v2.4.1 -> v2.4.2 * github.com/go-chi/cors v1.1.1 -> v1.2.0 * github.com/go-git/go-billy v5.0.0 -> v5.1.0 * github.com/go-git/go-git v5.2.0 -> v5.3.0 * github.com/go-ldap/ldap v3.2.4 -> v3.3.0 * github.com/go-redis/redis v8.6.0 -> v8.8.2 * github.com/go-sql-driver/mysql v1.5.0 -> v1.6.0 * github.com/go-swagger/go-swagger v0.26.1 -> v0.27.0 * github.com/lib/pq v1.9.0 -> v1.10.1 * github.com/mattn/go-sqlite3 v1.14.6 -> v1.14.7 * github.com/go-testfixtures/testfixtures v3.5.0 -> v3.6.0 * github.com/issue9/identicon v1.0.1 -> v1.2.0 * github.com/klauspost/compress v1.11.8 -> v1.12.1 * github.com/mgechev/revive v1.0.3 -> v1.0.6 * github.com/microcosm-cc/bluemonday v1.0.7 -> v1.0.8 * github.com/niklasfasching/go-org v1.4.0 -> v1.5.0 * github.com/olivere/elastic v7.0.22 -> v7.0.24 * github.com/pelletier/go-toml v1.8.1 -> v1.9.0 * github.com/prometheus/client_golang v1.9.0 -> v1.10.0 * github.com/xanzy/go-gitlab v0.44.0 -> v0.48.0 * github.com/yuin/goldmark v1.3.3 -> v1.3.5 * github.com/6543/go-version v1.2.4 -> v1.3.1 * do github.com/lib/pq v1.10.0 -> v1.10.1 again ...
108 lines
3 KiB
Go
Vendored
108 lines
3 KiB
Go
Vendored
// Copyright The OpenTelemetry Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package attribute // import "go.opentelemetry.io/otel/attribute"
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"reflect"
|
|
)
|
|
|
|
// KeyValue holds a key and value pair.
|
|
type KeyValue struct {
|
|
Key Key
|
|
Value Value
|
|
}
|
|
|
|
// Valid returns if kv is a valid OpenTelemetry attribute.
|
|
func (kv KeyValue) Valid() bool {
|
|
return kv.Key != "" && kv.Value.Type() != INVALID
|
|
}
|
|
|
|
// Bool creates a new key-value pair with a passed name and a bool
|
|
// value.
|
|
func Bool(k string, v bool) KeyValue {
|
|
return Key(k).Bool(v)
|
|
}
|
|
|
|
// Int64 creates a new key-value pair with a passed name and an int64
|
|
// value.
|
|
func Int64(k string, v int64) KeyValue {
|
|
return Key(k).Int64(v)
|
|
}
|
|
|
|
// Float64 creates a new key-value pair with a passed name and a float64
|
|
// value.
|
|
func Float64(k string, v float64) KeyValue {
|
|
return Key(k).Float64(v)
|
|
}
|
|
|
|
// String creates a new key-value pair with a passed name and a string
|
|
// value.
|
|
func String(k, v string) KeyValue {
|
|
return Key(k).String(v)
|
|
}
|
|
|
|
// Stringer creates a new key-value pair with a passed name and a string
|
|
// value generated by the passed Stringer interface.
|
|
func Stringer(k string, v fmt.Stringer) KeyValue {
|
|
return Key(k).String(v.String())
|
|
}
|
|
|
|
// Int creates a new key-value pair instance with a passed name and
|
|
// either an int32 or an int64 value, depending on whether the int
|
|
// type is 32 or 64 bits wide.
|
|
func Int(k string, v int) KeyValue {
|
|
return Key(k).Int(v)
|
|
}
|
|
|
|
// Array creates a new key-value pair with a passed name and a array.
|
|
// Only arrays of primitive type are supported.
|
|
func Array(k string, v interface{}) KeyValue {
|
|
return Key(k).Array(v)
|
|
}
|
|
|
|
// Any creates a new key-value pair instance with a passed name and
|
|
// automatic type inference. This is slower, and not type-safe.
|
|
func Any(k string, value interface{}) KeyValue {
|
|
if value == nil {
|
|
return String(k, "<nil>")
|
|
}
|
|
|
|
if stringer, ok := value.(fmt.Stringer); ok {
|
|
return String(k, stringer.String())
|
|
}
|
|
|
|
rv := reflect.ValueOf(value)
|
|
|
|
switch rv.Kind() {
|
|
case reflect.Array, reflect.Slice:
|
|
return Array(k, value)
|
|
case reflect.Bool:
|
|
return Bool(k, rv.Bool())
|
|
case reflect.Int, reflect.Int8, reflect.Int16:
|
|
return Int(k, int(rv.Int()))
|
|
case reflect.Int64:
|
|
return Int64(k, rv.Int())
|
|
case reflect.Float64:
|
|
return Float64(k, rv.Float())
|
|
case reflect.String:
|
|
return String(k, rv.String())
|
|
}
|
|
if b, err := json.Marshal(value); b != nil && err == nil {
|
|
return String(k, string(b))
|
|
}
|
|
return String(k, fmt.Sprint(value))
|
|
}
|