mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
GCLOUD: go get -u google.golang.org/api
This commit is contained in:
191
vendor/github.com/golang/groupcache/LICENSE
generated
vendored
Normal file
191
vendor/github.com/golang/groupcache/LICENSE
generated
vendored
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction, and
|
||||||
|
distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
||||||
|
owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all other entities
|
||||||
|
that control, are controlled by, or are under common control with that entity.
|
||||||
|
For the purposes of this definition, "control" means (i) the power, direct or
|
||||||
|
indirect, to cause the direction or management of such entity, whether by
|
||||||
|
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
||||||
|
permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications, including
|
||||||
|
but not limited to software source code, documentation source, and configuration
|
||||||
|
files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical transformation or
|
||||||
|
translation of a Source form, including but not limited to compiled object code,
|
||||||
|
generated documentation, and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
||||||
|
available under the License, as indicated by a copyright notice that is included
|
||||||
|
in or attached to the work (an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
||||||
|
is based on (or derived from) the Work and for which the editorial revisions,
|
||||||
|
annotations, elaborations, or other modifications represent, as a whole, an
|
||||||
|
original work of authorship. For the purposes of this License, Derivative Works
|
||||||
|
shall not include works that remain separable from, or merely link (or bind by
|
||||||
|
name) to the interfaces of, the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including the original version
|
||||||
|
of the Work and any modifications or additions to that Work or Derivative Works
|
||||||
|
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
||||||
|
by the copyright owner or by an individual or Legal Entity authorized to submit
|
||||||
|
on behalf of the copyright owner. For the purposes of this definition,
|
||||||
|
"submitted" means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems, and
|
||||||
|
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
||||||
|
the purpose of discussing and improving the Work, but excluding communication
|
||||||
|
that is conspicuously marked or otherwise designated in writing by the copyright
|
||||||
|
owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
||||||
|
of whom a Contribution has been received by Licensor and subsequently
|
||||||
|
incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License.
|
||||||
|
|
||||||
|
Subject to the terms and conditions of this License, each Contributor hereby
|
||||||
|
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||||
|
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the Work and such
|
||||||
|
Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License.
|
||||||
|
|
||||||
|
Subject to the terms and conditions of this License, each Contributor hereby
|
||||||
|
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||||
|
irrevocable (except as stated in this section) patent license to make, have
|
||||||
|
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
||||||
|
such license applies only to those patent claims licensable by such Contributor
|
||||||
|
that are necessarily infringed by their Contribution(s) alone or by combination
|
||||||
|
of their Contribution(s) with the Work to which such Contribution(s) was
|
||||||
|
submitted. If You institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
||||||
|
Contribution incorporated within the Work constitutes direct or contributory
|
||||||
|
patent infringement, then any patent licenses granted to You under this License
|
||||||
|
for that Work shall terminate as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution.
|
||||||
|
|
||||||
|
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
||||||
|
in any medium, with or without modifications, and in Source or Object form,
|
||||||
|
provided that You meet the following conditions:
|
||||||
|
|
||||||
|
You must give any other recipients of the Work or Derivative Works a copy of
|
||||||
|
this License; and
|
||||||
|
You must cause any modified files to carry prominent notices stating that You
|
||||||
|
changed the files; and
|
||||||
|
You must retain, in the Source form of any Derivative Works that You distribute,
|
||||||
|
all copyright, patent, trademark, and attribution notices from the Source form
|
||||||
|
of the Work, excluding those notices that do not pertain to any part of the
|
||||||
|
Derivative Works; and
|
||||||
|
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
||||||
|
Derivative Works that You distribute must include a readable copy of the
|
||||||
|
attribution notices contained within such NOTICE file, excluding those notices
|
||||||
|
that do not pertain to any part of the Derivative Works, in at least one of the
|
||||||
|
following places: within a NOTICE text file distributed as part of the
|
||||||
|
Derivative Works; within the Source form or documentation, if provided along
|
||||||
|
with the Derivative Works; or, within a display generated by the Derivative
|
||||||
|
Works, if and wherever such third-party notices normally appear. The contents of
|
||||||
|
the NOTICE file are for informational purposes only and do not modify the
|
||||||
|
License. You may add Your own attribution notices within Derivative Works that
|
||||||
|
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
||||||
|
provided that such additional attribution notices cannot be construed as
|
||||||
|
modifying the License.
|
||||||
|
You may add Your own copyright statement to Your modifications and may provide
|
||||||
|
additional or different license terms and conditions for use, reproduction, or
|
||||||
|
distribution of Your modifications, or for any such Derivative Works as a whole,
|
||||||
|
provided Your use, reproduction, and distribution of the Work otherwise complies
|
||||||
|
with the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions.
|
||||||
|
|
||||||
|
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
||||||
|
for inclusion in the Work by You to the Licensor shall be under the terms and
|
||||||
|
conditions of this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
||||||
|
any separate license agreement you may have executed with Licensor regarding
|
||||||
|
such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks.
|
||||||
|
|
||||||
|
This License does not grant permission to use the trade names, trademarks,
|
||||||
|
service marks, or product names of the Licensor, except as required for
|
||||||
|
reasonable and customary use in describing the origin of the Work and
|
||||||
|
reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, Licensor provides the
|
||||||
|
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
||||||
|
including, without limitation, any warranties or conditions of TITLE,
|
||||||
|
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
||||||
|
solely responsible for determining the appropriateness of using or
|
||||||
|
redistributing the Work and assume any risks associated with Your exercise of
|
||||||
|
permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability.
|
||||||
|
|
||||||
|
In no event and under no legal theory, whether in tort (including negligence),
|
||||||
|
contract, or otherwise, unless required by applicable law (such as deliberate
|
||||||
|
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special, incidental,
|
||||||
|
or consequential damages of any character arising as a result of this License or
|
||||||
|
out of the use or inability to use the Work (including but not limited to
|
||||||
|
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
||||||
|
any and all other commercial damages or losses), even if such Contributor has
|
||||||
|
been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability.
|
||||||
|
|
||||||
|
While redistributing the Work or Derivative Works thereof, You may choose to
|
||||||
|
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
||||||
|
other liability obligations and/or rights consistent with this License. However,
|
||||||
|
in accepting such obligations, You may act only on Your own behalf and on Your
|
||||||
|
sole responsibility, not on behalf of any other Contributor, and only if You
|
||||||
|
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason of your
|
||||||
|
accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following boilerplate
|
||||||
|
notice, with the fields enclosed by brackets "[]" replaced with your own
|
||||||
|
identifying information. (Don't include the brackets!) The text should be
|
||||||
|
enclosed in the appropriate comment syntax for the file format. We also
|
||||||
|
recommend that a file or class name and description of purpose be included on
|
||||||
|
the same "printed page" as the copyright notice for easier identification within
|
||||||
|
third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
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.
|
133
vendor/github.com/golang/groupcache/lru/lru.go
generated
vendored
Normal file
133
vendor/github.com/golang/groupcache/lru/lru.go
generated
vendored
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2013 Google Inc.
|
||||||
|
|
||||||
|
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 lru implements an LRU cache.
|
||||||
|
package lru
|
||||||
|
|
||||||
|
import "container/list"
|
||||||
|
|
||||||
|
// Cache is an LRU cache. It is not safe for concurrent access.
|
||||||
|
type Cache struct {
|
||||||
|
// MaxEntries is the maximum number of cache entries before
|
||||||
|
// an item is evicted. Zero means no limit.
|
||||||
|
MaxEntries int
|
||||||
|
|
||||||
|
// OnEvicted optionally specifies a callback function to be
|
||||||
|
// executed when an entry is purged from the cache.
|
||||||
|
OnEvicted func(key Key, value interface{})
|
||||||
|
|
||||||
|
ll *list.List
|
||||||
|
cache map[interface{}]*list.Element
|
||||||
|
}
|
||||||
|
|
||||||
|
// A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators
|
||||||
|
type Key interface{}
|
||||||
|
|
||||||
|
type entry struct {
|
||||||
|
key Key
|
||||||
|
value interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates a new Cache.
|
||||||
|
// If maxEntries is zero, the cache has no limit and it's assumed
|
||||||
|
// that eviction is done by the caller.
|
||||||
|
func New(maxEntries int) *Cache {
|
||||||
|
return &Cache{
|
||||||
|
MaxEntries: maxEntries,
|
||||||
|
ll: list.New(),
|
||||||
|
cache: make(map[interface{}]*list.Element),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add adds a value to the cache.
|
||||||
|
func (c *Cache) Add(key Key, value interface{}) {
|
||||||
|
if c.cache == nil {
|
||||||
|
c.cache = make(map[interface{}]*list.Element)
|
||||||
|
c.ll = list.New()
|
||||||
|
}
|
||||||
|
if ee, ok := c.cache[key]; ok {
|
||||||
|
c.ll.MoveToFront(ee)
|
||||||
|
ee.Value.(*entry).value = value
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ele := c.ll.PushFront(&entry{key, value})
|
||||||
|
c.cache[key] = ele
|
||||||
|
if c.MaxEntries != 0 && c.ll.Len() > c.MaxEntries {
|
||||||
|
c.RemoveOldest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get looks up a key's value from the cache.
|
||||||
|
func (c *Cache) Get(key Key) (value interface{}, ok bool) {
|
||||||
|
if c.cache == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if ele, hit := c.cache[key]; hit {
|
||||||
|
c.ll.MoveToFront(ele)
|
||||||
|
return ele.Value.(*entry).value, true
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove removes the provided key from the cache.
|
||||||
|
func (c *Cache) Remove(key Key) {
|
||||||
|
if c.cache == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if ele, hit := c.cache[key]; hit {
|
||||||
|
c.removeElement(ele)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveOldest removes the oldest item from the cache.
|
||||||
|
func (c *Cache) RemoveOldest() {
|
||||||
|
if c.cache == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ele := c.ll.Back()
|
||||||
|
if ele != nil {
|
||||||
|
c.removeElement(ele)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Cache) removeElement(e *list.Element) {
|
||||||
|
c.ll.Remove(e)
|
||||||
|
kv := e.Value.(*entry)
|
||||||
|
delete(c.cache, kv.key)
|
||||||
|
if c.OnEvicted != nil {
|
||||||
|
c.OnEvicted(kv.key, kv.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Len returns the number of items in the cache.
|
||||||
|
func (c *Cache) Len() int {
|
||||||
|
if c.cache == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return c.ll.Len()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear purges all stored items from the cache.
|
||||||
|
func (c *Cache) Clear() {
|
||||||
|
if c.OnEvicted != nil {
|
||||||
|
for _, e := range c.cache {
|
||||||
|
kv := e.Value.(*entry)
|
||||||
|
c.OnEvicted(kv.key, kv.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.ll = nil
|
||||||
|
c.cache = nil
|
||||||
|
}
|
85
vendor/golang.org/x/tools/internal/event/core/event.go
generated
vendored
Normal file
85
vendor/golang.org/x/tools/internal/event/core/event.go
generated
vendored
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
// Copyright 2019 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 core provides support for event based telemetry.
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/tools/internal/event/label"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Event holds the information about an event of note that ocurred.
|
||||||
|
type Event struct {
|
||||||
|
at time.Time
|
||||||
|
|
||||||
|
// As events are often on the stack, storing the first few labels directly
|
||||||
|
// in the event can avoid an allocation at all for the very common cases of
|
||||||
|
// simple events.
|
||||||
|
// The length needs to be large enough to cope with the majority of events
|
||||||
|
// but no so large as to cause undue stack pressure.
|
||||||
|
// A log message with two values will use 3 labels (one for each value and
|
||||||
|
// one for the message itself).
|
||||||
|
|
||||||
|
static [3]label.Label // inline storage for the first few labels
|
||||||
|
dynamic []label.Label // dynamically sized storage for remaining labels
|
||||||
|
}
|
||||||
|
|
||||||
|
// eventLabelMap implements label.Map for a the labels of an Event.
|
||||||
|
type eventLabelMap struct {
|
||||||
|
event Event
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ev Event) At() time.Time { return ev.at }
|
||||||
|
|
||||||
|
func (ev Event) Format(f fmt.State, r rune) {
|
||||||
|
if !ev.at.IsZero() {
|
||||||
|
fmt.Fprint(f, ev.at.Format("2006/01/02 15:04:05 "))
|
||||||
|
}
|
||||||
|
for index := 0; ev.Valid(index); index++ {
|
||||||
|
if l := ev.Label(index); l.Valid() {
|
||||||
|
fmt.Fprintf(f, "\n\t%v", l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ev Event) Valid(index int) bool {
|
||||||
|
return index >= 0 && index < len(ev.static)+len(ev.dynamic)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ev Event) Label(index int) label.Label {
|
||||||
|
if index < len(ev.static) {
|
||||||
|
return ev.static[index]
|
||||||
|
}
|
||||||
|
return ev.dynamic[index-len(ev.static)]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ev Event) Find(key label.Key) label.Label {
|
||||||
|
for _, l := range ev.static {
|
||||||
|
if l.Key() == key {
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, l := range ev.dynamic {
|
||||||
|
if l.Key() == key {
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return label.Label{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeEvent(static [3]label.Label, labels []label.Label) Event {
|
||||||
|
return Event{
|
||||||
|
static: static,
|
||||||
|
dynamic: labels,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CloneEvent event returns a copy of the event with the time adjusted to at.
|
||||||
|
func CloneEvent(ev Event, at time.Time) Event {
|
||||||
|
ev.at = at
|
||||||
|
return ev
|
||||||
|
}
|
70
vendor/golang.org/x/tools/internal/event/core/export.go
generated
vendored
Normal file
70
vendor/golang.org/x/tools/internal/event/core/export.go
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
// Copyright 2019 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 core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"golang.org/x/tools/internal/event/label"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Exporter is a function that handles events.
|
||||||
|
// It may return a modified context and event.
|
||||||
|
type Exporter func(context.Context, Event, label.Map) context.Context
|
||||||
|
|
||||||
|
var (
|
||||||
|
exporter unsafe.Pointer
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetExporter sets the global exporter function that handles all events.
|
||||||
|
// The exporter is called synchronously from the event call site, so it should
|
||||||
|
// return quickly so as not to hold up user code.
|
||||||
|
func SetExporter(e Exporter) {
|
||||||
|
p := unsafe.Pointer(&e)
|
||||||
|
if e == nil {
|
||||||
|
// &e is always valid, and so p is always valid, but for the early abort
|
||||||
|
// of ProcessEvent to be efficient it needs to make the nil check on the
|
||||||
|
// pointer without having to dereference it, so we make the nil function
|
||||||
|
// also a nil pointer
|
||||||
|
p = nil
|
||||||
|
}
|
||||||
|
atomic.StorePointer(&exporter, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// deliver is called to deliver an event to the supplied exporter.
|
||||||
|
// it will fill in the time.
|
||||||
|
func deliver(ctx context.Context, exporter Exporter, ev Event) context.Context {
|
||||||
|
// add the current time to the event
|
||||||
|
ev.at = time.Now()
|
||||||
|
// hand the event off to the current exporter
|
||||||
|
return exporter(ctx, ev, ev)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export is called to deliver an event to the global exporter if set.
|
||||||
|
func Export(ctx context.Context, ev Event) context.Context {
|
||||||
|
// get the global exporter and abort early if there is not one
|
||||||
|
exporterPtr := (*Exporter)(atomic.LoadPointer(&exporter))
|
||||||
|
if exporterPtr == nil {
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
return deliver(ctx, *exporterPtr, ev)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExportPair is called to deliver a start event to the supplied exporter.
|
||||||
|
// It also returns a function that will deliver the end event to the same
|
||||||
|
// exporter.
|
||||||
|
// It will fill in the time.
|
||||||
|
func ExportPair(ctx context.Context, begin, end Event) (context.Context, func()) {
|
||||||
|
// get the global exporter and abort early if there is not one
|
||||||
|
exporterPtr := (*Exporter)(atomic.LoadPointer(&exporter))
|
||||||
|
if exporterPtr == nil {
|
||||||
|
return ctx, func() {}
|
||||||
|
}
|
||||||
|
ctx = deliver(ctx, *exporterPtr, begin)
|
||||||
|
return ctx, func() { deliver(ctx, *exporterPtr, end) }
|
||||||
|
}
|
77
vendor/golang.org/x/tools/internal/event/core/fast.go
generated
vendored
Normal file
77
vendor/golang.org/x/tools/internal/event/core/fast.go
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
// Copyright 2019 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 core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"golang.org/x/tools/internal/event/keys"
|
||||||
|
"golang.org/x/tools/internal/event/label"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Log1 takes a message and one label delivers a log event to the exporter.
|
||||||
|
// It is a customized version of Print that is faster and does no allocation.
|
||||||
|
func Log1(ctx context.Context, message string, t1 label.Label) {
|
||||||
|
Export(ctx, MakeEvent([3]label.Label{
|
||||||
|
keys.Msg.Of(message),
|
||||||
|
t1,
|
||||||
|
}, nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log2 takes a message and two labels and delivers a log event to the exporter.
|
||||||
|
// It is a customized version of Print that is faster and does no allocation.
|
||||||
|
func Log2(ctx context.Context, message string, t1 label.Label, t2 label.Label) {
|
||||||
|
Export(ctx, MakeEvent([3]label.Label{
|
||||||
|
keys.Msg.Of(message),
|
||||||
|
t1,
|
||||||
|
t2,
|
||||||
|
}, nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Metric1 sends a label event to the exporter with the supplied labels.
|
||||||
|
func Metric1(ctx context.Context, t1 label.Label) context.Context {
|
||||||
|
return Export(ctx, MakeEvent([3]label.Label{
|
||||||
|
keys.Metric.New(),
|
||||||
|
t1,
|
||||||
|
}, nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Metric2 sends a label event to the exporter with the supplied labels.
|
||||||
|
func Metric2(ctx context.Context, t1, t2 label.Label) context.Context {
|
||||||
|
return Export(ctx, MakeEvent([3]label.Label{
|
||||||
|
keys.Metric.New(),
|
||||||
|
t1,
|
||||||
|
t2,
|
||||||
|
}, nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start1 sends a span start event with the supplied label list to the exporter.
|
||||||
|
// It also returns a function that will end the span, which should normally be
|
||||||
|
// deferred.
|
||||||
|
func Start1(ctx context.Context, name string, t1 label.Label) (context.Context, func()) {
|
||||||
|
return ExportPair(ctx,
|
||||||
|
MakeEvent([3]label.Label{
|
||||||
|
keys.Start.Of(name),
|
||||||
|
t1,
|
||||||
|
}, nil),
|
||||||
|
MakeEvent([3]label.Label{
|
||||||
|
keys.End.New(),
|
||||||
|
}, nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start2 sends a span start event with the supplied label list to the exporter.
|
||||||
|
// It also returns a function that will end the span, which should normally be
|
||||||
|
// deferred.
|
||||||
|
func Start2(ctx context.Context, name string, t1, t2 label.Label) (context.Context, func()) {
|
||||||
|
return ExportPair(ctx,
|
||||||
|
MakeEvent([3]label.Label{
|
||||||
|
keys.Start.Of(name),
|
||||||
|
t1,
|
||||||
|
t2,
|
||||||
|
}, nil),
|
||||||
|
MakeEvent([3]label.Label{
|
||||||
|
keys.End.New(),
|
||||||
|
}, nil))
|
||||||
|
}
|
7
vendor/golang.org/x/tools/internal/event/doc.go
generated
vendored
Normal file
7
vendor/golang.org/x/tools/internal/event/doc.go
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Copyright 2019 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 event provides a set of packages that cover the main
|
||||||
|
// concepts of telemetry in an implementation agnostic way.
|
||||||
|
package event
|
127
vendor/golang.org/x/tools/internal/event/event.go
generated
vendored
Normal file
127
vendor/golang.org/x/tools/internal/event/event.go
generated
vendored
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
// Copyright 2019 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 event
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"golang.org/x/tools/internal/event/core"
|
||||||
|
"golang.org/x/tools/internal/event/keys"
|
||||||
|
"golang.org/x/tools/internal/event/label"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Exporter is a function that handles events.
|
||||||
|
// It may return a modified context and event.
|
||||||
|
type Exporter func(context.Context, core.Event, label.Map) context.Context
|
||||||
|
|
||||||
|
// SetExporter sets the global exporter function that handles all events.
|
||||||
|
// The exporter is called synchronously from the event call site, so it should
|
||||||
|
// return quickly so as not to hold up user code.
|
||||||
|
func SetExporter(e Exporter) {
|
||||||
|
core.SetExporter(core.Exporter(e))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log takes a message and a label list and combines them into a single event
|
||||||
|
// before delivering them to the exporter.
|
||||||
|
func Log(ctx context.Context, message string, labels ...label.Label) {
|
||||||
|
core.Export(ctx, core.MakeEvent([3]label.Label{
|
||||||
|
keys.Msg.Of(message),
|
||||||
|
}, labels))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsLog returns true if the event was built by the Log function.
|
||||||
|
// It is intended to be used in exporters to identify the semantics of the
|
||||||
|
// event when deciding what to do with it.
|
||||||
|
func IsLog(ev core.Event) bool {
|
||||||
|
return ev.Label(0).Key() == keys.Msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error takes a message and a label list and combines them into a single event
|
||||||
|
// before delivering them to the exporter. It captures the error in the
|
||||||
|
// delivered event.
|
||||||
|
func Error(ctx context.Context, message string, err error, labels ...label.Label) {
|
||||||
|
core.Export(ctx, core.MakeEvent([3]label.Label{
|
||||||
|
keys.Msg.Of(message),
|
||||||
|
keys.Err.Of(err),
|
||||||
|
}, labels))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsError returns true if the event was built by the Error function.
|
||||||
|
// It is intended to be used in exporters to identify the semantics of the
|
||||||
|
// event when deciding what to do with it.
|
||||||
|
func IsError(ev core.Event) bool {
|
||||||
|
return ev.Label(0).Key() == keys.Msg &&
|
||||||
|
ev.Label(1).Key() == keys.Err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Metric sends a label event to the exporter with the supplied labels.
|
||||||
|
func Metric(ctx context.Context, labels ...label.Label) {
|
||||||
|
core.Export(ctx, core.MakeEvent([3]label.Label{
|
||||||
|
keys.Metric.New(),
|
||||||
|
}, labels))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsMetric returns true if the event was built by the Metric function.
|
||||||
|
// It is intended to be used in exporters to identify the semantics of the
|
||||||
|
// event when deciding what to do with it.
|
||||||
|
func IsMetric(ev core.Event) bool {
|
||||||
|
return ev.Label(0).Key() == keys.Metric
|
||||||
|
}
|
||||||
|
|
||||||
|
// Label sends a label event to the exporter with the supplied labels.
|
||||||
|
func Label(ctx context.Context, labels ...label.Label) context.Context {
|
||||||
|
return core.Export(ctx, core.MakeEvent([3]label.Label{
|
||||||
|
keys.Label.New(),
|
||||||
|
}, labels))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsLabel returns true if the event was built by the Label function.
|
||||||
|
// It is intended to be used in exporters to identify the semantics of the
|
||||||
|
// event when deciding what to do with it.
|
||||||
|
func IsLabel(ev core.Event) bool {
|
||||||
|
return ev.Label(0).Key() == keys.Label
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start sends a span start event with the supplied label list to the exporter.
|
||||||
|
// It also returns a function that will end the span, which should normally be
|
||||||
|
// deferred.
|
||||||
|
func Start(ctx context.Context, name string, labels ...label.Label) (context.Context, func()) {
|
||||||
|
return core.ExportPair(ctx,
|
||||||
|
core.MakeEvent([3]label.Label{
|
||||||
|
keys.Start.Of(name),
|
||||||
|
}, labels),
|
||||||
|
core.MakeEvent([3]label.Label{
|
||||||
|
keys.End.New(),
|
||||||
|
}, nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsStart returns true if the event was built by the Start function.
|
||||||
|
// It is intended to be used in exporters to identify the semantics of the
|
||||||
|
// event when deciding what to do with it.
|
||||||
|
func IsStart(ev core.Event) bool {
|
||||||
|
return ev.Label(0).Key() == keys.Start
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsEnd returns true if the event was built by the End function.
|
||||||
|
// It is intended to be used in exporters to identify the semantics of the
|
||||||
|
// event when deciding what to do with it.
|
||||||
|
func IsEnd(ev core.Event) bool {
|
||||||
|
return ev.Label(0).Key() == keys.End
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detach returns a context without an associated span.
|
||||||
|
// This allows the creation of spans that are not children of the current span.
|
||||||
|
func Detach(ctx context.Context) context.Context {
|
||||||
|
return core.Export(ctx, core.MakeEvent([3]label.Label{
|
||||||
|
keys.Detach.New(),
|
||||||
|
}, nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsDetach returns true if the event was built by the Detach function.
|
||||||
|
// It is intended to be used in exporters to identify the semantics of the
|
||||||
|
// event when deciding what to do with it.
|
||||||
|
func IsDetach(ev core.Event) bool {
|
||||||
|
return ev.Label(0).Key() == keys.Detach
|
||||||
|
}
|
564
vendor/golang.org/x/tools/internal/event/keys/keys.go
generated
vendored
Normal file
564
vendor/golang.org/x/tools/internal/event/keys/keys.go
generated
vendored
Normal file
@ -0,0 +1,564 @@
|
|||||||
|
// Copyright 2019 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 keys
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"golang.org/x/tools/internal/event/label"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Value represents a key for untyped values.
|
||||||
|
type Value struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates a new Key for untyped values.
|
||||||
|
func New(name, description string) *Value {
|
||||||
|
return &Value{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Value) Name() string { return k.name }
|
||||||
|
func (k *Value) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *Value) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
fmt.Fprint(w, k.From(l))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *Value) Get(lm label.Map) interface{} {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *Value) From(t label.Label) interface{} { return t.UnpackValue() }
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *Value) Of(value interface{}) label.Label { return label.OfValue(k, value) }
|
||||||
|
|
||||||
|
// Tag represents a key for tagging labels that have no value.
|
||||||
|
// These are used when the existence of the label is the entire information it
|
||||||
|
// carries, such as marking events to be of a specific kind, or from a specific
|
||||||
|
// package.
|
||||||
|
type Tag struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTag creates a new Key for tagging labels.
|
||||||
|
func NewTag(name, description string) *Tag {
|
||||||
|
return &Tag{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Tag) Name() string { return k.name }
|
||||||
|
func (k *Tag) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *Tag) Format(w io.Writer, buf []byte, l label.Label) {}
|
||||||
|
|
||||||
|
// New creates a new Label with this key.
|
||||||
|
func (k *Tag) New() label.Label { return label.OfValue(k, nil) }
|
||||||
|
|
||||||
|
// Int represents a key
|
||||||
|
type Int struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewInt creates a new Key for int values.
|
||||||
|
func NewInt(name, description string) *Int {
|
||||||
|
return &Int{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Int) Name() string { return k.name }
|
||||||
|
func (k *Int) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *Int) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendInt(buf, int64(k.From(l)), 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *Int) Of(v int) label.Label { return label.Of64(k, uint64(v)) }
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *Int) Get(lm label.Map) int {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *Int) From(t label.Label) int { return int(t.Unpack64()) }
|
||||||
|
|
||||||
|
// Int8 represents a key
|
||||||
|
type Int8 struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewInt8 creates a new Key for int8 values.
|
||||||
|
func NewInt8(name, description string) *Int8 {
|
||||||
|
return &Int8{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Int8) Name() string { return k.name }
|
||||||
|
func (k *Int8) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *Int8) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendInt(buf, int64(k.From(l)), 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *Int8) Of(v int8) label.Label { return label.Of64(k, uint64(v)) }
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *Int8) Get(lm label.Map) int8 {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *Int8) From(t label.Label) int8 { return int8(t.Unpack64()) }
|
||||||
|
|
||||||
|
// Int16 represents a key
|
||||||
|
type Int16 struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewInt16 creates a new Key for int16 values.
|
||||||
|
func NewInt16(name, description string) *Int16 {
|
||||||
|
return &Int16{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Int16) Name() string { return k.name }
|
||||||
|
func (k *Int16) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *Int16) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendInt(buf, int64(k.From(l)), 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *Int16) Of(v int16) label.Label { return label.Of64(k, uint64(v)) }
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *Int16) Get(lm label.Map) int16 {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *Int16) From(t label.Label) int16 { return int16(t.Unpack64()) }
|
||||||
|
|
||||||
|
// Int32 represents a key
|
||||||
|
type Int32 struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewInt32 creates a new Key for int32 values.
|
||||||
|
func NewInt32(name, description string) *Int32 {
|
||||||
|
return &Int32{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Int32) Name() string { return k.name }
|
||||||
|
func (k *Int32) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *Int32) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendInt(buf, int64(k.From(l)), 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *Int32) Of(v int32) label.Label { return label.Of64(k, uint64(v)) }
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *Int32) Get(lm label.Map) int32 {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *Int32) From(t label.Label) int32 { return int32(t.Unpack64()) }
|
||||||
|
|
||||||
|
// Int64 represents a key
|
||||||
|
type Int64 struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewInt64 creates a new Key for int64 values.
|
||||||
|
func NewInt64(name, description string) *Int64 {
|
||||||
|
return &Int64{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Int64) Name() string { return k.name }
|
||||||
|
func (k *Int64) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *Int64) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendInt(buf, k.From(l), 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *Int64) Of(v int64) label.Label { return label.Of64(k, uint64(v)) }
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *Int64) Get(lm label.Map) int64 {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *Int64) From(t label.Label) int64 { return int64(t.Unpack64()) }
|
||||||
|
|
||||||
|
// UInt represents a key
|
||||||
|
type UInt struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUInt creates a new Key for uint values.
|
||||||
|
func NewUInt(name, description string) *UInt {
|
||||||
|
return &UInt{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *UInt) Name() string { return k.name }
|
||||||
|
func (k *UInt) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *UInt) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendUint(buf, uint64(k.From(l)), 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *UInt) Of(v uint) label.Label { return label.Of64(k, uint64(v)) }
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *UInt) Get(lm label.Map) uint {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *UInt) From(t label.Label) uint { return uint(t.Unpack64()) }
|
||||||
|
|
||||||
|
// UInt8 represents a key
|
||||||
|
type UInt8 struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUInt8 creates a new Key for uint8 values.
|
||||||
|
func NewUInt8(name, description string) *UInt8 {
|
||||||
|
return &UInt8{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *UInt8) Name() string { return k.name }
|
||||||
|
func (k *UInt8) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *UInt8) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendUint(buf, uint64(k.From(l)), 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *UInt8) Of(v uint8) label.Label { return label.Of64(k, uint64(v)) }
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *UInt8) Get(lm label.Map) uint8 {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *UInt8) From(t label.Label) uint8 { return uint8(t.Unpack64()) }
|
||||||
|
|
||||||
|
// UInt16 represents a key
|
||||||
|
type UInt16 struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUInt16 creates a new Key for uint16 values.
|
||||||
|
func NewUInt16(name, description string) *UInt16 {
|
||||||
|
return &UInt16{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *UInt16) Name() string { return k.name }
|
||||||
|
func (k *UInt16) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *UInt16) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendUint(buf, uint64(k.From(l)), 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *UInt16) Of(v uint16) label.Label { return label.Of64(k, uint64(v)) }
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *UInt16) Get(lm label.Map) uint16 {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *UInt16) From(t label.Label) uint16 { return uint16(t.Unpack64()) }
|
||||||
|
|
||||||
|
// UInt32 represents a key
|
||||||
|
type UInt32 struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUInt32 creates a new Key for uint32 values.
|
||||||
|
func NewUInt32(name, description string) *UInt32 {
|
||||||
|
return &UInt32{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *UInt32) Name() string { return k.name }
|
||||||
|
func (k *UInt32) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *UInt32) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendUint(buf, uint64(k.From(l)), 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *UInt32) Of(v uint32) label.Label { return label.Of64(k, uint64(v)) }
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *UInt32) Get(lm label.Map) uint32 {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *UInt32) From(t label.Label) uint32 { return uint32(t.Unpack64()) }
|
||||||
|
|
||||||
|
// UInt64 represents a key
|
||||||
|
type UInt64 struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUInt64 creates a new Key for uint64 values.
|
||||||
|
func NewUInt64(name, description string) *UInt64 {
|
||||||
|
return &UInt64{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *UInt64) Name() string { return k.name }
|
||||||
|
func (k *UInt64) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *UInt64) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendUint(buf, k.From(l), 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *UInt64) Of(v uint64) label.Label { return label.Of64(k, v) }
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *UInt64) Get(lm label.Map) uint64 {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *UInt64) From(t label.Label) uint64 { return t.Unpack64() }
|
||||||
|
|
||||||
|
// Float32 represents a key
|
||||||
|
type Float32 struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFloat32 creates a new Key for float32 values.
|
||||||
|
func NewFloat32(name, description string) *Float32 {
|
||||||
|
return &Float32{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Float32) Name() string { return k.name }
|
||||||
|
func (k *Float32) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *Float32) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendFloat(buf, float64(k.From(l)), 'E', -1, 32))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *Float32) Of(v float32) label.Label {
|
||||||
|
return label.Of64(k, uint64(math.Float32bits(v)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *Float32) Get(lm label.Map) float32 {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *Float32) From(t label.Label) float32 {
|
||||||
|
return math.Float32frombits(uint32(t.Unpack64()))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 represents a key
|
||||||
|
type Float64 struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFloat64 creates a new Key for int64 values.
|
||||||
|
func NewFloat64(name, description string) *Float64 {
|
||||||
|
return &Float64{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Float64) Name() string { return k.name }
|
||||||
|
func (k *Float64) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *Float64) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendFloat(buf, k.From(l), 'E', -1, 64))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *Float64) Of(v float64) label.Label {
|
||||||
|
return label.Of64(k, math.Float64bits(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *Float64) Get(lm label.Map) float64 {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *Float64) From(t label.Label) float64 {
|
||||||
|
return math.Float64frombits(t.Unpack64())
|
||||||
|
}
|
||||||
|
|
||||||
|
// String represents a key
|
||||||
|
type String struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewString creates a new Key for int64 values.
|
||||||
|
func NewString(name, description string) *String {
|
||||||
|
return &String{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *String) Name() string { return k.name }
|
||||||
|
func (k *String) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *String) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendQuote(buf, k.From(l)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *String) Of(v string) label.Label { return label.OfString(k, v) }
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *String) Get(lm label.Map) string {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *String) From(t label.Label) string { return t.UnpackString() }
|
||||||
|
|
||||||
|
// Boolean represents a key
|
||||||
|
type Boolean struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBoolean creates a new Key for bool values.
|
||||||
|
func NewBoolean(name, description string) *Boolean {
|
||||||
|
return &Boolean{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Boolean) Name() string { return k.name }
|
||||||
|
func (k *Boolean) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *Boolean) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
w.Write(strconv.AppendBool(buf, k.From(l)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *Boolean) Of(v bool) label.Label {
|
||||||
|
if v {
|
||||||
|
return label.Of64(k, 1)
|
||||||
|
}
|
||||||
|
return label.Of64(k, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *Boolean) Get(lm label.Map) bool {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *Boolean) From(t label.Label) bool { return t.Unpack64() > 0 }
|
||||||
|
|
||||||
|
// Error represents a key
|
||||||
|
type Error struct {
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewError creates a new Key for int64 values.
|
||||||
|
func NewError(name, description string) *Error {
|
||||||
|
return &Error{name: name, description: description}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Error) Name() string { return k.name }
|
||||||
|
func (k *Error) Description() string { return k.description }
|
||||||
|
|
||||||
|
func (k *Error) Format(w io.Writer, buf []byte, l label.Label) {
|
||||||
|
io.WriteString(w, k.From(l).Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Of creates a new Label with this key and the supplied value.
|
||||||
|
func (k *Error) Of(v error) label.Label { return label.OfValue(k, v) }
|
||||||
|
|
||||||
|
// Get can be used to get a label for the key from a label.Map.
|
||||||
|
func (k *Error) Get(lm label.Map) error {
|
||||||
|
if t := lm.Find(k); t.Valid() {
|
||||||
|
return k.From(t)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// From can be used to get a value from a Label.
|
||||||
|
func (k *Error) From(t label.Label) error {
|
||||||
|
err, _ := t.UnpackValue().(error)
|
||||||
|
return err
|
||||||
|
}
|
22
vendor/golang.org/x/tools/internal/event/keys/standard.go
generated
vendored
Normal file
22
vendor/golang.org/x/tools/internal/event/keys/standard.go
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2020 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 keys
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Msg is a key used to add message strings to label lists.
|
||||||
|
Msg = NewString("message", "a readable message")
|
||||||
|
// Label is a key used to indicate an event adds labels to the context.
|
||||||
|
Label = NewTag("label", "a label context marker")
|
||||||
|
// Start is used for things like traces that have a name.
|
||||||
|
Start = NewString("start", "span start")
|
||||||
|
// Metric is a key used to indicate an event records metrics.
|
||||||
|
End = NewTag("end", "a span end marker")
|
||||||
|
// Metric is a key used to indicate an event records metrics.
|
||||||
|
Detach = NewTag("detach", "a span detach marker")
|
||||||
|
// Err is a key used to add error values to label lists.
|
||||||
|
Err = NewError("error", "an error that occurred")
|
||||||
|
// Metric is a key used to indicate an event records metrics.
|
||||||
|
Metric = NewTag("metric", "a metric event marker")
|
||||||
|
)
|
213
vendor/golang.org/x/tools/internal/event/label/label.go
generated
vendored
Normal file
213
vendor/golang.org/x/tools/internal/event/label/label.go
generated
vendored
Normal file
@ -0,0 +1,213 @@
|
|||||||
|
// Copyright 2019 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 label
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"reflect"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Key is used as the identity of a Label.
|
||||||
|
// Keys are intended to be compared by pointer only, the name should be unique
|
||||||
|
// for communicating with external systems, but it is not required or enforced.
|
||||||
|
type Key interface {
|
||||||
|
// Name returns the key name.
|
||||||
|
Name() string
|
||||||
|
// Description returns a string that can be used to describe the value.
|
||||||
|
Description() string
|
||||||
|
|
||||||
|
// Format is used in formatting to append the value of the label to the
|
||||||
|
// supplied buffer.
|
||||||
|
// The formatter may use the supplied buf as a scratch area to avoid
|
||||||
|
// allocations.
|
||||||
|
Format(w io.Writer, buf []byte, l Label)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Label holds a key and value pair.
|
||||||
|
// It is normally used when passing around lists of labels.
|
||||||
|
type Label struct {
|
||||||
|
key Key
|
||||||
|
packed uint64
|
||||||
|
untyped interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map is the interface to a collection of Labels indexed by key.
|
||||||
|
type Map interface {
|
||||||
|
// Find returns the label that matches the supplied key.
|
||||||
|
Find(key Key) Label
|
||||||
|
}
|
||||||
|
|
||||||
|
// List is the interface to something that provides an iterable
|
||||||
|
// list of labels.
|
||||||
|
// Iteration should start from 0 and continue until Valid returns false.
|
||||||
|
type List interface {
|
||||||
|
// Valid returns true if the index is within range for the list.
|
||||||
|
// It does not imply the label at that index will itself be valid.
|
||||||
|
Valid(index int) bool
|
||||||
|
// Label returns the label at the given index.
|
||||||
|
Label(index int) Label
|
||||||
|
}
|
||||||
|
|
||||||
|
// list implements LabelList for a list of Labels.
|
||||||
|
type list struct {
|
||||||
|
labels []Label
|
||||||
|
}
|
||||||
|
|
||||||
|
// filter wraps a LabelList filtering out specific labels.
|
||||||
|
type filter struct {
|
||||||
|
keys []Key
|
||||||
|
underlying List
|
||||||
|
}
|
||||||
|
|
||||||
|
// listMap implements LabelMap for a simple list of labels.
|
||||||
|
type listMap struct {
|
||||||
|
labels []Label
|
||||||
|
}
|
||||||
|
|
||||||
|
// mapChain implements LabelMap for a list of underlying LabelMap.
|
||||||
|
type mapChain struct {
|
||||||
|
maps []Map
|
||||||
|
}
|
||||||
|
|
||||||
|
// OfValue creates a new label from the key and value.
|
||||||
|
// This method is for implementing new key types, label creation should
|
||||||
|
// normally be done with the Of method of the key.
|
||||||
|
func OfValue(k Key, value interface{}) Label { return Label{key: k, untyped: value} }
|
||||||
|
|
||||||
|
// UnpackValue assumes the label was built using LabelOfValue and returns the value
|
||||||
|
// that was passed to that constructor.
|
||||||
|
// This method is for implementing new key types, for type safety normal
|
||||||
|
// access should be done with the From method of the key.
|
||||||
|
func (t Label) UnpackValue() interface{} { return t.untyped }
|
||||||
|
|
||||||
|
// Of64 creates a new label from a key and a uint64. This is often
|
||||||
|
// used for non uint64 values that can be packed into a uint64.
|
||||||
|
// This method is for implementing new key types, label creation should
|
||||||
|
// normally be done with the Of method of the key.
|
||||||
|
func Of64(k Key, v uint64) Label { return Label{key: k, packed: v} }
|
||||||
|
|
||||||
|
// Unpack64 assumes the label was built using LabelOf64 and returns the value that
|
||||||
|
// was passed to that constructor.
|
||||||
|
// This method is for implementing new key types, for type safety normal
|
||||||
|
// access should be done with the From method of the key.
|
||||||
|
func (t Label) Unpack64() uint64 { return t.packed }
|
||||||
|
|
||||||
|
// OfString creates a new label from a key and a string.
|
||||||
|
// This method is for implementing new key types, label creation should
|
||||||
|
// normally be done with the Of method of the key.
|
||||||
|
func OfString(k Key, v string) Label {
|
||||||
|
hdr := (*reflect.StringHeader)(unsafe.Pointer(&v))
|
||||||
|
return Label{
|
||||||
|
key: k,
|
||||||
|
packed: uint64(hdr.Len),
|
||||||
|
untyped: unsafe.Pointer(hdr.Data),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnpackString assumes the label was built using LabelOfString and returns the
|
||||||
|
// value that was passed to that constructor.
|
||||||
|
// This method is for implementing new key types, for type safety normal
|
||||||
|
// access should be done with the From method of the key.
|
||||||
|
func (t Label) UnpackString() string {
|
||||||
|
var v string
|
||||||
|
hdr := (*reflect.StringHeader)(unsafe.Pointer(&v))
|
||||||
|
hdr.Data = uintptr(t.untyped.(unsafe.Pointer))
|
||||||
|
hdr.Len = int(t.packed)
|
||||||
|
return *(*string)(unsafe.Pointer(hdr))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid returns true if the Label is a valid one (it has a key).
|
||||||
|
func (t Label) Valid() bool { return t.key != nil }
|
||||||
|
|
||||||
|
// Key returns the key of this Label.
|
||||||
|
func (t Label) Key() Key { return t.key }
|
||||||
|
|
||||||
|
// Format is used for debug printing of labels.
|
||||||
|
func (t Label) Format(f fmt.State, r rune) {
|
||||||
|
if !t.Valid() {
|
||||||
|
io.WriteString(f, `nil`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
io.WriteString(f, t.Key().Name())
|
||||||
|
io.WriteString(f, "=")
|
||||||
|
var buf [128]byte
|
||||||
|
t.Key().Format(f, buf[:0], t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *list) Valid(index int) bool {
|
||||||
|
return index >= 0 && index < len(l.labels)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *list) Label(index int) Label {
|
||||||
|
return l.labels[index]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *filter) Valid(index int) bool {
|
||||||
|
return f.underlying.Valid(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *filter) Label(index int) Label {
|
||||||
|
l := f.underlying.Label(index)
|
||||||
|
for _, f := range f.keys {
|
||||||
|
if l.Key() == f {
|
||||||
|
return Label{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lm listMap) Find(key Key) Label {
|
||||||
|
for _, l := range lm.labels {
|
||||||
|
if l.Key() == key {
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Label{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c mapChain) Find(key Key) Label {
|
||||||
|
for _, src := range c.maps {
|
||||||
|
l := src.Find(key)
|
||||||
|
if l.Valid() {
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Label{}
|
||||||
|
}
|
||||||
|
|
||||||
|
var emptyList = &list{}
|
||||||
|
|
||||||
|
func NewList(labels ...Label) List {
|
||||||
|
if len(labels) == 0 {
|
||||||
|
return emptyList
|
||||||
|
}
|
||||||
|
return &list{labels: labels}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Filter(l List, keys ...Key) List {
|
||||||
|
if len(keys) == 0 {
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
return &filter{keys: keys, underlying: l}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMap(labels ...Label) Map {
|
||||||
|
return listMap{labels: labels}
|
||||||
|
}
|
||||||
|
|
||||||
|
func MergeMaps(srcs ...Map) Map {
|
||||||
|
var nonNil []Map
|
||||||
|
for _, src := range srcs {
|
||||||
|
if src != nil {
|
||||||
|
nonNil = append(nonNil, src)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(nonNil) == 1 {
|
||||||
|
return nonNil[0]
|
||||||
|
}
|
||||||
|
return mapChain{maps: nonNil}
|
||||||
|
}
|
100
vendor/google.golang.org/grpc/internal/channelz/logging.go
generated
vendored
Normal file
100
vendor/google.golang.org/grpc/internal/channelz/logging.go
generated
vendored
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2020 gRPC 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 channelz
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/internal/grpclog"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Info logs through grpclog.Info and adds a trace event if channelz is on.
|
||||||
|
func Info(id int64, args ...interface{}) {
|
||||||
|
if IsOn() {
|
||||||
|
AddTraceEvent(id, 1, &TraceEventDesc{
|
||||||
|
Desc: fmt.Sprint(args...),
|
||||||
|
Severity: CtINFO,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
grpclog.InfoDepth(1, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Infof logs through grpclog.Infof and adds a trace event if channelz is on.
|
||||||
|
func Infof(id int64, format string, args ...interface{}) {
|
||||||
|
msg := fmt.Sprintf(format, args...)
|
||||||
|
if IsOn() {
|
||||||
|
AddTraceEvent(id, 1, &TraceEventDesc{
|
||||||
|
Desc: msg,
|
||||||
|
Severity: CtINFO,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
grpclog.InfoDepth(1, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warning logs through grpclog.Warning and adds a trace event if channelz is on.
|
||||||
|
func Warning(id int64, args ...interface{}) {
|
||||||
|
if IsOn() {
|
||||||
|
AddTraceEvent(id, 1, &TraceEventDesc{
|
||||||
|
Desc: fmt.Sprint(args...),
|
||||||
|
Severity: CtWarning,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
grpclog.WarningDepth(1, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warningf logs through grpclog.Warningf and adds a trace event if channelz is on.
|
||||||
|
func Warningf(id int64, format string, args ...interface{}) {
|
||||||
|
msg := fmt.Sprintf(format, args...)
|
||||||
|
if IsOn() {
|
||||||
|
AddTraceEvent(id, 1, &TraceEventDesc{
|
||||||
|
Desc: msg,
|
||||||
|
Severity: CtWarning,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
grpclog.WarningDepth(1, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error logs through grpclog.Error and adds a trace event if channelz is on.
|
||||||
|
func Error(id int64, args ...interface{}) {
|
||||||
|
if IsOn() {
|
||||||
|
AddTraceEvent(id, 1, &TraceEventDesc{
|
||||||
|
Desc: fmt.Sprint(args...),
|
||||||
|
Severity: CtError,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
grpclog.ErrorDepth(1, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorf logs through grpclog.Errorf and adds a trace event if channelz is on.
|
||||||
|
func Errorf(id int64, format string, args ...interface{}) {
|
||||||
|
msg := fmt.Sprintf(format, args...)
|
||||||
|
if IsOn() {
|
||||||
|
AddTraceEvent(id, 1, &TraceEventDesc{
|
||||||
|
Desc: msg,
|
||||||
|
Severity: CtError,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
grpclog.ErrorDepth(1, msg)
|
||||||
|
}
|
||||||
|
}
|
118
vendor/google.golang.org/grpc/internal/grpclog/grpclog.go
generated
vendored
Normal file
118
vendor/google.golang.org/grpc/internal/grpclog/grpclog.go
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2020 gRPC 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 grpclog (internal) defines depth logging for grpc.
|
||||||
|
package grpclog
|
||||||
|
|
||||||
|
// Logger is the logger used for the non-depth log functions.
|
||||||
|
var Logger LoggerV2
|
||||||
|
|
||||||
|
// DepthLogger is the logger used for the depth log functions.
|
||||||
|
var DepthLogger DepthLoggerV2
|
||||||
|
|
||||||
|
// InfoDepth logs to the INFO log at the specified depth.
|
||||||
|
func InfoDepth(depth int, args ...interface{}) {
|
||||||
|
if DepthLogger != nil {
|
||||||
|
DepthLogger.InfoDepth(depth, args...)
|
||||||
|
} else {
|
||||||
|
Logger.Info(args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WarningDepth logs to the WARNING log at the specified depth.
|
||||||
|
func WarningDepth(depth int, args ...interface{}) {
|
||||||
|
if DepthLogger != nil {
|
||||||
|
DepthLogger.WarningDepth(depth, args...)
|
||||||
|
} else {
|
||||||
|
Logger.Warning(args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorDepth logs to the ERROR log at the specified depth.
|
||||||
|
func ErrorDepth(depth int, args ...interface{}) {
|
||||||
|
if DepthLogger != nil {
|
||||||
|
DepthLogger.ErrorDepth(depth, args...)
|
||||||
|
} else {
|
||||||
|
Logger.Error(args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FatalDepth logs to the FATAL log at the specified depth.
|
||||||
|
func FatalDepth(depth int, args ...interface{}) {
|
||||||
|
if DepthLogger != nil {
|
||||||
|
DepthLogger.FatalDepth(depth, args...)
|
||||||
|
} else {
|
||||||
|
Logger.Fatal(args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoggerV2 does underlying logging work for grpclog.
|
||||||
|
// This is a copy of the LoggerV2 defined in the external grpclog package. It
|
||||||
|
// is defined here to avoid a circular dependency.
|
||||||
|
type LoggerV2 interface {
|
||||||
|
// Info logs to INFO log. Arguments are handled in the manner of fmt.Print.
|
||||||
|
Info(args ...interface{})
|
||||||
|
// Infoln logs to INFO log. Arguments are handled in the manner of fmt.Println.
|
||||||
|
Infoln(args ...interface{})
|
||||||
|
// Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf.
|
||||||
|
Infof(format string, args ...interface{})
|
||||||
|
// Warning logs to WARNING log. Arguments are handled in the manner of fmt.Print.
|
||||||
|
Warning(args ...interface{})
|
||||||
|
// Warningln logs to WARNING log. Arguments are handled in the manner of fmt.Println.
|
||||||
|
Warningln(args ...interface{})
|
||||||
|
// Warningf logs to WARNING log. Arguments are handled in the manner of fmt.Printf.
|
||||||
|
Warningf(format string, args ...interface{})
|
||||||
|
// Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.
|
||||||
|
Error(args ...interface{})
|
||||||
|
// Errorln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
|
||||||
|
Errorln(args ...interface{})
|
||||||
|
// Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
|
||||||
|
Errorf(format string, args ...interface{})
|
||||||
|
// Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print.
|
||||||
|
// gRPC ensures that all Fatal logs will exit with os.Exit(1).
|
||||||
|
// Implementations may also call os.Exit() with a non-zero exit code.
|
||||||
|
Fatal(args ...interface{})
|
||||||
|
// Fatalln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
|
||||||
|
// gRPC ensures that all Fatal logs will exit with os.Exit(1).
|
||||||
|
// Implementations may also call os.Exit() with a non-zero exit code.
|
||||||
|
Fatalln(args ...interface{})
|
||||||
|
// Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
|
||||||
|
// gRPC ensures that all Fatal logs will exit with os.Exit(1).
|
||||||
|
// Implementations may also call os.Exit() with a non-zero exit code.
|
||||||
|
Fatalf(format string, args ...interface{})
|
||||||
|
// V reports whether verbosity level l is at least the requested verbose level.
|
||||||
|
V(l int) bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// DepthLoggerV2 logs at a specified call frame. If a LoggerV2 also implements
|
||||||
|
// DepthLoggerV2, the below functions will be called with the appropriate stack
|
||||||
|
// depth set for trivial functions the logger may ignore.
|
||||||
|
// This is a copy of the DepthLoggerV2 defined in the external grpclog package.
|
||||||
|
// It is defined here to avoid a circular dependency.
|
||||||
|
//
|
||||||
|
// This API is EXPERIMENTAL.
|
||||||
|
type DepthLoggerV2 interface {
|
||||||
|
// InfoDepth logs to INFO log at the specified depth. Arguments are handled in the manner of fmt.Print.
|
||||||
|
InfoDepth(depth int, args ...interface{})
|
||||||
|
// WarningDepth logs to WARNING log at the specified depth. Arguments are handled in the manner of fmt.Print.
|
||||||
|
WarningDepth(depth int, args ...interface{})
|
||||||
|
// ErrorDetph logs to ERROR log at the specified depth. Arguments are handled in the manner of fmt.Print.
|
||||||
|
ErrorDepth(depth int, args ...interface{})
|
||||||
|
// FatalDepth logs to FATAL log at the specified depth. Arguments are handled in the manner of fmt.Print.
|
||||||
|
FatalDepth(depth int, args ...interface{})
|
||||||
|
}
|
63
vendor/google.golang.org/grpc/internal/grpclog/prefixLogger.go
generated
vendored
Normal file
63
vendor/google.golang.org/grpc/internal/grpclog/prefixLogger.go
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2020 gRPC 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 grpclog
|
||||||
|
|
||||||
|
// PrefixLogger does logging with a prefix.
|
||||||
|
//
|
||||||
|
// Logging method on a nil logs without any prefix.
|
||||||
|
type PrefixLogger struct {
|
||||||
|
prefix string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Infof does info logging.
|
||||||
|
func (pl *PrefixLogger) Infof(format string, args ...interface{}) {
|
||||||
|
if pl != nil {
|
||||||
|
// Handle nil, so the tests can pass in a nil logger.
|
||||||
|
format = pl.prefix + format
|
||||||
|
}
|
||||||
|
Logger.Infof(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warningf does warning logging.
|
||||||
|
func (pl *PrefixLogger) Warningf(format string, args ...interface{}) {
|
||||||
|
if pl != nil {
|
||||||
|
format = pl.prefix + format
|
||||||
|
}
|
||||||
|
Logger.Warningf(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorf does error logging.
|
||||||
|
func (pl *PrefixLogger) Errorf(format string, args ...interface{}) {
|
||||||
|
if pl != nil {
|
||||||
|
format = pl.prefix + format
|
||||||
|
}
|
||||||
|
Logger.Errorf(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debugf does info logging at verbose level 2.
|
||||||
|
func (pl *PrefixLogger) Debugf(format string, args ...interface{}) {
|
||||||
|
if Logger.V(2) {
|
||||||
|
pl.Infof(format, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPrefixLogger creates a prefix logger with the given prefix.
|
||||||
|
func NewPrefixLogger(prefix string) *PrefixLogger {
|
||||||
|
return &PrefixLogger{prefix: prefix}
|
||||||
|
}
|
55
vendor/google.golang.org/grpc/internal/grpcutil/target.go
generated
vendored
Normal file
55
vendor/google.golang.org/grpc/internal/grpcutil/target.go
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2020 gRPC 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 grpcutil provides a bunch of utility functions to be used across the
|
||||||
|
// gRPC codebase.
|
||||||
|
package grpcutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/resolver"
|
||||||
|
)
|
||||||
|
|
||||||
|
// split2 returns the values from strings.SplitN(s, sep, 2).
|
||||||
|
// If sep is not found, it returns ("", "", false) instead.
|
||||||
|
func split2(s, sep string) (string, string, bool) {
|
||||||
|
spl := strings.SplitN(s, sep, 2)
|
||||||
|
if len(spl) < 2 {
|
||||||
|
return "", "", false
|
||||||
|
}
|
||||||
|
return spl[0], spl[1], true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseTarget splits target into a resolver.Target struct containing scheme,
|
||||||
|
// authority and endpoint.
|
||||||
|
//
|
||||||
|
// If target is not a valid scheme://authority/endpoint, it returns {Endpoint:
|
||||||
|
// target}.
|
||||||
|
func ParseTarget(target string) (ret resolver.Target) {
|
||||||
|
var ok bool
|
||||||
|
ret.Scheme, ret.Endpoint, ok = split2(target, "://")
|
||||||
|
if !ok {
|
||||||
|
return resolver.Target{Endpoint: target}
|
||||||
|
}
|
||||||
|
ret.Authority, ret.Endpoint, ok = split2(ret.Endpoint, "/")
|
||||||
|
if !ok {
|
||||||
|
return resolver.Target{Endpoint: target}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
Reference in New Issue
Block a user