Update xorm to v1 (#323)
Fix limit for databases other than sqlite go mod tidy && go mod vendor Remove unneeded break statements Make everything work with the new xorm version Fix xorm logging Fix lint Fix redis init Fix using id field Fix database init for testing Change default database log level Add xorm logger Use const for postgres go mod tidy Merge branch 'master' into update/xorm # Conflicts: # go.mod # go.sum # vendor/modules.txt go mod vendor Fix loading fixtures for postgres Go mod vendor1 Update xorm to version 1 Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/323
This commit is contained in:
5
vendor/golang.org/x/tools/internal/fastwalk/fastwalk_unix.go
generated
vendored
5
vendor/golang.org/x/tools/internal/fastwalk/fastwalk_unix.go
generated
vendored
@ -76,8 +76,9 @@ func readDir(dirName string, fn func(dirName, entName string, typ os.FileMode) e
|
||||
}
|
||||
|
||||
func parseDirEnt(buf []byte) (consumed int, name string, typ os.FileMode) {
|
||||
// golang.org/issue/15653
|
||||
dirent := (*syscall.Dirent)(unsafe.Pointer(&buf[0]))
|
||||
// golang.org/issue/37269
|
||||
dirent := &syscall.Dirent{}
|
||||
copy((*[unsafe.Sizeof(syscall.Dirent{})]byte)(unsafe.Pointer(dirent))[:], buf)
|
||||
if v := unsafe.Offsetof(dirent.Reclen) + unsafe.Sizeof(dirent.Reclen); uintptr(len(buf)) < v {
|
||||
panic(fmt.Sprintf("buf size of %d smaller than dirent header size %d", len(buf), v))
|
||||
}
|
||||
|
186
vendor/golang.org/x/tools/internal/gocommand/invoke.go
generated
vendored
Normal file
186
vendor/golang.org/x/tools/internal/gocommand/invoke.go
generated
vendored
Normal file
@ -0,0 +1,186 @@
|
||||
// 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 gocommand is a helper for calling the go command.
|
||||
package gocommand
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/tools/internal/telemetry/event"
|
||||
)
|
||||
|
||||
// An Runner will run go command invocations and serialize
|
||||
// them if it sees a concurrency error.
|
||||
type Runner struct {
|
||||
// LoadMu guards packages.Load calls and associated state.
|
||||
loadMu sync.Mutex
|
||||
serializeLoads int
|
||||
}
|
||||
|
||||
// 1.13: go: updates to go.mod needed, but contents have changed
|
||||
// 1.14: go: updating go.mod: existing contents have changed since last read
|
||||
var modConcurrencyError = regexp.MustCompile(`go:.*go.mod.*contents have changed`)
|
||||
|
||||
// Run calls Runner.RunRaw, serializing requests if they fight over
|
||||
// go.mod changes.
|
||||
func (runner *Runner) Run(ctx context.Context, inv Invocation) (*bytes.Buffer, error) {
|
||||
stdout, _, friendly, _ := runner.RunRaw(ctx, inv)
|
||||
return stdout, friendly
|
||||
}
|
||||
|
||||
// Run calls Innvocation.RunRaw, serializing requests if they fight over
|
||||
// go.mod changes.
|
||||
func (runner *Runner) RunRaw(ctx context.Context, inv Invocation) (*bytes.Buffer, *bytes.Buffer, error, error) {
|
||||
// We want to run invocations concurrently as much as possible. However,
|
||||
// if go.mod updates are needed, only one can make them and the others will
|
||||
// fail. We need to retry in those cases, but we don't want to thrash so
|
||||
// badly we never recover. To avoid that, once we've seen one concurrency
|
||||
// error, start serializing everything until the backlog has cleared out.
|
||||
runner.loadMu.Lock()
|
||||
var locked bool // If true, we hold the mutex and have incremented.
|
||||
if runner.serializeLoads == 0 {
|
||||
runner.loadMu.Unlock()
|
||||
} else {
|
||||
locked = true
|
||||
runner.serializeLoads++
|
||||
}
|
||||
defer func() {
|
||||
if locked {
|
||||
runner.serializeLoads--
|
||||
runner.loadMu.Unlock()
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
stdout, stderr, friendlyErr, err := inv.runRaw(ctx)
|
||||
if friendlyErr == nil || !modConcurrencyError.MatchString(friendlyErr.Error()) {
|
||||
return stdout, stderr, friendlyErr, err
|
||||
}
|
||||
event.Error(ctx, "Load concurrency error, will retry serially", err)
|
||||
if !locked {
|
||||
runner.loadMu.Lock()
|
||||
runner.serializeLoads++
|
||||
locked = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// An Invocation represents a call to the go command.
|
||||
type Invocation struct {
|
||||
Verb string
|
||||
Args []string
|
||||
BuildFlags []string
|
||||
Env []string
|
||||
WorkingDir string
|
||||
Logf func(format string, args ...interface{})
|
||||
}
|
||||
|
||||
// RunRaw is like RunPiped, but also returns the raw stderr and error for callers
|
||||
// that want to do low-level error handling/recovery.
|
||||
func (i *Invocation) runRaw(ctx context.Context) (stdout *bytes.Buffer, stderr *bytes.Buffer, friendlyError error, rawError error) {
|
||||
stdout = &bytes.Buffer{}
|
||||
stderr = &bytes.Buffer{}
|
||||
rawError = i.RunPiped(ctx, stdout, stderr)
|
||||
if rawError != nil {
|
||||
// Check for 'go' executable not being found.
|
||||
if ee, ok := rawError.(*exec.Error); ok && ee.Err == exec.ErrNotFound {
|
||||
friendlyError = fmt.Errorf("go command required, not found: %v", ee)
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
friendlyError = ctx.Err()
|
||||
}
|
||||
friendlyError = fmt.Errorf("err: %v: stderr: %s", rawError, stderr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// RunPiped is like Run, but relies on the given stdout/stderr
|
||||
func (i *Invocation) RunPiped(ctx context.Context, stdout, stderr io.Writer) error {
|
||||
log := i.Logf
|
||||
if log == nil {
|
||||
log = func(string, ...interface{}) {}
|
||||
}
|
||||
|
||||
goArgs := []string{i.Verb}
|
||||
switch i.Verb {
|
||||
case "mod":
|
||||
// mod needs the sub-verb before build flags.
|
||||
goArgs = append(goArgs, i.Args[0])
|
||||
goArgs = append(goArgs, i.BuildFlags...)
|
||||
goArgs = append(goArgs, i.Args[1:]...)
|
||||
case "env":
|
||||
// env doesn't take build flags.
|
||||
goArgs = append(goArgs, i.Args...)
|
||||
default:
|
||||
goArgs = append(goArgs, i.BuildFlags...)
|
||||
goArgs = append(goArgs, i.Args...)
|
||||
}
|
||||
cmd := exec.Command("go", goArgs...)
|
||||
cmd.Stdout = stdout
|
||||
cmd.Stderr = stderr
|
||||
// On darwin the cwd gets resolved to the real path, which breaks anything that
|
||||
// expects the working directory to keep the original path, including the
|
||||
// go command when dealing with modules.
|
||||
// The Go stdlib has a special feature where if the cwd and the PWD are the
|
||||
// same node then it trusts the PWD, so by setting it in the env for the child
|
||||
// process we fix up all the paths returned by the go command.
|
||||
cmd.Env = append(os.Environ(), i.Env...)
|
||||
if i.WorkingDir != "" {
|
||||
cmd.Env = append(cmd.Env, "PWD="+i.WorkingDir)
|
||||
cmd.Dir = i.WorkingDir
|
||||
}
|
||||
|
||||
defer func(start time.Time) { log("%s for %v", time.Since(start), cmdDebugStr(cmd)) }(time.Now())
|
||||
|
||||
return runCmdContext(ctx, cmd)
|
||||
}
|
||||
|
||||
// runCmdContext is like exec.CommandContext except it sends os.Interrupt
|
||||
// before os.Kill.
|
||||
func runCmdContext(ctx context.Context, cmd *exec.Cmd) error {
|
||||
if err := cmd.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
resChan := make(chan error, 1)
|
||||
go func() {
|
||||
resChan <- cmd.Wait()
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-resChan:
|
||||
return err
|
||||
case <-ctx.Done():
|
||||
}
|
||||
// Cancelled. Interrupt and see if it ends voluntarily.
|
||||
cmd.Process.Signal(os.Interrupt)
|
||||
select {
|
||||
case err := <-resChan:
|
||||
return err
|
||||
case <-time.After(time.Second):
|
||||
}
|
||||
// Didn't shut down in response to interrupt. Kill it hard.
|
||||
cmd.Process.Kill()
|
||||
return <-resChan
|
||||
}
|
||||
|
||||
func cmdDebugStr(cmd *exec.Cmd) string {
|
||||
env := make(map[string]string)
|
||||
for _, kv := range cmd.Env {
|
||||
split := strings.Split(kv, "=")
|
||||
k, v := split[0], split[1]
|
||||
env[k] = v
|
||||
}
|
||||
|
||||
return fmt.Sprintf("GOROOT=%v GOPATH=%v GO111MODULE=%v GOPROXY=%v PWD=%v go %v", env["GOROOT"], env["GOPATH"], env["GO111MODULE"], env["GOPROXY"], env["PWD"], cmd.Args)
|
||||
}
|
32
vendor/golang.org/x/tools/internal/gopathwalk/walk.go
generated
vendored
32
vendor/golang.org/x/tools/internal/gopathwalk/walk.go
generated
vendored
@ -23,8 +23,10 @@ import (
|
||||
|
||||
// Options controls the behavior of a Walk call.
|
||||
type Options struct {
|
||||
Debug bool // Enable debug logging
|
||||
ModulesEnabled bool // Search module caches. Also disables legacy goimports ignore rules.
|
||||
// If Logf is non-nil, debug logging is enabled through this function.
|
||||
Logf func(format string, args ...interface{})
|
||||
// Search module caches. Also disables legacy goimports ignore rules.
|
||||
ModulesEnabled bool
|
||||
}
|
||||
|
||||
// RootType indicates the type of a Root.
|
||||
@ -80,14 +82,14 @@ func WalkSkip(roots []Root, add func(root Root, dir string), skip func(root Root
|
||||
// walkDir creates a walker and starts fastwalk with this walker.
|
||||
func walkDir(root Root, add func(Root, string), skip func(root Root, dir string) bool, opts Options) {
|
||||
if _, err := os.Stat(root.Path); os.IsNotExist(err) {
|
||||
if opts.Debug {
|
||||
log.Printf("skipping nonexistent directory: %v", root.Path)
|
||||
if opts.Logf != nil {
|
||||
opts.Logf("skipping nonexistent directory: %v", root.Path)
|
||||
}
|
||||
return
|
||||
}
|
||||
start := time.Now()
|
||||
if opts.Debug {
|
||||
log.Printf("gopathwalk: scanning %s", root.Path)
|
||||
if opts.Logf != nil {
|
||||
opts.Logf("gopathwalk: scanning %s", root.Path)
|
||||
}
|
||||
w := &walker{
|
||||
root: root,
|
||||
@ -100,8 +102,8 @@ func walkDir(root Root, add func(Root, string), skip func(root Root, dir string)
|
||||
log.Printf("gopathwalk: scanning directory %v: %v", root.Path, err)
|
||||
}
|
||||
|
||||
if opts.Debug {
|
||||
log.Printf("gopathwalk: scanned %s in %v", root.Path, time.Since(start))
|
||||
if opts.Logf != nil {
|
||||
opts.Logf("gopathwalk: scanned %s in %v", root.Path, time.Since(start))
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,11 +132,11 @@ func (w *walker) init() {
|
||||
full := filepath.Join(w.root.Path, p)
|
||||
if fi, err := os.Stat(full); err == nil {
|
||||
w.ignoredDirs = append(w.ignoredDirs, fi)
|
||||
if w.opts.Debug {
|
||||
log.Printf("Directory added to ignore list: %s", full)
|
||||
if w.opts.Logf != nil {
|
||||
w.opts.Logf("Directory added to ignore list: %s", full)
|
||||
}
|
||||
} else if w.opts.Debug {
|
||||
log.Printf("Error statting ignored directory: %v", err)
|
||||
} else if w.opts.Logf != nil {
|
||||
w.opts.Logf("Error statting ignored directory: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -145,11 +147,11 @@ func (w *walker) init() {
|
||||
func (w *walker) getIgnoredDirs(path string) []string {
|
||||
file := filepath.Join(path, ".goimportsignore")
|
||||
slurp, err := ioutil.ReadFile(file)
|
||||
if w.opts.Debug {
|
||||
if w.opts.Logf != nil {
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
w.opts.Logf("%v", err)
|
||||
} else {
|
||||
log.Printf("Read %s", file)
|
||||
w.opts.Logf("Read %s", file)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
|
72
vendor/golang.org/x/tools/internal/imports/fix.go
generated
vendored
72
vendor/golang.org/x/tools/internal/imports/fix.go
generated
vendored
@ -14,7 +14,6 @@ import (
|
||||
"go/token"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@ -22,11 +21,11 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"golang.org/x/tools/go/ast/astutil"
|
||||
"golang.org/x/tools/internal/gocommand"
|
||||
"golang.org/x/tools/internal/gopathwalk"
|
||||
)
|
||||
|
||||
@ -263,7 +262,7 @@ type pass struct {
|
||||
|
||||
// loadPackageNames saves the package names for everything referenced by imports.
|
||||
func (p *pass) loadPackageNames(imports []*ImportInfo) error {
|
||||
if p.env.Debug {
|
||||
if p.env.Logf != nil {
|
||||
p.env.Logf("loading package names for %v packages", len(imports))
|
||||
defer func() {
|
||||
p.env.Logf("done loading package names for %v packages", len(imports))
|
||||
@ -335,7 +334,7 @@ func (p *pass) load() ([]*ImportFix, bool) {
|
||||
if p.loadRealPackageNames {
|
||||
err := p.loadPackageNames(append(imports, p.candidates...))
|
||||
if err != nil {
|
||||
if p.env.Debug {
|
||||
if p.env.Logf != nil {
|
||||
p.env.Logf("loading package names: %v", err)
|
||||
}
|
||||
return nil, false
|
||||
@ -529,7 +528,7 @@ func getFixes(fset *token.FileSet, f *ast.File, filename string, env *ProcessEnv
|
||||
return nil, err
|
||||
}
|
||||
srcDir := filepath.Dir(abs)
|
||||
if env.Debug {
|
||||
if env.Logf != nil {
|
||||
env.Logf("fixImports(filename=%q), abs=%q, srcDir=%q ...", filename, abs, srcDir)
|
||||
}
|
||||
|
||||
@ -537,7 +536,7 @@ func getFixes(fset *token.FileSet, f *ast.File, filename string, env *ProcessEnv
|
||||
// derive package names from import paths, see if the file is already
|
||||
// complete. We can't add any imports yet, because we don't know
|
||||
// if missing references are actually package vars.
|
||||
p := &pass{fset: fset, f: f, srcDir: srcDir}
|
||||
p := &pass{fset: fset, f: f, srcDir: srcDir, env: env}
|
||||
if fixes, done := p.load(); done {
|
||||
return fixes, nil
|
||||
}
|
||||
@ -559,8 +558,7 @@ func getFixes(fset *token.FileSet, f *ast.File, filename string, env *ProcessEnv
|
||||
}
|
||||
|
||||
// Third pass: get real package names where we had previously used
|
||||
// the naive algorithm. This is the first step that will use the
|
||||
// environment, so we provide it here for the first time.
|
||||
// the naive algorithm.
|
||||
p = &pass{fset: fset, f: f, srcDir: srcDir, env: env}
|
||||
p.loadRealPackageNames = true
|
||||
p.otherFiles = otherFiles
|
||||
@ -748,14 +746,17 @@ func getPackageExports(ctx context.Context, wrapped func(PackageExport), searchP
|
||||
// the go command, the go/build package, etc.
|
||||
type ProcessEnv struct {
|
||||
LocalPrefix string
|
||||
Debug bool
|
||||
|
||||
GocmdRunner *gocommand.Runner
|
||||
|
||||
BuildFlags []string
|
||||
|
||||
// If non-empty, these will be used instead of the
|
||||
// process-wide values.
|
||||
GOPATH, GOROOT, GO111MODULE, GOPROXY, GOFLAGS, GOSUMDB string
|
||||
WorkingDir string
|
||||
|
||||
// Logf is the default logger for the ProcessEnv.
|
||||
// If Logf is non-nil, debug logging is enabled through this function.
|
||||
Logf func(format string, args ...interface{})
|
||||
|
||||
resolver Resolver
|
||||
@ -791,7 +792,7 @@ func (e *ProcessEnv) GetResolver() Resolver {
|
||||
if e.resolver != nil {
|
||||
return e.resolver
|
||||
}
|
||||
out, err := e.invokeGo("env", "GOMOD")
|
||||
out, err := e.invokeGo(context.TODO(), "env", "GOMOD")
|
||||
if err != nil || len(bytes.TrimSpace(out.Bytes())) == 0 {
|
||||
e.resolver = newGopathResolver(e)
|
||||
return e.resolver
|
||||
@ -822,37 +823,24 @@ func (e *ProcessEnv) buildContext() *build.Context {
|
||||
return &ctx
|
||||
}
|
||||
|
||||
func (e *ProcessEnv) invokeGo(args ...string) (*bytes.Buffer, error) {
|
||||
cmd := exec.Command("go", args...)
|
||||
stdout := &bytes.Buffer{}
|
||||
stderr := &bytes.Buffer{}
|
||||
cmd.Stdout = stdout
|
||||
cmd.Stderr = stderr
|
||||
cmd.Env = e.env()
|
||||
cmd.Dir = e.WorkingDir
|
||||
|
||||
if e.Debug {
|
||||
defer func(start time.Time) { e.Logf("%s for %v", time.Since(start), cmdDebugStr(cmd)) }(time.Now())
|
||||
func (e *ProcessEnv) invokeGo(ctx context.Context, verb string, args ...string) (*bytes.Buffer, error) {
|
||||
inv := gocommand.Invocation{
|
||||
Verb: verb,
|
||||
Args: args,
|
||||
BuildFlags: e.BuildFlags,
|
||||
Env: e.env(),
|
||||
Logf: e.Logf,
|
||||
WorkingDir: e.WorkingDir,
|
||||
}
|
||||
if err := cmd.Run(); err != nil {
|
||||
return nil, fmt.Errorf("running go: %v (stderr:\n%s)", err, stderr)
|
||||
}
|
||||
return stdout, nil
|
||||
}
|
||||
|
||||
func cmdDebugStr(cmd *exec.Cmd) string {
|
||||
env := make(map[string]string)
|
||||
for _, kv := range cmd.Env {
|
||||
split := strings.Split(kv, "=")
|
||||
k, v := split[0], split[1]
|
||||
env[k] = v
|
||||
}
|
||||
|
||||
return fmt.Sprintf("GOROOT=%v GOPATH=%v GO111MODULE=%v GOPROXY=%v PWD=%v go %v", env["GOROOT"], env["GOPATH"], env["GO111MODULE"], env["GOPROXY"], env["PWD"], cmd.Args)
|
||||
return e.GocmdRunner.Run(ctx, inv)
|
||||
}
|
||||
|
||||
func addStdlibCandidates(pass *pass, refs references) {
|
||||
add := func(pkg string) {
|
||||
// Prevent self-imports.
|
||||
if path.Base(pkg) == pass.f.Name.Name && filepath.Join(pass.env.GOROOT, "src", pkg) == pass.srcDir {
|
||||
return
|
||||
}
|
||||
exports := copyExports(stdlib[pkg])
|
||||
pass.addCandidate(
|
||||
&ImportInfo{ImportPath: pkg},
|
||||
@ -1251,7 +1239,7 @@ func (r *gopathResolver) scan(ctx context.Context, callback *scanCallback) error
|
||||
case <-r.scanSema:
|
||||
}
|
||||
defer func() { r.scanSema <- struct{}{} }()
|
||||
gopathwalk.Walk(roots, add, gopathwalk.Options{Debug: r.env.Debug, ModulesEnabled: false})
|
||||
gopathwalk.Walk(roots, add, gopathwalk.Options{Logf: r.env.Logf, ModulesEnabled: false})
|
||||
close(scanDone)
|
||||
}()
|
||||
select {
|
||||
@ -1355,7 +1343,7 @@ func loadExportsFromFiles(ctx context.Context, env *ProcessEnv, dir string, incl
|
||||
}
|
||||
}
|
||||
|
||||
if env.Debug {
|
||||
if env.Logf != nil {
|
||||
sortedExports := append([]string(nil), exports...)
|
||||
sort.Strings(sortedExports)
|
||||
env.Logf("loaded exports in dir %v (package %v): %v", dir, pkgName, strings.Join(sortedExports, ", "))
|
||||
@ -1371,7 +1359,7 @@ func findImport(ctx context.Context, pass *pass, candidates []pkgDistance, pkgNa
|
||||
// ones. Note that this sorts by the de-vendored name, so
|
||||
// there's no "penalty" for vendoring.
|
||||
sort.Sort(byDistanceOrImportPathShortLength(candidates))
|
||||
if pass.env.Debug {
|
||||
if pass.env.Logf != nil {
|
||||
for i, c := range candidates {
|
||||
pass.env.Logf("%s candidate %d/%d: %v in %v", pkgName, i+1, len(candidates), c.pkg.importPathShort, c.pkg.dir)
|
||||
}
|
||||
@ -1409,14 +1397,14 @@ func findImport(ctx context.Context, pass *pass, candidates []pkgDistance, pkgNa
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
if pass.env.Debug {
|
||||
if pass.env.Logf != nil {
|
||||
pass.env.Logf("loading exports in dir %s (seeking package %s)", c.pkg.dir, pkgName)
|
||||
}
|
||||
// If we're an x_test, load the package under test's test variant.
|
||||
includeTest := strings.HasSuffix(pass.f.Name.Name, "_test") && c.pkg.dir == pass.srcDir
|
||||
_, exports, err := pass.env.GetResolver().loadExports(ctx, c.pkg, includeTest)
|
||||
if err != nil {
|
||||
if pass.env.Debug {
|
||||
if pass.env.Logf != nil {
|
||||
pass.env.Logf("loading exports in dir %s (seeking package %s): %v", c.pkg.dir, pkgName, err)
|
||||
}
|
||||
resc <- nil
|
||||
|
10
vendor/golang.org/x/tools/internal/imports/imports.go
generated
vendored
10
vendor/golang.org/x/tools/internal/imports/imports.go
generated
vendored
@ -21,13 +21,13 @@ import (
|
||||
"go/token"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/go/ast/astutil"
|
||||
"golang.org/x/tools/internal/gocommand"
|
||||
)
|
||||
|
||||
// Options is golang.org/x/tools/imports.Options with extra internal-only options.
|
||||
@ -155,12 +155,10 @@ func initialize(filename string, src []byte, opt *Options) ([]byte, *Options, er
|
||||
GOSUMDB: os.Getenv("GOSUMDB"),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the logger if the user has not provided it.
|
||||
if opt.Env.Logf == nil {
|
||||
opt.Env.Logf = log.Printf
|
||||
// Set the gocmdRunner if the user has not provided it.
|
||||
if opt.Env.GocmdRunner == nil {
|
||||
opt.Env.GocmdRunner = &gocommand.Runner{}
|
||||
}
|
||||
|
||||
if src == nil {
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
|
18
vendor/golang.org/x/tools/internal/imports/mod.go
generated
vendored
18
vendor/golang.org/x/tools/internal/imports/mod.go
generated
vendored
@ -14,9 +14,9 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/mod/module"
|
||||
"golang.org/x/mod/semver"
|
||||
"golang.org/x/tools/internal/gopathwalk"
|
||||
"golang.org/x/tools/internal/module"
|
||||
"golang.org/x/tools/internal/semver"
|
||||
)
|
||||
|
||||
// ModuleResolver implements resolver for modules using the go command as little
|
||||
@ -146,7 +146,7 @@ func (r *ModuleResolver) init() error {
|
||||
}
|
||||
|
||||
func (r *ModuleResolver) initAllMods() error {
|
||||
stdout, err := r.env.invokeGo("list", "-m", "-json", "...")
|
||||
stdout, err := r.env.invokeGo(context.TODO(), "list", "-m", "-json", "...")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -156,12 +156,14 @@ func (r *ModuleResolver) initAllMods() error {
|
||||
return err
|
||||
}
|
||||
if mod.Dir == "" {
|
||||
if r.env.Debug {
|
||||
if r.env.Logf != nil {
|
||||
r.env.Logf("module %v has not been downloaded and will be ignored", mod.Path)
|
||||
}
|
||||
// Can't do anything with a module that's not downloaded.
|
||||
continue
|
||||
}
|
||||
// golang/go#36193: the go command doesn't always clean paths.
|
||||
mod.Dir = filepath.Clean(mod.Dir)
|
||||
r.modsByModPath = append(r.modsByModPath, mod)
|
||||
r.modsByDir = append(r.modsByDir, mod)
|
||||
if mod.Main {
|
||||
@ -468,7 +470,7 @@ func (r *ModuleResolver) scan(ctx context.Context, callback *scanCallback) error
|
||||
if r.scannedRoots[root] {
|
||||
continue
|
||||
}
|
||||
gopathwalk.WalkSkip([]gopathwalk.Root{root}, add, skip, gopathwalk.Options{Debug: r.env.Debug, ModulesEnabled: true})
|
||||
gopathwalk.WalkSkip([]gopathwalk.Root{root}, add, skip, gopathwalk.Options{Logf: r.env.Logf, ModulesEnabled: true})
|
||||
r.scannedRoots[root] = true
|
||||
}
|
||||
close(scanDone)
|
||||
@ -579,9 +581,9 @@ func (r *ModuleResolver) scanDirForPackage(root gopathwalk.Root, dir string) dir
|
||||
err: fmt.Errorf("invalid module cache path: %v", subdir),
|
||||
}
|
||||
}
|
||||
modPath, err := module.DecodePath(filepath.ToSlash(matches[1]))
|
||||
modPath, err := module.UnescapePath(filepath.ToSlash(matches[1]))
|
||||
if err != nil {
|
||||
if r.env.Debug {
|
||||
if r.env.Logf != nil {
|
||||
r.env.Logf("decoding module cache path %q: %v", subdir, err)
|
||||
}
|
||||
return directoryPackageInfo{
|
||||
@ -697,7 +699,7 @@ func getMainModuleAnd114(env *ProcessEnv) (*ModuleJSON, bool, error) {
|
||||
{{.GoVersion}}
|
||||
{{range context.ReleaseTags}}{{if eq . "go1.14"}}{{.}}{{end}}{{end}}
|
||||
`
|
||||
stdout, err := env.invokeGo("list", "-m", "-f", format)
|
||||
stdout, err := env.invokeGo(context.TODO(), "list", "-m", "-f", format)
|
||||
if err != nil {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
29
vendor/golang.org/x/tools/internal/imports/mod_cache.go
generated
vendored
29
vendor/golang.org/x/tools/internal/imports/mod_cache.go
generated
vendored
@ -132,20 +132,7 @@ func (d *dirInfoCache) ScanAndListen(ctx context.Context, listener cacheListener
|
||||
}
|
||||
d.mu.Unlock()
|
||||
|
||||
// Process the pre-existing keys.
|
||||
for _, k := range keys {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
cancel()
|
||||
return func() {}
|
||||
default:
|
||||
}
|
||||
if v, ok := d.Load(k); ok {
|
||||
listener(v)
|
||||
}
|
||||
}
|
||||
|
||||
return func() {
|
||||
stop := func() {
|
||||
cancel()
|
||||
d.mu.Lock()
|
||||
delete(d.listeners, cookie)
|
||||
@ -154,6 +141,20 @@ func (d *dirInfoCache) ScanAndListen(ctx context.Context, listener cacheListener
|
||||
<-sema
|
||||
}
|
||||
}
|
||||
|
||||
// Process the pre-existing keys.
|
||||
for _, k := range keys {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return stop
|
||||
default:
|
||||
}
|
||||
if v, ok := d.Load(k); ok {
|
||||
listener(v)
|
||||
}
|
||||
}
|
||||
|
||||
return stop
|
||||
}
|
||||
|
||||
// Store stores the package info for dir.
|
||||
|
540
vendor/golang.org/x/tools/internal/module/module.go
generated
vendored
540
vendor/golang.org/x/tools/internal/module/module.go
generated
vendored
@ -1,540 +0,0 @@
|
||||
// Copyright 2018 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 module defines the module.Version type
|
||||
// along with support code.
|
||||
package module
|
||||
|
||||
// IMPORTANT NOTE
|
||||
//
|
||||
// This file essentially defines the set of valid import paths for the go command.
|
||||
// There are many subtle considerations, including Unicode ambiguity,
|
||||
// security, network, and file system representations.
|
||||
//
|
||||
// This file also defines the set of valid module path and version combinations,
|
||||
// another topic with many subtle considerations.
|
||||
//
|
||||
// Changes to the semantics in this file require approval from rsc.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"golang.org/x/tools/internal/semver"
|
||||
)
|
||||
|
||||
// A Version is defined by a module path and version pair.
|
||||
type Version struct {
|
||||
Path string
|
||||
|
||||
// Version is usually a semantic version in canonical form.
|
||||
// There are two exceptions to this general rule.
|
||||
// First, the top-level target of a build has no specific version
|
||||
// and uses Version = "".
|
||||
// Second, during MVS calculations the version "none" is used
|
||||
// to represent the decision to take no version of a given module.
|
||||
Version string `json:",omitempty"`
|
||||
}
|
||||
|
||||
// Check checks that a given module path, version pair is valid.
|
||||
// In addition to the path being a valid module path
|
||||
// and the version being a valid semantic version,
|
||||
// the two must correspond.
|
||||
// For example, the path "yaml/v2" only corresponds to
|
||||
// semantic versions beginning with "v2.".
|
||||
func Check(path, version string) error {
|
||||
if err := CheckPath(path); err != nil {
|
||||
return err
|
||||
}
|
||||
if !semver.IsValid(version) {
|
||||
return fmt.Errorf("malformed semantic version %v", version)
|
||||
}
|
||||
_, pathMajor, _ := SplitPathVersion(path)
|
||||
if !MatchPathMajor(version, pathMajor) {
|
||||
if pathMajor == "" {
|
||||
pathMajor = "v0 or v1"
|
||||
}
|
||||
if pathMajor[0] == '.' { // .v1
|
||||
pathMajor = pathMajor[1:]
|
||||
}
|
||||
return fmt.Errorf("mismatched module path %v and version %v (want %v)", path, version, pathMajor)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// firstPathOK reports whether r can appear in the first element of a module path.
|
||||
// The first element of the path must be an LDH domain name, at least for now.
|
||||
// To avoid case ambiguity, the domain name must be entirely lower case.
|
||||
func firstPathOK(r rune) bool {
|
||||
return r == '-' || r == '.' ||
|
||||
'0' <= r && r <= '9' ||
|
||||
'a' <= r && r <= 'z'
|
||||
}
|
||||
|
||||
// pathOK reports whether r can appear in an import path element.
|
||||
// Paths can be ASCII letters, ASCII digits, and limited ASCII punctuation: + - . _ and ~.
|
||||
// This matches what "go get" has historically recognized in import paths.
|
||||
// TODO(rsc): We would like to allow Unicode letters, but that requires additional
|
||||
// care in the safe encoding (see note below).
|
||||
func pathOK(r rune) bool {
|
||||
if r < utf8.RuneSelf {
|
||||
return r == '+' || r == '-' || r == '.' || r == '_' || r == '~' ||
|
||||
'0' <= r && r <= '9' ||
|
||||
'A' <= r && r <= 'Z' ||
|
||||
'a' <= r && r <= 'z'
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// fileNameOK reports whether r can appear in a file name.
|
||||
// For now we allow all Unicode letters but otherwise limit to pathOK plus a few more punctuation characters.
|
||||
// If we expand the set of allowed characters here, we have to
|
||||
// work harder at detecting potential case-folding and normalization collisions.
|
||||
// See note about "safe encoding" below.
|
||||
func fileNameOK(r rune) bool {
|
||||
if r < utf8.RuneSelf {
|
||||
// Entire set of ASCII punctuation, from which we remove characters:
|
||||
// ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
|
||||
// We disallow some shell special characters: " ' * < > ? ` |
|
||||
// (Note that some of those are disallowed by the Windows file system as well.)
|
||||
// We also disallow path separators / : and \ (fileNameOK is only called on path element characters).
|
||||
// We allow spaces (U+0020) in file names.
|
||||
const allowed = "!#$%&()+,-.=@[]^_{}~ "
|
||||
if '0' <= r && r <= '9' || 'A' <= r && r <= 'Z' || 'a' <= r && r <= 'z' {
|
||||
return true
|
||||
}
|
||||
for i := 0; i < len(allowed); i++ {
|
||||
if rune(allowed[i]) == r {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
// It may be OK to add more ASCII punctuation here, but only carefully.
|
||||
// For example Windows disallows < > \, and macOS disallows :, so we must not allow those.
|
||||
return unicode.IsLetter(r)
|
||||
}
|
||||
|
||||
// CheckPath checks that a module path is valid.
|
||||
func CheckPath(path string) error {
|
||||
if err := checkPath(path, false); err != nil {
|
||||
return fmt.Errorf("malformed module path %q: %v", path, err)
|
||||
}
|
||||
i := strings.Index(path, "/")
|
||||
if i < 0 {
|
||||
i = len(path)
|
||||
}
|
||||
if i == 0 {
|
||||
return fmt.Errorf("malformed module path %q: leading slash", path)
|
||||
}
|
||||
if !strings.Contains(path[:i], ".") {
|
||||
return fmt.Errorf("malformed module path %q: missing dot in first path element", path)
|
||||
}
|
||||
if path[0] == '-' {
|
||||
return fmt.Errorf("malformed module path %q: leading dash in first path element", path)
|
||||
}
|
||||
for _, r := range path[:i] {
|
||||
if !firstPathOK(r) {
|
||||
return fmt.Errorf("malformed module path %q: invalid char %q in first path element", path, r)
|
||||
}
|
||||
}
|
||||
if _, _, ok := SplitPathVersion(path); !ok {
|
||||
return fmt.Errorf("malformed module path %q: invalid version", path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckImportPath checks that an import path is valid.
|
||||
func CheckImportPath(path string) error {
|
||||
if err := checkPath(path, false); err != nil {
|
||||
return fmt.Errorf("malformed import path %q: %v", path, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkPath checks that a general path is valid.
|
||||
// It returns an error describing why but not mentioning path.
|
||||
// Because these checks apply to both module paths and import paths,
|
||||
// the caller is expected to add the "malformed ___ path %q: " prefix.
|
||||
// fileName indicates whether the final element of the path is a file name
|
||||
// (as opposed to a directory name).
|
||||
func checkPath(path string, fileName bool) error {
|
||||
if !utf8.ValidString(path) {
|
||||
return fmt.Errorf("invalid UTF-8")
|
||||
}
|
||||
if path == "" {
|
||||
return fmt.Errorf("empty string")
|
||||
}
|
||||
if strings.Contains(path, "..") {
|
||||
return fmt.Errorf("double dot")
|
||||
}
|
||||
if strings.Contains(path, "//") {
|
||||
return fmt.Errorf("double slash")
|
||||
}
|
||||
if path[len(path)-1] == '/' {
|
||||
return fmt.Errorf("trailing slash")
|
||||
}
|
||||
elemStart := 0
|
||||
for i, r := range path {
|
||||
if r == '/' {
|
||||
if err := checkElem(path[elemStart:i], fileName); err != nil {
|
||||
return err
|
||||
}
|
||||
elemStart = i + 1
|
||||
}
|
||||
}
|
||||
if err := checkElem(path[elemStart:], fileName); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkElem checks whether an individual path element is valid.
|
||||
// fileName indicates whether the element is a file name (not a directory name).
|
||||
func checkElem(elem string, fileName bool) error {
|
||||
if elem == "" {
|
||||
return fmt.Errorf("empty path element")
|
||||
}
|
||||
if strings.Count(elem, ".") == len(elem) {
|
||||
return fmt.Errorf("invalid path element %q", elem)
|
||||
}
|
||||
if elem[0] == '.' && !fileName {
|
||||
return fmt.Errorf("leading dot in path element")
|
||||
}
|
||||
if elem[len(elem)-1] == '.' {
|
||||
return fmt.Errorf("trailing dot in path element")
|
||||
}
|
||||
charOK := pathOK
|
||||
if fileName {
|
||||
charOK = fileNameOK
|
||||
}
|
||||
for _, r := range elem {
|
||||
if !charOK(r) {
|
||||
return fmt.Errorf("invalid char %q", r)
|
||||
}
|
||||
}
|
||||
|
||||
// Windows disallows a bunch of path elements, sadly.
|
||||
// See https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
|
||||
short := elem
|
||||
if i := strings.Index(short, "."); i >= 0 {
|
||||
short = short[:i]
|
||||
}
|
||||
for _, bad := range badWindowsNames {
|
||||
if strings.EqualFold(bad, short) {
|
||||
return fmt.Errorf("disallowed path element %q", elem)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckFilePath checks whether a slash-separated file path is valid.
|
||||
func CheckFilePath(path string) error {
|
||||
if err := checkPath(path, true); err != nil {
|
||||
return fmt.Errorf("malformed file path %q: %v", path, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// badWindowsNames are the reserved file path elements on Windows.
|
||||
// See https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
|
||||
var badWindowsNames = []string{
|
||||
"CON",
|
||||
"PRN",
|
||||
"AUX",
|
||||
"NUL",
|
||||
"COM1",
|
||||
"COM2",
|
||||
"COM3",
|
||||
"COM4",
|
||||
"COM5",
|
||||
"COM6",
|
||||
"COM7",
|
||||
"COM8",
|
||||
"COM9",
|
||||
"LPT1",
|
||||
"LPT2",
|
||||
"LPT3",
|
||||
"LPT4",
|
||||
"LPT5",
|
||||
"LPT6",
|
||||
"LPT7",
|
||||
"LPT8",
|
||||
"LPT9",
|
||||
}
|
||||
|
||||
// SplitPathVersion returns prefix and major version such that prefix+pathMajor == path
|
||||
// and version is either empty or "/vN" for N >= 2.
|
||||
// As a special case, gopkg.in paths are recognized directly;
|
||||
// they require ".vN" instead of "/vN", and for all N, not just N >= 2.
|
||||
func SplitPathVersion(path string) (prefix, pathMajor string, ok bool) {
|
||||
if strings.HasPrefix(path, "gopkg.in/") {
|
||||
return splitGopkgIn(path)
|
||||
}
|
||||
|
||||
i := len(path)
|
||||
dot := false
|
||||
for i > 0 && ('0' <= path[i-1] && path[i-1] <= '9' || path[i-1] == '.') {
|
||||
if path[i-1] == '.' {
|
||||
dot = true
|
||||
}
|
||||
i--
|
||||
}
|
||||
if i <= 1 || i == len(path) || path[i-1] != 'v' || path[i-2] != '/' {
|
||||
return path, "", true
|
||||
}
|
||||
prefix, pathMajor = path[:i-2], path[i-2:]
|
||||
if dot || len(pathMajor) <= 2 || pathMajor[2] == '0' || pathMajor == "/v1" {
|
||||
return path, "", false
|
||||
}
|
||||
return prefix, pathMajor, true
|
||||
}
|
||||
|
||||
// splitGopkgIn is like SplitPathVersion but only for gopkg.in paths.
|
||||
func splitGopkgIn(path string) (prefix, pathMajor string, ok bool) {
|
||||
if !strings.HasPrefix(path, "gopkg.in/") {
|
||||
return path, "", false
|
||||
}
|
||||
i := len(path)
|
||||
if strings.HasSuffix(path, "-unstable") {
|
||||
i -= len("-unstable")
|
||||
}
|
||||
for i > 0 && ('0' <= path[i-1] && path[i-1] <= '9') {
|
||||
i--
|
||||
}
|
||||
if i <= 1 || path[i-1] != 'v' || path[i-2] != '.' {
|
||||
// All gopkg.in paths must end in vN for some N.
|
||||
return path, "", false
|
||||
}
|
||||
prefix, pathMajor = path[:i-2], path[i-2:]
|
||||
if len(pathMajor) <= 2 || pathMajor[2] == '0' && pathMajor != ".v0" {
|
||||
return path, "", false
|
||||
}
|
||||
return prefix, pathMajor, true
|
||||
}
|
||||
|
||||
// MatchPathMajor reports whether the semantic version v
|
||||
// matches the path major version pathMajor.
|
||||
func MatchPathMajor(v, pathMajor string) bool {
|
||||
if strings.HasPrefix(pathMajor, ".v") && strings.HasSuffix(pathMajor, "-unstable") {
|
||||
pathMajor = strings.TrimSuffix(pathMajor, "-unstable")
|
||||
}
|
||||
if strings.HasPrefix(v, "v0.0.0-") && pathMajor == ".v1" {
|
||||
// Allow old bug in pseudo-versions that generated v0.0.0- pseudoversion for gopkg .v1.
|
||||
// For example, gopkg.in/yaml.v2@v2.2.1's go.mod requires gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405.
|
||||
return true
|
||||
}
|
||||
m := semver.Major(v)
|
||||
if pathMajor == "" {
|
||||
return m == "v0" || m == "v1" || semver.Build(v) == "+incompatible"
|
||||
}
|
||||
return (pathMajor[0] == '/' || pathMajor[0] == '.') && m == pathMajor[1:]
|
||||
}
|
||||
|
||||
// CanonicalVersion returns the canonical form of the version string v.
|
||||
// It is the same as semver.Canonical(v) except that it preserves the special build suffix "+incompatible".
|
||||
func CanonicalVersion(v string) string {
|
||||
cv := semver.Canonical(v)
|
||||
if semver.Build(v) == "+incompatible" {
|
||||
cv += "+incompatible"
|
||||
}
|
||||
return cv
|
||||
}
|
||||
|
||||
// Sort sorts the list by Path, breaking ties by comparing Versions.
|
||||
func Sort(list []Version) {
|
||||
sort.Slice(list, func(i, j int) bool {
|
||||
mi := list[i]
|
||||
mj := list[j]
|
||||
if mi.Path != mj.Path {
|
||||
return mi.Path < mj.Path
|
||||
}
|
||||
// To help go.sum formatting, allow version/file.
|
||||
// Compare semver prefix by semver rules,
|
||||
// file by string order.
|
||||
vi := mi.Version
|
||||
vj := mj.Version
|
||||
var fi, fj string
|
||||
if k := strings.Index(vi, "/"); k >= 0 {
|
||||
vi, fi = vi[:k], vi[k:]
|
||||
}
|
||||
if k := strings.Index(vj, "/"); k >= 0 {
|
||||
vj, fj = vj[:k], vj[k:]
|
||||
}
|
||||
if vi != vj {
|
||||
return semver.Compare(vi, vj) < 0
|
||||
}
|
||||
return fi < fj
|
||||
})
|
||||
}
|
||||
|
||||
// Safe encodings
|
||||
//
|
||||
// Module paths appear as substrings of file system paths
|
||||
// (in the download cache) and of web server URLs in the proxy protocol.
|
||||
// In general we cannot rely on file systems to be case-sensitive,
|
||||
// nor can we rely on web servers, since they read from file systems.
|
||||
// That is, we cannot rely on the file system to keep rsc.io/QUOTE
|
||||
// and rsc.io/quote separate. Windows and macOS don't.
|
||||
// Instead, we must never require two different casings of a file path.
|
||||
// Because we want the download cache to match the proxy protocol,
|
||||
// and because we want the proxy protocol to be possible to serve
|
||||
// from a tree of static files (which might be stored on a case-insensitive
|
||||
// file system), the proxy protocol must never require two different casings
|
||||
// of a URL path either.
|
||||
//
|
||||
// One possibility would be to make the safe encoding be the lowercase
|
||||
// hexadecimal encoding of the actual path bytes. This would avoid ever
|
||||
// needing different casings of a file path, but it would be fairly illegible
|
||||
// to most programmers when those paths appeared in the file system
|
||||
// (including in file paths in compiler errors and stack traces)
|
||||
// in web server logs, and so on. Instead, we want a safe encoding that
|
||||
// leaves most paths unaltered.
|
||||
//
|
||||
// The safe encoding is this:
|
||||
// replace every uppercase letter with an exclamation mark
|
||||
// followed by the letter's lowercase equivalent.
|
||||
//
|
||||
// For example,
|
||||
// github.com/Azure/azure-sdk-for-go -> github.com/!azure/azure-sdk-for-go.
|
||||
// github.com/GoogleCloudPlatform/cloudsql-proxy -> github.com/!google!cloud!platform/cloudsql-proxy
|
||||
// github.com/Sirupsen/logrus -> github.com/!sirupsen/logrus.
|
||||
//
|
||||
// Import paths that avoid upper-case letters are left unchanged.
|
||||
// Note that because import paths are ASCII-only and avoid various
|
||||
// problematic punctuation (like : < and >), the safe encoding is also ASCII-only
|
||||
// and avoids the same problematic punctuation.
|
||||
//
|
||||
// Import paths have never allowed exclamation marks, so there is no
|
||||
// need to define how to encode a literal !.
|
||||
//
|
||||
// Although paths are disallowed from using Unicode (see pathOK above),
|
||||
// the eventual plan is to allow Unicode letters as well, to assume that
|
||||
// file systems and URLs are Unicode-safe (storing UTF-8), and apply
|
||||
// the !-for-uppercase convention. Note however that not all runes that
|
||||
// are different but case-fold equivalent are an upper/lower pair.
|
||||
// For example, U+004B ('K'), U+006B ('k'), and U+212A ('K' for Kelvin)
|
||||
// are considered to case-fold to each other. When we do add Unicode
|
||||
// letters, we must not assume that upper/lower are the only case-equivalent pairs.
|
||||
// Perhaps the Kelvin symbol would be disallowed entirely, for example.
|
||||
// Or perhaps it would encode as "!!k", or perhaps as "(212A)".
|
||||
//
|
||||
// Also, it would be nice to allow Unicode marks as well as letters,
|
||||
// but marks include combining marks, and then we must deal not
|
||||
// only with case folding but also normalization: both U+00E9 ('é')
|
||||
// and U+0065 U+0301 ('e' followed by combining acute accent)
|
||||
// look the same on the page and are treated by some file systems
|
||||
// as the same path. If we do allow Unicode marks in paths, there
|
||||
// must be some kind of normalization to allow only one canonical
|
||||
// encoding of any character used in an import path.
|
||||
|
||||
// EncodePath returns the safe encoding of the given module path.
|
||||
// It fails if the module path is invalid.
|
||||
func EncodePath(path string) (encoding string, err error) {
|
||||
if err := CheckPath(path); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return encodeString(path)
|
||||
}
|
||||
|
||||
// EncodeVersion returns the safe encoding of the given module version.
|
||||
// Versions are allowed to be in non-semver form but must be valid file names
|
||||
// and not contain exclamation marks.
|
||||
func EncodeVersion(v string) (encoding string, err error) {
|
||||
if err := checkElem(v, true); err != nil || strings.Contains(v, "!") {
|
||||
return "", fmt.Errorf("disallowed version string %q", v)
|
||||
}
|
||||
return encodeString(v)
|
||||
}
|
||||
|
||||
func encodeString(s string) (encoding string, err error) {
|
||||
haveUpper := false
|
||||
for _, r := range s {
|
||||
if r == '!' || r >= utf8.RuneSelf {
|
||||
// This should be disallowed by CheckPath, but diagnose anyway.
|
||||
// The correctness of the encoding loop below depends on it.
|
||||
return "", fmt.Errorf("internal error: inconsistency in EncodePath")
|
||||
}
|
||||
if 'A' <= r && r <= 'Z' {
|
||||
haveUpper = true
|
||||
}
|
||||
}
|
||||
|
||||
if !haveUpper {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
var buf []byte
|
||||
for _, r := range s {
|
||||
if 'A' <= r && r <= 'Z' {
|
||||
buf = append(buf, '!', byte(r+'a'-'A'))
|
||||
} else {
|
||||
buf = append(buf, byte(r))
|
||||
}
|
||||
}
|
||||
return string(buf), nil
|
||||
}
|
||||
|
||||
// DecodePath returns the module path of the given safe encoding.
|
||||
// It fails if the encoding is invalid or encodes an invalid path.
|
||||
func DecodePath(encoding string) (path string, err error) {
|
||||
path, ok := decodeString(encoding)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("invalid module path encoding %q", encoding)
|
||||
}
|
||||
if err := CheckPath(path); err != nil {
|
||||
return "", fmt.Errorf("invalid module path encoding %q: %v", encoding, err)
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
||||
// DecodeVersion returns the version string for the given safe encoding.
|
||||
// It fails if the encoding is invalid or encodes an invalid version.
|
||||
// Versions are allowed to be in non-semver form but must be valid file names
|
||||
// and not contain exclamation marks.
|
||||
func DecodeVersion(encoding string) (v string, err error) {
|
||||
v, ok := decodeString(encoding)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("invalid version encoding %q", encoding)
|
||||
}
|
||||
if err := checkElem(v, true); err != nil {
|
||||
return "", fmt.Errorf("disallowed version string %q", v)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func decodeString(encoding string) (string, bool) {
|
||||
var buf []byte
|
||||
|
||||
bang := false
|
||||
for _, r := range encoding {
|
||||
if r >= utf8.RuneSelf {
|
||||
return "", false
|
||||
}
|
||||
if bang {
|
||||
bang = false
|
||||
if r < 'a' || 'z' < r {
|
||||
return "", false
|
||||
}
|
||||
buf = append(buf, byte(r+'A'-'a'))
|
||||
continue
|
||||
}
|
||||
if r == '!' {
|
||||
bang = true
|
||||
continue
|
||||
}
|
||||
if 'A' <= r && r <= 'Z' {
|
||||
return "", false
|
||||
}
|
||||
buf = append(buf, byte(r))
|
||||
}
|
||||
if bang {
|
||||
return "", false
|
||||
}
|
||||
return string(buf), true
|
||||
}
|
31
vendor/golang.org/x/tools/internal/packagesinternal/packages.go
generated
vendored
31
vendor/golang.org/x/tools/internal/packagesinternal/packages.go
generated
vendored
@ -1,4 +1,35 @@
|
||||
// Package packagesinternal exposes internal-only fields from go/packages.
|
||||
package packagesinternal
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/tools/internal/gocommand"
|
||||
)
|
||||
|
||||
// Fields must match go list;
|
||||
type Module struct {
|
||||
Path string // module path
|
||||
Version string // module version
|
||||
Versions []string // available module versions (with -versions)
|
||||
Replace *Module // replaced by this module
|
||||
Time *time.Time // time version was created
|
||||
Update *Module // available update, if any (with -u)
|
||||
Main bool // is this the main module?
|
||||
Indirect bool // is this module only an indirect dependency of main module?
|
||||
Dir string // directory holding files for this module, if any
|
||||
GoMod string // path to go.mod file used when loading this module, if any
|
||||
GoVersion string // go version used in module
|
||||
Error *ModuleError // error loading module
|
||||
}
|
||||
type ModuleError struct {
|
||||
Err string // the error itself
|
||||
}
|
||||
|
||||
var GetForTest = func(p interface{}) string { return "" }
|
||||
|
||||
var GetModule = func(p interface{}) *Module { return nil }
|
||||
|
||||
var GetGoCmdRunner = func(config interface{}) *gocommand.Runner { return nil }
|
||||
|
||||
var SetGoCmdRunner = func(config interface{}, runner *gocommand.Runner) {}
|
||||
|
388
vendor/golang.org/x/tools/internal/semver/semver.go
generated
vendored
388
vendor/golang.org/x/tools/internal/semver/semver.go
generated
vendored
@ -1,388 +0,0 @@
|
||||
// Copyright 2018 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 semver implements comparison of semantic version strings.
|
||||
// In this package, semantic version strings must begin with a leading "v",
|
||||
// as in "v1.0.0".
|
||||
//
|
||||
// The general form of a semantic version string accepted by this package is
|
||||
//
|
||||
// vMAJOR[.MINOR[.PATCH[-PRERELEASE][+BUILD]]]
|
||||
//
|
||||
// where square brackets indicate optional parts of the syntax;
|
||||
// MAJOR, MINOR, and PATCH are decimal integers without extra leading zeros;
|
||||
// PRERELEASE and BUILD are each a series of non-empty dot-separated identifiers
|
||||
// using only alphanumeric characters and hyphens; and
|
||||
// all-numeric PRERELEASE identifiers must not have leading zeros.
|
||||
//
|
||||
// This package follows Semantic Versioning 2.0.0 (see semver.org)
|
||||
// with two exceptions. First, it requires the "v" prefix. Second, it recognizes
|
||||
// vMAJOR and vMAJOR.MINOR (with no prerelease or build suffixes)
|
||||
// as shorthands for vMAJOR.0.0 and vMAJOR.MINOR.0.
|
||||
package semver
|
||||
|
||||
// parsed returns the parsed form of a semantic version string.
|
||||
type parsed struct {
|
||||
major string
|
||||
minor string
|
||||
patch string
|
||||
short string
|
||||
prerelease string
|
||||
build string
|
||||
err string
|
||||
}
|
||||
|
||||
// IsValid reports whether v is a valid semantic version string.
|
||||
func IsValid(v string) bool {
|
||||
_, ok := parse(v)
|
||||
return ok
|
||||
}
|
||||
|
||||
// Canonical returns the canonical formatting of the semantic version v.
|
||||
// It fills in any missing .MINOR or .PATCH and discards build metadata.
|
||||
// Two semantic versions compare equal only if their canonical formattings
|
||||
// are identical strings.
|
||||
// The canonical invalid semantic version is the empty string.
|
||||
func Canonical(v string) string {
|
||||
p, ok := parse(v)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
if p.build != "" {
|
||||
return v[:len(v)-len(p.build)]
|
||||
}
|
||||
if p.short != "" {
|
||||
return v + p.short
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Major returns the major version prefix of the semantic version v.
|
||||
// For example, Major("v2.1.0") == "v2".
|
||||
// If v is an invalid semantic version string, Major returns the empty string.
|
||||
func Major(v string) string {
|
||||
pv, ok := parse(v)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return v[:1+len(pv.major)]
|
||||
}
|
||||
|
||||
// MajorMinor returns the major.minor version prefix of the semantic version v.
|
||||
// For example, MajorMinor("v2.1.0") == "v2.1".
|
||||
// If v is an invalid semantic version string, MajorMinor returns the empty string.
|
||||
func MajorMinor(v string) string {
|
||||
pv, ok := parse(v)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
i := 1 + len(pv.major)
|
||||
if j := i + 1 + len(pv.minor); j <= len(v) && v[i] == '.' && v[i+1:j] == pv.minor {
|
||||
return v[:j]
|
||||
}
|
||||
return v[:i] + "." + pv.minor
|
||||
}
|
||||
|
||||
// Prerelease returns the prerelease suffix of the semantic version v.
|
||||
// For example, Prerelease("v2.1.0-pre+meta") == "-pre".
|
||||
// If v is an invalid semantic version string, Prerelease returns the empty string.
|
||||
func Prerelease(v string) string {
|
||||
pv, ok := parse(v)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return pv.prerelease
|
||||
}
|
||||
|
||||
// Build returns the build suffix of the semantic version v.
|
||||
// For example, Build("v2.1.0+meta") == "+meta".
|
||||
// If v is an invalid semantic version string, Build returns the empty string.
|
||||
func Build(v string) string {
|
||||
pv, ok := parse(v)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return pv.build
|
||||
}
|
||||
|
||||
// Compare returns an integer comparing two versions according to
|
||||
// according to semantic version precedence.
|
||||
// The result will be 0 if v == w, -1 if v < w, or +1 if v > w.
|
||||
//
|
||||
// An invalid semantic version string is considered less than a valid one.
|
||||
// All invalid semantic version strings compare equal to each other.
|
||||
func Compare(v, w string) int {
|
||||
pv, ok1 := parse(v)
|
||||
pw, ok2 := parse(w)
|
||||
if !ok1 && !ok2 {
|
||||
return 0
|
||||
}
|
||||
if !ok1 {
|
||||
return -1
|
||||
}
|
||||
if !ok2 {
|
||||
return +1
|
||||
}
|
||||
if c := compareInt(pv.major, pw.major); c != 0 {
|
||||
return c
|
||||
}
|
||||
if c := compareInt(pv.minor, pw.minor); c != 0 {
|
||||
return c
|
||||
}
|
||||
if c := compareInt(pv.patch, pw.patch); c != 0 {
|
||||
return c
|
||||
}
|
||||
return comparePrerelease(pv.prerelease, pw.prerelease)
|
||||
}
|
||||
|
||||
// Max canonicalizes its arguments and then returns the version string
|
||||
// that compares greater.
|
||||
func Max(v, w string) string {
|
||||
v = Canonical(v)
|
||||
w = Canonical(w)
|
||||
if Compare(v, w) > 0 {
|
||||
return v
|
||||
}
|
||||
return w
|
||||
}
|
||||
|
||||
func parse(v string) (p parsed, ok bool) {
|
||||
if v == "" || v[0] != 'v' {
|
||||
p.err = "missing v prefix"
|
||||
return
|
||||
}
|
||||
p.major, v, ok = parseInt(v[1:])
|
||||
if !ok {
|
||||
p.err = "bad major version"
|
||||
return
|
||||
}
|
||||
if v == "" {
|
||||
p.minor = "0"
|
||||
p.patch = "0"
|
||||
p.short = ".0.0"
|
||||
return
|
||||
}
|
||||
if v[0] != '.' {
|
||||
p.err = "bad minor prefix"
|
||||
ok = false
|
||||
return
|
||||
}
|
||||
p.minor, v, ok = parseInt(v[1:])
|
||||
if !ok {
|
||||
p.err = "bad minor version"
|
||||
return
|
||||
}
|
||||
if v == "" {
|
||||
p.patch = "0"
|
||||
p.short = ".0"
|
||||
return
|
||||
}
|
||||
if v[0] != '.' {
|
||||
p.err = "bad patch prefix"
|
||||
ok = false
|
||||
return
|
||||
}
|
||||
p.patch, v, ok = parseInt(v[1:])
|
||||
if !ok {
|
||||
p.err = "bad patch version"
|
||||
return
|
||||
}
|
||||
if len(v) > 0 && v[0] == '-' {
|
||||
p.prerelease, v, ok = parsePrerelease(v)
|
||||
if !ok {
|
||||
p.err = "bad prerelease"
|
||||
return
|
||||
}
|
||||
}
|
||||
if len(v) > 0 && v[0] == '+' {
|
||||
p.build, v, ok = parseBuild(v)
|
||||
if !ok {
|
||||
p.err = "bad build"
|
||||
return
|
||||
}
|
||||
}
|
||||
if v != "" {
|
||||
p.err = "junk on end"
|
||||
ok = false
|
||||
return
|
||||
}
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
|
||||
func parseInt(v string) (t, rest string, ok bool) {
|
||||
if v == "" {
|
||||
return
|
||||
}
|
||||
if v[0] < '0' || '9' < v[0] {
|
||||
return
|
||||
}
|
||||
i := 1
|
||||
for i < len(v) && '0' <= v[i] && v[i] <= '9' {
|
||||
i++
|
||||
}
|
||||
if v[0] == '0' && i != 1 {
|
||||
return
|
||||
}
|
||||
return v[:i], v[i:], true
|
||||
}
|
||||
|
||||
func parsePrerelease(v string) (t, rest string, ok bool) {
|
||||
// "A pre-release version MAY be denoted by appending a hyphen and
|
||||
// a series of dot separated identifiers immediately following the patch version.
|
||||
// Identifiers MUST comprise only ASCII alphanumerics and hyphen [0-9A-Za-z-].
|
||||
// Identifiers MUST NOT be empty. Numeric identifiers MUST NOT include leading zeroes."
|
||||
if v == "" || v[0] != '-' {
|
||||
return
|
||||
}
|
||||
i := 1
|
||||
start := 1
|
||||
for i < len(v) && v[i] != '+' {
|
||||
if !isIdentChar(v[i]) && v[i] != '.' {
|
||||
return
|
||||
}
|
||||
if v[i] == '.' {
|
||||
if start == i || isBadNum(v[start:i]) {
|
||||
return
|
||||
}
|
||||
start = i + 1
|
||||
}
|
||||
i++
|
||||
}
|
||||
if start == i || isBadNum(v[start:i]) {
|
||||
return
|
||||
}
|
||||
return v[:i], v[i:], true
|
||||
}
|
||||
|
||||
func parseBuild(v string) (t, rest string, ok bool) {
|
||||
if v == "" || v[0] != '+' {
|
||||
return
|
||||
}
|
||||
i := 1
|
||||
start := 1
|
||||
for i < len(v) {
|
||||
if !isIdentChar(v[i]) {
|
||||
return
|
||||
}
|
||||
if v[i] == '.' {
|
||||
if start == i {
|
||||
return
|
||||
}
|
||||
start = i + 1
|
||||
}
|
||||
i++
|
||||
}
|
||||
if start == i {
|
||||
return
|
||||
}
|
||||
return v[:i], v[i:], true
|
||||
}
|
||||
|
||||
func isIdentChar(c byte) bool {
|
||||
return 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || '0' <= c && c <= '9' || c == '-'
|
||||
}
|
||||
|
||||
func isBadNum(v string) bool {
|
||||
i := 0
|
||||
for i < len(v) && '0' <= v[i] && v[i] <= '9' {
|
||||
i++
|
||||
}
|
||||
return i == len(v) && i > 1 && v[0] == '0'
|
||||
}
|
||||
|
||||
func isNum(v string) bool {
|
||||
i := 0
|
||||
for i < len(v) && '0' <= v[i] && v[i] <= '9' {
|
||||
i++
|
||||
}
|
||||
return i == len(v)
|
||||
}
|
||||
|
||||
func compareInt(x, y string) int {
|
||||
if x == y {
|
||||
return 0
|
||||
}
|
||||
if len(x) < len(y) {
|
||||
return -1
|
||||
}
|
||||
if len(x) > len(y) {
|
||||
return +1
|
||||
}
|
||||
if x < y {
|
||||
return -1
|
||||
} else {
|
||||
return +1
|
||||
}
|
||||
}
|
||||
|
||||
func comparePrerelease(x, y string) int {
|
||||
// "When major, minor, and patch are equal, a pre-release version has
|
||||
// lower precedence than a normal version.
|
||||
// Example: 1.0.0-alpha < 1.0.0.
|
||||
// Precedence for two pre-release versions with the same major, minor,
|
||||
// and patch version MUST be determined by comparing each dot separated
|
||||
// identifier from left to right until a difference is found as follows:
|
||||
// identifiers consisting of only digits are compared numerically and
|
||||
// identifiers with letters or hyphens are compared lexically in ASCII
|
||||
// sort order. Numeric identifiers always have lower precedence than
|
||||
// non-numeric identifiers. A larger set of pre-release fields has a
|
||||
// higher precedence than a smaller set, if all of the preceding
|
||||
// identifiers are equal.
|
||||
// Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta <
|
||||
// 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0."
|
||||
if x == y {
|
||||
return 0
|
||||
}
|
||||
if x == "" {
|
||||
return +1
|
||||
}
|
||||
if y == "" {
|
||||
return -1
|
||||
}
|
||||
for x != "" && y != "" {
|
||||
x = x[1:] // skip - or .
|
||||
y = y[1:] // skip - or .
|
||||
var dx, dy string
|
||||
dx, x = nextIdent(x)
|
||||
dy, y = nextIdent(y)
|
||||
if dx != dy {
|
||||
ix := isNum(dx)
|
||||
iy := isNum(dy)
|
||||
if ix != iy {
|
||||
if ix {
|
||||
return -1
|
||||
} else {
|
||||
return +1
|
||||
}
|
||||
}
|
||||
if ix {
|
||||
if len(dx) < len(dy) {
|
||||
return -1
|
||||
}
|
||||
if len(dx) > len(dy) {
|
||||
return +1
|
||||
}
|
||||
}
|
||||
if dx < dy {
|
||||
return -1
|
||||
} else {
|
||||
return +1
|
||||
}
|
||||
}
|
||||
}
|
||||
if x == "" {
|
||||
return -1
|
||||
} else {
|
||||
return +1
|
||||
}
|
||||
}
|
||||
|
||||
func nextIdent(x string) (dx, rest string) {
|
||||
i := 0
|
||||
for i < len(x) && x[i] != '.' {
|
||||
i++
|
||||
}
|
||||
return x[:i], x[i:]
|
||||
}
|
113
vendor/golang.org/x/tools/internal/telemetry/event/event.go
generated
vendored
Normal file
113
vendor/golang.org/x/tools/internal/telemetry/event/event.go
generated
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
// 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 support for event based telemetry.
|
||||
package event
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type eventType uint8
|
||||
|
||||
const (
|
||||
invalidType = eventType(iota)
|
||||
LogType // an event that should be recorded in a log
|
||||
StartSpanType // the start of a span of time
|
||||
EndSpanType // the end of a span of time
|
||||
LabelType // some values that should be noted for later events
|
||||
DetachType // an event that causes a context to detach
|
||||
RecordType // a value that should be tracked
|
||||
)
|
||||
|
||||
// sTags is used to hold a small number of tags inside an event whichout
|
||||
// requiring a separate allocation.
|
||||
// As tags are often on the stack, this avoids 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 tags (one for each value and
|
||||
// one for the message itself).
|
||||
type sTags [3]Tag
|
||||
|
||||
// Event holds the information about an event of note that ocurred.
|
||||
type Event struct {
|
||||
At time.Time
|
||||
|
||||
typ eventType
|
||||
static sTags // inline storage for the first few tags
|
||||
dynamic []Tag // dynamically sized storage for remaining tags
|
||||
}
|
||||
|
||||
// eventTagMap implements TagMap for a the tags of an Event.
|
||||
type eventTagMap struct {
|
||||
event Event
|
||||
}
|
||||
|
||||
func (ev Event) IsLog() bool { return ev.typ == LogType }
|
||||
func (ev Event) IsEndSpan() bool { return ev.typ == EndSpanType }
|
||||
func (ev Event) IsStartSpan() bool { return ev.typ == StartSpanType }
|
||||
func (ev Event) IsLabel() bool { return ev.typ == LabelType }
|
||||
func (ev Event) IsDetach() bool { return ev.typ == DetachType }
|
||||
func (ev Event) IsRecord() bool { return ev.typ == RecordType }
|
||||
|
||||
func (ev Event) Format(f fmt.State, r rune) {
|
||||
tagMap := TagMap(ev)
|
||||
if !ev.At.IsZero() {
|
||||
fmt.Fprint(f, ev.At.Format("2006/01/02 15:04:05 "))
|
||||
}
|
||||
msg := Msg.Get(tagMap)
|
||||
err := Err.Get(tagMap)
|
||||
fmt.Fprint(f, msg)
|
||||
if err != nil {
|
||||
if f.Flag('+') {
|
||||
fmt.Fprintf(f, ": %+v", err)
|
||||
} else {
|
||||
fmt.Fprintf(f, ": %v", err)
|
||||
}
|
||||
}
|
||||
for index := 0; ev.Valid(index); index++ {
|
||||
tag := ev.Tag(index)
|
||||
// msg and err were both already printed above, so we skip them to avoid
|
||||
// double printing
|
||||
if !tag.Valid() || tag.Key == Msg || tag.Key == Err {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(f, "\n\t%v", tag)
|
||||
}
|
||||
}
|
||||
|
||||
func (ev Event) Valid(index int) bool {
|
||||
return index >= 0 && index < len(ev.static)+len(ev.dynamic)
|
||||
}
|
||||
|
||||
func (ev Event) Tag(index int) Tag {
|
||||
if index < len(ev.static) {
|
||||
return ev.static[index]
|
||||
}
|
||||
return ev.dynamic[index-len(ev.static)]
|
||||
}
|
||||
|
||||
func (ev Event) Find(key interface{}) Tag {
|
||||
for _, tag := range ev.static {
|
||||
if tag.Key == key {
|
||||
return tag
|
||||
}
|
||||
}
|
||||
for _, tag := range ev.dynamic {
|
||||
if tag.Key == key {
|
||||
return tag
|
||||
}
|
||||
}
|
||||
return Tag{}
|
||||
}
|
||||
|
||||
func makeEvent(typ eventType, static sTags, tags []Tag) Event {
|
||||
return Event{
|
||||
typ: typ,
|
||||
static: static,
|
||||
dynamic: tags,
|
||||
}
|
||||
}
|
68
vendor/golang.org/x/tools/internal/telemetry/event/export.go
generated
vendored
Normal file
68
vendor/golang.org/x/tools/internal/telemetry/event/export.go
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
// 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"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Exporter is a function that handles events.
|
||||
// It may return a modified context and event.
|
||||
type Exporter func(context.Context, Event, TagMap) 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 and generate the basic tag source.
|
||||
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)
|
||||
}
|
||||
|
||||
// dispatch is called to deliver an event to the global exporter if set.
|
||||
func dispatch(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)
|
||||
}
|
||||
|
||||
// dispatchPair 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 and generate the basic tag source.
|
||||
func dispatchPair(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) }
|
||||
}
|
499
vendor/golang.org/x/tools/internal/telemetry/event/key.go
generated
vendored
Normal file
499
vendor/golang.org/x/tools/internal/telemetry/event/key.go
generated
vendored
Normal file
@ -0,0 +1,499 @@
|
||||
// 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 (
|
||||
"math"
|
||||
)
|
||||
|
||||
var (
|
||||
// Msg is a key used to add message strings to tag lists.
|
||||
Msg = NewStringKey("message", "a readable message")
|
||||
// Name is used for things like traces that have a name.
|
||||
Name = NewStringKey("name", "an entity name")
|
||||
// Err is a key used to add error values to tag lists.
|
||||
Err = NewErrorKey("error", "an error that occurred")
|
||||
)
|
||||
|
||||
// Key is the interface shared by all key implementations.
|
||||
type Key interface {
|
||||
// Name returns the key name.
|
||||
Name() string
|
||||
// Description returns a string that can be used to describe the value.
|
||||
Description() string
|
||||
}
|
||||
|
||||
// key is used as the identity of a Tag.
|
||||
// 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 struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// ValueKey represents a key for untyped values.
|
||||
type ValueKey struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewKey creates a new Key for untyped values.
|
||||
func NewKey(name, description string) *ValueKey {
|
||||
return &ValueKey{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *ValueKey) Name() string { return k.name }
|
||||
func (k *ValueKey) Description() string { return k.description }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *ValueKey) Get(tags TagMap) interface{} {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *ValueKey) From(t Tag) interface{} { return t.untyped }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *ValueKey) Of(value interface{}) Tag { return Tag{Key: k, untyped: value} }
|
||||
|
||||
// IntKey represents a key
|
||||
type IntKey struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewIntKey creates a new Key for int values.
|
||||
func NewIntKey(name, description string) *IntKey {
|
||||
return &IntKey{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *IntKey) Name() string { return k.name }
|
||||
func (k *IntKey) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *IntKey) Of(v int) Tag { return Tag{Key: k, packed: uint64(v)} }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *IntKey) Get(tags TagMap) int {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *IntKey) From(t Tag) int { return int(t.packed) }
|
||||
|
||||
// Int8Key represents a key
|
||||
type Int8Key struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewInt8Key creates a new Key for int8 values.
|
||||
func NewInt8Key(name, description string) *Int8Key {
|
||||
return &Int8Key{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *Int8Key) Name() string { return k.name }
|
||||
func (k *Int8Key) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *Int8Key) Of(v int8) Tag { return Tag{Key: k, packed: uint64(v)} }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *Int8Key) Get(tags TagMap) int8 {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *Int8Key) From(t Tag) int8 { return int8(t.packed) }
|
||||
|
||||
// Int16Key represents a key
|
||||
type Int16Key struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewInt16Key creates a new Key for int16 values.
|
||||
func NewInt16Key(name, description string) *Int16Key {
|
||||
return &Int16Key{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *Int16Key) Name() string { return k.name }
|
||||
func (k *Int16Key) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *Int16Key) Of(v int16) Tag { return Tag{Key: k, packed: uint64(v)} }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *Int16Key) Get(tags TagMap) int16 {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *Int16Key) From(t Tag) int16 { return int16(t.packed) }
|
||||
|
||||
// Int32Key represents a key
|
||||
type Int32Key struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewInt32Key creates a new Key for int32 values.
|
||||
func NewInt32Key(name, description string) *Int32Key {
|
||||
return &Int32Key{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *Int32Key) Name() string { return k.name }
|
||||
func (k *Int32Key) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *Int32Key) Of(v int32) Tag { return Tag{Key: k, packed: uint64(v)} }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *Int32Key) Get(tags TagMap) int32 {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *Int32Key) From(t Tag) int32 { return int32(t.packed) }
|
||||
|
||||
// Int64Key represents a key
|
||||
type Int64Key struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewInt64Key creates a new Key for int64 values.
|
||||
func NewInt64Key(name, description string) *Int64Key {
|
||||
return &Int64Key{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *Int64Key) Name() string { return k.name }
|
||||
func (k *Int64Key) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *Int64Key) Of(v int64) Tag { return Tag{Key: k, packed: uint64(v)} }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *Int64Key) Get(tags TagMap) int64 {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *Int64Key) From(t Tag) int64 { return int64(t.packed) }
|
||||
|
||||
// UIntKey represents a key
|
||||
type UIntKey struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewUIntKey creates a new Key for uint values.
|
||||
func NewUIntKey(name, description string) *UIntKey {
|
||||
return &UIntKey{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *UIntKey) Name() string { return k.name }
|
||||
func (k *UIntKey) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *UIntKey) Of(v uint) Tag { return Tag{Key: k, packed: uint64(v)} }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *UIntKey) Get(tags TagMap) uint {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *UIntKey) From(t Tag) uint { return uint(t.packed) }
|
||||
|
||||
// UInt8Key represents a key
|
||||
type UInt8Key struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewUInt8Key creates a new Key for uint8 values.
|
||||
func NewUInt8Key(name, description string) *UInt8Key {
|
||||
return &UInt8Key{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *UInt8Key) Name() string { return k.name }
|
||||
func (k *UInt8Key) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *UInt8Key) Of(v uint8) Tag { return Tag{Key: k, packed: uint64(v)} }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *UInt8Key) Get(tags TagMap) uint8 {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *UInt8Key) From(t Tag) uint8 { return uint8(t.packed) }
|
||||
|
||||
// UInt16Key represents a key
|
||||
type UInt16Key struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewUInt16Key creates a new Key for uint16 values.
|
||||
func NewUInt16Key(name, description string) *UInt16Key {
|
||||
return &UInt16Key{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *UInt16Key) Name() string { return k.name }
|
||||
func (k *UInt16Key) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *UInt16Key) Of(v uint16) Tag { return Tag{Key: k, packed: uint64(v)} }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *UInt16Key) Get(tags TagMap) uint16 {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *UInt16Key) From(t Tag) uint16 { return uint16(t.packed) }
|
||||
|
||||
// UInt32Key represents a key
|
||||
type UInt32Key struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewUInt32Key creates a new Key for uint32 values.
|
||||
func NewUInt32Key(name, description string) *UInt32Key {
|
||||
return &UInt32Key{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *UInt32Key) Name() string { return k.name }
|
||||
func (k *UInt32Key) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *UInt32Key) Of(v uint32) Tag { return Tag{Key: k, packed: uint64(v)} }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *UInt32Key) Get(tags TagMap) uint32 {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *UInt32Key) From(t Tag) uint32 { return uint32(t.packed) }
|
||||
|
||||
// UInt64Key represents a key
|
||||
type UInt64Key struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewUInt64Key creates a new Key for uint64 values.
|
||||
func NewUInt64Key(name, description string) *UInt64Key {
|
||||
return &UInt64Key{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *UInt64Key) Name() string { return k.name }
|
||||
func (k *UInt64Key) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *UInt64Key) Of(v uint64) Tag { return Tag{Key: k, packed: v} }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *UInt64Key) Get(tags TagMap) uint64 {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *UInt64Key) From(t Tag) uint64 { return t.packed }
|
||||
|
||||
// Float32Key represents a key
|
||||
type Float32Key struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewFloat32Key creates a new Key for float32 values.
|
||||
func NewFloat32Key(name, description string) *Float32Key {
|
||||
return &Float32Key{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *Float32Key) Name() string { return k.name }
|
||||
func (k *Float32Key) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *Float32Key) Of(v float32) Tag {
|
||||
return Tag{Key: k, packed: uint64(math.Float32bits(v))}
|
||||
}
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *Float32Key) Get(tags TagMap) float32 {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *Float32Key) From(t Tag) float32 {
|
||||
return math.Float32frombits(uint32(t.packed))
|
||||
}
|
||||
|
||||
// Float64Key represents a key
|
||||
type Float64Key struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewFloat64Key creates a new Key for int64 values.
|
||||
func NewFloat64Key(name, description string) *Float64Key {
|
||||
return &Float64Key{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *Float64Key) Name() string { return k.name }
|
||||
func (k *Float64Key) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *Float64Key) Of(v float64) Tag {
|
||||
return Tag{Key: k, packed: math.Float64bits(v)}
|
||||
}
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *Float64Key) Get(tags TagMap) float64 {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *Float64Key) From(t Tag) float64 {
|
||||
return math.Float64frombits(t.packed)
|
||||
}
|
||||
|
||||
// StringKey represents a key
|
||||
type StringKey struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewStringKey creates a new Key for int64 values.
|
||||
func NewStringKey(name, description string) *StringKey {
|
||||
return &StringKey{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *StringKey) Name() string { return k.name }
|
||||
func (k *StringKey) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *StringKey) Of(v string) Tag { return Tag{Key: k, str: v} }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *StringKey) Get(tags TagMap) string {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *StringKey) From(t Tag) string { return t.str }
|
||||
|
||||
// BooleanKey represents a key
|
||||
type BooleanKey struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewBooleanKey creates a new Key for bool values.
|
||||
func NewBooleanKey(name, description string) *BooleanKey {
|
||||
return &BooleanKey{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *BooleanKey) Name() string { return k.name }
|
||||
func (k *BooleanKey) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *BooleanKey) Of(v bool) Tag {
|
||||
t := Tag{Key: k}
|
||||
if v {
|
||||
t.packed = 1
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *BooleanKey) Get(tags TagMap) bool {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *BooleanKey) From(t Tag) bool { return t.packed > 0 }
|
||||
|
||||
// ErrorKey represents a key
|
||||
type ErrorKey struct {
|
||||
name string
|
||||
description string
|
||||
}
|
||||
|
||||
// NewErrorKey creates a new Key for int64 values.
|
||||
func NewErrorKey(name, description string) *ErrorKey {
|
||||
return &ErrorKey{name: name, description: description}
|
||||
}
|
||||
|
||||
func (k *ErrorKey) Name() string { return k.name }
|
||||
func (k *ErrorKey) Description() string { return k.description }
|
||||
|
||||
// Of creates a new Tag with this key and the supplied value.
|
||||
func (k *ErrorKey) Of(v error) Tag { return Tag{Key: k, untyped: v} }
|
||||
|
||||
// Get can be used to get a tag for the key from a TagMap.
|
||||
func (k *ErrorKey) Get(tags TagMap) error {
|
||||
if t := tags.Find(k); t.Valid() {
|
||||
return k.From(t)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// From can be used to get a value from a Tag.
|
||||
func (k *ErrorKey) From(t Tag) error {
|
||||
err, _ := t.untyped.(error)
|
||||
return err
|
||||
}
|
29
vendor/golang.org/x/tools/internal/telemetry/event/label.go
generated
vendored
Normal file
29
vendor/golang.org/x/tools/internal/telemetry/event/label.go
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
// Label sends a label event to the exporter with the supplied tags.
|
||||
func Label(ctx context.Context, tags ...Tag) context.Context {
|
||||
return dispatch(ctx, makeEvent(LabelType, sTags{}, tags))
|
||||
}
|
||||
|
||||
// Label1 sends a label event to the exporter with the supplied tags.
|
||||
func Label1(ctx context.Context, t1 Tag) context.Context {
|
||||
return dispatch(ctx, makeEvent(LabelType, sTags{t1}, nil))
|
||||
}
|
||||
|
||||
// Label2 sends a label event to the exporter with the supplied tags.
|
||||
func Label2(ctx context.Context, t1, t2 Tag) context.Context {
|
||||
return dispatch(ctx, makeEvent(LabelType, sTags{t1, t2}, nil))
|
||||
}
|
||||
|
||||
// Label3 sends a label event to the exporter with the supplied tags.
|
||||
func Label3(ctx context.Context, t1, t2, t3 Tag) context.Context {
|
||||
return dispatch(ctx, makeEvent(LabelType, sTags{t1, t2, t3}, nil))
|
||||
}
|
59
vendor/golang.org/x/tools/internal/telemetry/event/log.go
generated
vendored
Normal file
59
vendor/golang.org/x/tools/internal/telemetry/event/log.go
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
// 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"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Log sends a log event with the supplied tag list to the exporter.
|
||||
func Log(ctx context.Context, tags ...Tag) {
|
||||
dispatch(ctx, makeEvent(LogType, sTags{}, tags))
|
||||
}
|
||||
|
||||
// Log1 sends a label event to the exporter with the supplied tags.
|
||||
func Log1(ctx context.Context, t1 Tag) context.Context {
|
||||
return dispatch(ctx, makeEvent(LogType, sTags{t1}, nil))
|
||||
}
|
||||
|
||||
// Log2 sends a label event to the exporter with the supplied tags.
|
||||
func Log2(ctx context.Context, t1, t2 Tag) context.Context {
|
||||
return dispatch(ctx, makeEvent(LogType, sTags{t1, t2}, nil))
|
||||
}
|
||||
|
||||
// Log3 sends a label event to the exporter with the supplied tags.
|
||||
func Log3(ctx context.Context, t1, t2, t3 Tag) context.Context {
|
||||
return dispatch(ctx, makeEvent(LogType, sTags{t1, t2, t3}, nil))
|
||||
}
|
||||
|
||||
// Print takes a message and a tag list and combines them into a single event
|
||||
// before delivering them to the exporter.
|
||||
func Print(ctx context.Context, message string, tags ...Tag) {
|
||||
dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(message)}, tags))
|
||||
}
|
||||
|
||||
// Print1 takes a message and one tag delivers a log event to the exporter.
|
||||
// It is a customized version of Print that is faster and does no allocation.
|
||||
func Print1(ctx context.Context, message string, t1 Tag) {
|
||||
dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(message), t1}, nil))
|
||||
}
|
||||
|
||||
// Print2 takes a message and two tags and delivers a log event to the exporter.
|
||||
// It is a customized version of Print that is faster and does no allocation.
|
||||
func Print2(ctx context.Context, message string, t1 Tag, t2 Tag) {
|
||||
dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(message), t1, t2}, nil))
|
||||
}
|
||||
|
||||
// Error takes a message and a tag 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, tags ...Tag) {
|
||||
if err == nil {
|
||||
err = errors.New(message)
|
||||
message = ""
|
||||
}
|
||||
dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(message), Err.Of(err)}, tags))
|
||||
}
|
29
vendor/golang.org/x/tools/internal/telemetry/event/metric.go
generated
vendored
Normal file
29
vendor/golang.org/x/tools/internal/telemetry/event/metric.go
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
// Record sends a label event to the exporter with the supplied tags.
|
||||
func Record(ctx context.Context, tags ...Tag) context.Context {
|
||||
return dispatch(ctx, makeEvent(RecordType, sTags{}, tags))
|
||||
}
|
||||
|
||||
// Record1 sends a label event to the exporter with the supplied tags.
|
||||
func Record1(ctx context.Context, t1 Tag) context.Context {
|
||||
return dispatch(ctx, makeEvent(RecordType, sTags{t1}, nil))
|
||||
}
|
||||
|
||||
// Record2 sends a label event to the exporter with the supplied tags.
|
||||
func Record2(ctx context.Context, t1, t2 Tag) context.Context {
|
||||
return dispatch(ctx, makeEvent(RecordType, sTags{t1, t2}, nil))
|
||||
}
|
||||
|
||||
// Record3 sends a label event to the exporter with the supplied tags.
|
||||
func Record3(ctx context.Context, t1, t2, t3 Tag) context.Context {
|
||||
return dispatch(ctx, makeEvent(RecordType, sTags{t1, t2, t3}, nil))
|
||||
}
|
168
vendor/golang.org/x/tools/internal/telemetry/event/tag.go
generated
vendored
Normal file
168
vendor/golang.org/x/tools/internal/telemetry/event/tag.go
generated
vendored
Normal file
@ -0,0 +1,168 @@
|
||||
// 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 (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Tag holds a key and value pair.
|
||||
// It is normally used when passing around lists of tags.
|
||||
type Tag struct {
|
||||
Key Key
|
||||
packed uint64
|
||||
str string
|
||||
untyped interface{}
|
||||
}
|
||||
|
||||
// TagMap is the interface to a collection of Tags indexed by key.
|
||||
type TagMap interface {
|
||||
// Find returns the tag that matches the supplied key.
|
||||
Find(key interface{}) Tag
|
||||
}
|
||||
|
||||
// TagList is the interface to something that provides an iterable
|
||||
// list of tags.
|
||||
// Iteration should start from 0 and continue until Valid returns false.
|
||||
type TagList interface {
|
||||
// Valid returns true if the index is within range for the list.
|
||||
// It does not imply the tag at that index will itself be valid.
|
||||
Valid(index int) bool
|
||||
// Tag returns the tag at the given index.
|
||||
Tag(index int) Tag
|
||||
}
|
||||
|
||||
// tagList implements TagList for a list of Tags.
|
||||
type tagList struct {
|
||||
tags []Tag
|
||||
}
|
||||
|
||||
// tagFilter wraps a TagList filtering out specific tags.
|
||||
type tagFilter struct {
|
||||
keys []Key
|
||||
underlying TagList
|
||||
}
|
||||
|
||||
// tagMap implements TagMap for a simple list of tags.
|
||||
type tagMap struct {
|
||||
tags []Tag
|
||||
}
|
||||
|
||||
// tagMapChain implements TagMap for a list of underlying TagMap.
|
||||
type tagMapChain struct {
|
||||
maps []TagMap
|
||||
}
|
||||
|
||||
// Valid returns true if the Tag is a valid one (it has a key).
|
||||
func (t Tag) Valid() bool { return t.Key != nil }
|
||||
|
||||
// Format is used for debug printing of tags.
|
||||
func (t Tag) Format(f fmt.State, r rune) {
|
||||
if !t.Valid() {
|
||||
fmt.Fprintf(f, `nil`)
|
||||
return
|
||||
}
|
||||
switch key := t.Key.(type) {
|
||||
case *IntKey:
|
||||
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||
case *Int8Key:
|
||||
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||
case *Int16Key:
|
||||
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||
case *Int32Key:
|
||||
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||
case *Int64Key:
|
||||
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||
case *UIntKey:
|
||||
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||
case *UInt8Key:
|
||||
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||
case *UInt16Key:
|
||||
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||
case *UInt32Key:
|
||||
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||
case *UInt64Key:
|
||||
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||
case *Float32Key:
|
||||
fmt.Fprintf(f, "%s=%g", key.Name(), key.From(t))
|
||||
case *Float64Key:
|
||||
fmt.Fprintf(f, "%s=%g", key.Name(), key.From(t))
|
||||
case *BooleanKey:
|
||||
fmt.Fprintf(f, "%s=%t", key.Name(), key.From(t))
|
||||
case *StringKey:
|
||||
fmt.Fprintf(f, "%s=%q", key.Name(), key.From(t))
|
||||
case *ErrorKey:
|
||||
fmt.Fprintf(f, "%s=%v", key.Name(), key.From(t))
|
||||
case *ValueKey:
|
||||
fmt.Fprintf(f, "%s=%v", key.Name(), key.From(t))
|
||||
default:
|
||||
fmt.Fprintf(f, `%s="invalid type %T"`, key.Name(), key)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *tagList) Valid(index int) bool {
|
||||
return index >= 0 && index < len(l.tags)
|
||||
}
|
||||
|
||||
func (l *tagList) Tag(index int) Tag {
|
||||
return l.tags[index]
|
||||
}
|
||||
|
||||
func (f *tagFilter) Valid(index int) bool {
|
||||
return f.underlying.Valid(index)
|
||||
}
|
||||
|
||||
func (f *tagFilter) Tag(index int) Tag {
|
||||
tag := f.underlying.Tag(index)
|
||||
for _, f := range f.keys {
|
||||
if tag.Key == f {
|
||||
return Tag{}
|
||||
}
|
||||
}
|
||||
return tag
|
||||
}
|
||||
|
||||
func (l tagMap) Find(key interface{}) Tag {
|
||||
for _, tag := range l.tags {
|
||||
if tag.Key == key {
|
||||
return tag
|
||||
}
|
||||
}
|
||||
return Tag{}
|
||||
}
|
||||
|
||||
func (c tagMapChain) Find(key interface{}) Tag {
|
||||
for _, src := range c.maps {
|
||||
tag := src.Find(key)
|
||||
if tag.Valid() {
|
||||
return tag
|
||||
}
|
||||
}
|
||||
return Tag{}
|
||||
}
|
||||
|
||||
var emptyList = &tagList{}
|
||||
|
||||
func NewTagList(tags ...Tag) TagList {
|
||||
if len(tags) == 0 {
|
||||
return emptyList
|
||||
}
|
||||
return &tagList{tags: tags}
|
||||
}
|
||||
|
||||
func Filter(l TagList, keys ...Key) TagList {
|
||||
if len(keys) == 0 {
|
||||
return l
|
||||
}
|
||||
return &tagFilter{keys: keys, underlying: l}
|
||||
}
|
||||
|
||||
func NewTagMap(tags ...Tag) TagMap {
|
||||
return tagMap{tags: tags}
|
||||
}
|
||||
|
||||
func MergeTagMaps(srcs ...TagMap) TagMap {
|
||||
return tagMapChain{maps: srcs}
|
||||
}
|
42
vendor/golang.org/x/tools/internal/telemetry/event/trace.go
generated
vendored
Normal file
42
vendor/golang.org/x/tools/internal/telemetry/event/trace.go
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
// StartSpan sends a span start event with the supplied tag list to the exporter.
|
||||
// It also returns a function that will end the span, which should normally be
|
||||
// deferred.
|
||||
func StartSpan(ctx context.Context, name string, tags ...Tag) (context.Context, func()) {
|
||||
return dispatchPair(ctx,
|
||||
makeEvent(StartSpanType, sTags{Name.Of(name)}, tags),
|
||||
makeEvent(EndSpanType, sTags{}, nil))
|
||||
}
|
||||
|
||||
// StartSpan1 sends a span start event with the supplied tag list to the exporter.
|
||||
// It also returns a function that will end the span, which should normally be
|
||||
// deferred.
|
||||
func StartSpan1(ctx context.Context, name string, t1 Tag) (context.Context, func()) {
|
||||
return dispatchPair(ctx,
|
||||
makeEvent(StartSpanType, sTags{Name.Of(name), t1}, nil),
|
||||
makeEvent(EndSpanType, sTags{}, nil))
|
||||
}
|
||||
|
||||
// StartSpan2 sends a span start event with the supplied tag list to the exporter.
|
||||
// It also returns a function that will end the span, which should normally be
|
||||
// deferred.
|
||||
func StartSpan2(ctx context.Context, name string, t1, t2 Tag) (context.Context, func()) {
|
||||
return dispatchPair(ctx,
|
||||
makeEvent(StartSpanType, sTags{Name.Of(name), t1, t2}, nil),
|
||||
makeEvent(EndSpanType, sTags{}, nil))
|
||||
}
|
||||
|
||||
// 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 dispatch(ctx, makeEvent(DetachType, sTags{}, nil))
|
||||
}
|
Reference in New Issue
Block a user