mirror of
https://github.com/distribution/distribution.git
synced 2025-09-03 07:54:41 +00:00
Update Azure SDK and support additional authentication schemes
Microsoft has updated the golang Azure SDK significantly. Update the azure storage driver to use the new SDK. Add support for client secret and MSI authentication schemes in addition to shared key authentication. Implement rootDirectory support for the azure storage driver to mirror the S3 driver. Signed-off-by: Kirat Singh <kirat.singh@beacon.io> Co-authored-by: Cory Snider <corhere@gmail.com>
This commit is contained in:
202
vendor/github.com/kylelemons/godebug/LICENSE
generated
vendored
Normal file
202
vendor/github.com/kylelemons/godebug/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
186
vendor/github.com/kylelemons/godebug/diff/diff.go
generated
vendored
Normal file
186
vendor/github.com/kylelemons/godebug/diff/diff.go
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
// Copyright 2013 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package diff implements a linewise diff algorithm.
|
||||
package diff
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Chunk represents a piece of the diff. A chunk will not have both added and
|
||||
// deleted lines. Equal lines are always after any added or deleted lines.
|
||||
// A Chunk may or may not have any lines in it, especially for the first or last
|
||||
// chunk in a computation.
|
||||
type Chunk struct {
|
||||
Added []string
|
||||
Deleted []string
|
||||
Equal []string
|
||||
}
|
||||
|
||||
func (c *Chunk) empty() bool {
|
||||
return len(c.Added) == 0 && len(c.Deleted) == 0 && len(c.Equal) == 0
|
||||
}
|
||||
|
||||
// Diff returns a string containing a line-by-line unified diff of the linewise
|
||||
// changes required to make A into B. Each line is prefixed with '+', '-', or
|
||||
// ' ' to indicate if it should be added, removed, or is correct respectively.
|
||||
func Diff(A, B string) string {
|
||||
aLines := strings.Split(A, "\n")
|
||||
bLines := strings.Split(B, "\n")
|
||||
|
||||
chunks := DiffChunks(aLines, bLines)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
for _, c := range chunks {
|
||||
for _, line := range c.Added {
|
||||
fmt.Fprintf(buf, "+%s\n", line)
|
||||
}
|
||||
for _, line := range c.Deleted {
|
||||
fmt.Fprintf(buf, "-%s\n", line)
|
||||
}
|
||||
for _, line := range c.Equal {
|
||||
fmt.Fprintf(buf, " %s\n", line)
|
||||
}
|
||||
}
|
||||
return strings.TrimRight(buf.String(), "\n")
|
||||
}
|
||||
|
||||
// DiffChunks uses an O(D(N+M)) shortest-edit-script algorithm
|
||||
// to compute the edits required from A to B and returns the
|
||||
// edit chunks.
|
||||
func DiffChunks(a, b []string) []Chunk {
|
||||
// algorithm: http://www.xmailserver.org/diff2.pdf
|
||||
|
||||
// We'll need these quantities a lot.
|
||||
alen, blen := len(a), len(b) // M, N
|
||||
|
||||
// At most, it will require len(a) deletions and len(b) additions
|
||||
// to transform a into b.
|
||||
maxPath := alen + blen // MAX
|
||||
if maxPath == 0 {
|
||||
// degenerate case: two empty lists are the same
|
||||
return nil
|
||||
}
|
||||
|
||||
// Store the endpoint of the path for diagonals.
|
||||
// We store only the a index, because the b index on any diagonal
|
||||
// (which we know during the loop below) is aidx-diag.
|
||||
// endpoint[maxPath] represents the 0 diagonal.
|
||||
//
|
||||
// Stated differently:
|
||||
// endpoint[d] contains the aidx of a furthest reaching path in diagonal d
|
||||
endpoint := make([]int, 2*maxPath+1) // V
|
||||
|
||||
saved := make([][]int, 0, 8) // Vs
|
||||
save := func() {
|
||||
dup := make([]int, len(endpoint))
|
||||
copy(dup, endpoint)
|
||||
saved = append(saved, dup)
|
||||
}
|
||||
|
||||
var editDistance int // D
|
||||
dLoop:
|
||||
for editDistance = 0; editDistance <= maxPath; editDistance++ {
|
||||
// The 0 diag(onal) represents equality of a and b. Each diagonal to
|
||||
// the left is numbered one lower, to the right is one higher, from
|
||||
// -alen to +blen. Negative diagonals favor differences from a,
|
||||
// positive diagonals favor differences from b. The edit distance to a
|
||||
// diagonal d cannot be shorter than d itself.
|
||||
//
|
||||
// The iterations of this loop cover either odds or evens, but not both,
|
||||
// If odd indices are inputs, even indices are outputs and vice versa.
|
||||
for diag := -editDistance; diag <= editDistance; diag += 2 { // k
|
||||
var aidx int // x
|
||||
switch {
|
||||
case diag == -editDistance:
|
||||
// This is a new diagonal; copy from previous iter
|
||||
aidx = endpoint[maxPath-editDistance+1] + 0
|
||||
case diag == editDistance:
|
||||
// This is a new diagonal; copy from previous iter
|
||||
aidx = endpoint[maxPath+editDistance-1] + 1
|
||||
case endpoint[maxPath+diag+1] > endpoint[maxPath+diag-1]:
|
||||
// diagonal d+1 was farther along, so use that
|
||||
aidx = endpoint[maxPath+diag+1] + 0
|
||||
default:
|
||||
// diagonal d-1 was farther (or the same), so use that
|
||||
aidx = endpoint[maxPath+diag-1] + 1
|
||||
}
|
||||
// On diagonal d, we can compute bidx from aidx.
|
||||
bidx := aidx - diag // y
|
||||
// See how far we can go on this diagonal before we find a difference.
|
||||
for aidx < alen && bidx < blen && a[aidx] == b[bidx] {
|
||||
aidx++
|
||||
bidx++
|
||||
}
|
||||
// Store the end of the current edit chain.
|
||||
endpoint[maxPath+diag] = aidx
|
||||
// If we've found the end of both inputs, we're done!
|
||||
if aidx >= alen && bidx >= blen {
|
||||
save() // save the final path
|
||||
break dLoop
|
||||
}
|
||||
}
|
||||
save() // save the current path
|
||||
}
|
||||
if editDistance == 0 {
|
||||
return nil
|
||||
}
|
||||
chunks := make([]Chunk, editDistance+1)
|
||||
|
||||
x, y := alen, blen
|
||||
for d := editDistance; d > 0; d-- {
|
||||
endpoint := saved[d]
|
||||
diag := x - y
|
||||
insert := diag == -d || (diag != d && endpoint[maxPath+diag-1] < endpoint[maxPath+diag+1])
|
||||
|
||||
x1 := endpoint[maxPath+diag]
|
||||
var x0, xM, kk int
|
||||
if insert {
|
||||
kk = diag + 1
|
||||
x0 = endpoint[maxPath+kk]
|
||||
xM = x0
|
||||
} else {
|
||||
kk = diag - 1
|
||||
x0 = endpoint[maxPath+kk]
|
||||
xM = x0 + 1
|
||||
}
|
||||
y0 := x0 - kk
|
||||
|
||||
var c Chunk
|
||||
if insert {
|
||||
c.Added = b[y0:][:1]
|
||||
} else {
|
||||
c.Deleted = a[x0:][:1]
|
||||
}
|
||||
if xM < x1 {
|
||||
c.Equal = a[xM:][:x1-xM]
|
||||
}
|
||||
|
||||
x, y = x0, y0
|
||||
chunks[d] = c
|
||||
}
|
||||
if x > 0 {
|
||||
chunks[0].Equal = a[:x]
|
||||
}
|
||||
if chunks[0].empty() {
|
||||
chunks = chunks[1:]
|
||||
}
|
||||
if len(chunks) == 0 {
|
||||
return nil
|
||||
}
|
||||
return chunks
|
||||
}
|
5
vendor/github.com/kylelemons/godebug/pretty/.gitignore
generated
vendored
Normal file
5
vendor/github.com/kylelemons/godebug/pretty/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
*.test
|
||||
*.bench
|
||||
*.golden
|
||||
*.txt
|
||||
*.prof
|
25
vendor/github.com/kylelemons/godebug/pretty/doc.go
generated
vendored
Normal file
25
vendor/github.com/kylelemons/godebug/pretty/doc.go
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2013 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package pretty pretty-prints Go structures.
|
||||
//
|
||||
// This package uses reflection to examine a Go value and can
|
||||
// print out in a nice, aligned fashion. It supports three
|
||||
// modes (normal, compact, and extended) for advanced use.
|
||||
//
|
||||
// See the Reflect and Print examples for what the output looks like.
|
||||
package pretty
|
||||
|
||||
// TODO:
|
||||
// - Catch cycles
|
188
vendor/github.com/kylelemons/godebug/pretty/public.go
generated
vendored
Normal file
188
vendor/github.com/kylelemons/godebug/pretty/public.go
generated
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
// Copyright 2013 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package pretty
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/kylelemons/godebug/diff"
|
||||
)
|
||||
|
||||
// A Config represents optional configuration parameters for formatting.
|
||||
//
|
||||
// Some options, notably ShortList, dramatically increase the overhead
|
||||
// of pretty-printing a value.
|
||||
type Config struct {
|
||||
// Verbosity options
|
||||
Compact bool // One-line output. Overrides Diffable.
|
||||
Diffable bool // Adds extra newlines for more easily diffable output.
|
||||
|
||||
// Field and value options
|
||||
IncludeUnexported bool // Include unexported fields in output
|
||||
PrintStringers bool // Call String on a fmt.Stringer
|
||||
PrintTextMarshalers bool // Call MarshalText on an encoding.TextMarshaler
|
||||
SkipZeroFields bool // Skip struct fields that have a zero value.
|
||||
|
||||
// Output transforms
|
||||
ShortList int // Maximum character length for short lists if nonzero.
|
||||
|
||||
// Type-specific overrides
|
||||
//
|
||||
// Formatter maps a type to a function that will provide a one-line string
|
||||
// representation of the input value. Conceptually:
|
||||
// Formatter[reflect.TypeOf(v)](v) = "v as a string"
|
||||
//
|
||||
// Note that the first argument need not explicitly match the type, it must
|
||||
// merely be callable with it.
|
||||
//
|
||||
// When processing an input value, if its type exists as a key in Formatter:
|
||||
// 1) If the value is nil, no stringification is performed.
|
||||
// This allows overriding of PrintStringers and PrintTextMarshalers.
|
||||
// 2) The value will be called with the input as its only argument.
|
||||
// The function must return a string as its first return value.
|
||||
//
|
||||
// In addition to func literals, two common values for this will be:
|
||||
// fmt.Sprint (function) func Sprint(...interface{}) string
|
||||
// Type.String (method) func (Type) String() string
|
||||
//
|
||||
// Note that neither of these work if the String method is a pointer
|
||||
// method and the input will be provided as a value. In that case,
|
||||
// use a function that calls .String on the formal value parameter.
|
||||
Formatter map[reflect.Type]interface{}
|
||||
|
||||
// If TrackCycles is enabled, pretty will detect and track
|
||||
// self-referential structures. If a self-referential structure (aka a
|
||||
// "recursive" value) is detected, numbered placeholders will be emitted.
|
||||
//
|
||||
// Pointer tracking is disabled by default for performance reasons.
|
||||
TrackCycles bool
|
||||
}
|
||||
|
||||
// Default Config objects
|
||||
var (
|
||||
// DefaultFormatter is the default set of overrides for stringification.
|
||||
DefaultFormatter = map[reflect.Type]interface{}{
|
||||
reflect.TypeOf(time.Time{}): fmt.Sprint,
|
||||
reflect.TypeOf(net.IP{}): fmt.Sprint,
|
||||
reflect.TypeOf((*error)(nil)).Elem(): fmt.Sprint,
|
||||
}
|
||||
|
||||
// CompareConfig is the default configuration used for Compare.
|
||||
CompareConfig = &Config{
|
||||
Diffable: true,
|
||||
IncludeUnexported: true,
|
||||
Formatter: DefaultFormatter,
|
||||
}
|
||||
|
||||
// DefaultConfig is the default configuration used for all other top-level functions.
|
||||
DefaultConfig = &Config{
|
||||
Formatter: DefaultFormatter,
|
||||
}
|
||||
|
||||
// CycleTracker is a convenience config for formatting and comparing recursive structures.
|
||||
CycleTracker = &Config{
|
||||
Diffable: true,
|
||||
Formatter: DefaultFormatter,
|
||||
TrackCycles: true,
|
||||
}
|
||||
)
|
||||
|
||||
func (cfg *Config) fprint(buf *bytes.Buffer, vals ...interface{}) {
|
||||
ref := &reflector{
|
||||
Config: cfg,
|
||||
}
|
||||
if cfg.TrackCycles {
|
||||
ref.pointerTracker = new(pointerTracker)
|
||||
}
|
||||
for i, val := range vals {
|
||||
if i > 0 {
|
||||
buf.WriteByte('\n')
|
||||
}
|
||||
newFormatter(cfg, buf).write(ref.val2node(reflect.ValueOf(val)))
|
||||
}
|
||||
}
|
||||
|
||||
// Print writes the DefaultConfig representation of the given values to standard output.
|
||||
func Print(vals ...interface{}) {
|
||||
DefaultConfig.Print(vals...)
|
||||
}
|
||||
|
||||
// Print writes the configured presentation of the given values to standard output.
|
||||
func (cfg *Config) Print(vals ...interface{}) {
|
||||
fmt.Println(cfg.Sprint(vals...))
|
||||
}
|
||||
|
||||
// Sprint returns a string representation of the given value according to the DefaultConfig.
|
||||
func Sprint(vals ...interface{}) string {
|
||||
return DefaultConfig.Sprint(vals...)
|
||||
}
|
||||
|
||||
// Sprint returns a string representation of the given value according to cfg.
|
||||
func (cfg *Config) Sprint(vals ...interface{}) string {
|
||||
buf := new(bytes.Buffer)
|
||||
cfg.fprint(buf, vals...)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// Fprint writes the representation of the given value to the writer according to the DefaultConfig.
|
||||
func Fprint(w io.Writer, vals ...interface{}) (n int64, err error) {
|
||||
return DefaultConfig.Fprint(w, vals...)
|
||||
}
|
||||
|
||||
// Fprint writes the representation of the given value to the writer according to the cfg.
|
||||
func (cfg *Config) Fprint(w io.Writer, vals ...interface{}) (n int64, err error) {
|
||||
buf := new(bytes.Buffer)
|
||||
cfg.fprint(buf, vals...)
|
||||
return buf.WriteTo(w)
|
||||
}
|
||||
|
||||
// Compare returns a string containing a line-by-line unified diff of the
|
||||
// values in a and b, using the CompareConfig.
|
||||
//
|
||||
// Each line in the output is prefixed with '+', '-', or ' ' to indicate which
|
||||
// side it's from. Lines from the a side are marked with '-', lines from the
|
||||
// b side are marked with '+' and lines that are the same on both sides are
|
||||
// marked with ' '.
|
||||
//
|
||||
// The comparison is based on the intentionally-untyped output of Print, and as
|
||||
// such this comparison is pretty forviving. In particular, if the types of or
|
||||
// types within in a and b are different but have the same representation,
|
||||
// Compare will not indicate any differences between them.
|
||||
func Compare(a, b interface{}) string {
|
||||
return CompareConfig.Compare(a, b)
|
||||
}
|
||||
|
||||
// Compare returns a string containing a line-by-line unified diff of the
|
||||
// values in got and want according to the cfg.
|
||||
//
|
||||
// Each line in the output is prefixed with '+', '-', or ' ' to indicate which
|
||||
// side it's from. Lines from the a side are marked with '-', lines from the
|
||||
// b side are marked with '+' and lines that are the same on both sides are
|
||||
// marked with ' '.
|
||||
//
|
||||
// The comparison is based on the intentionally-untyped output of Print, and as
|
||||
// such this comparison is pretty forviving. In particular, if the types of or
|
||||
// types within in a and b are different but have the same representation,
|
||||
// Compare will not indicate any differences between them.
|
||||
func (cfg *Config) Compare(a, b interface{}) string {
|
||||
diffCfg := *cfg
|
||||
diffCfg.Diffable = true
|
||||
return diff.Diff(cfg.Sprint(a), cfg.Sprint(b))
|
||||
}
|
241
vendor/github.com/kylelemons/godebug/pretty/reflect.go
generated
vendored
Normal file
241
vendor/github.com/kylelemons/godebug/pretty/reflect.go
generated
vendored
Normal file
@@ -0,0 +1,241 @@
|
||||
// Copyright 2013 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package pretty
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func isZeroVal(val reflect.Value) bool {
|
||||
if !val.CanInterface() {
|
||||
return false
|
||||
}
|
||||
z := reflect.Zero(val.Type()).Interface()
|
||||
return reflect.DeepEqual(val.Interface(), z)
|
||||
}
|
||||
|
||||
// pointerTracker is a helper for tracking pointer chasing to detect cycles.
|
||||
type pointerTracker struct {
|
||||
addrs map[uintptr]int // addr[address] = seen count
|
||||
|
||||
lastID int
|
||||
ids map[uintptr]int // ids[address] = id
|
||||
}
|
||||
|
||||
// track tracks following a reference (pointer, slice, map, etc). Every call to
|
||||
// track should be paired with a call to untrack.
|
||||
func (p *pointerTracker) track(ptr uintptr) {
|
||||
if p.addrs == nil {
|
||||
p.addrs = make(map[uintptr]int)
|
||||
}
|
||||
p.addrs[ptr]++
|
||||
}
|
||||
|
||||
// untrack registers that we have backtracked over the reference to the pointer.
|
||||
func (p *pointerTracker) untrack(ptr uintptr) {
|
||||
p.addrs[ptr]--
|
||||
if p.addrs[ptr] == 0 {
|
||||
delete(p.addrs, ptr)
|
||||
}
|
||||
}
|
||||
|
||||
// seen returns whether the pointer was previously seen along this path.
|
||||
func (p *pointerTracker) seen(ptr uintptr) bool {
|
||||
_, ok := p.addrs[ptr]
|
||||
return ok
|
||||
}
|
||||
|
||||
// keep allocates an ID for the given address and returns it.
|
||||
func (p *pointerTracker) keep(ptr uintptr) int {
|
||||
if p.ids == nil {
|
||||
p.ids = make(map[uintptr]int)
|
||||
}
|
||||
if _, ok := p.ids[ptr]; !ok {
|
||||
p.lastID++
|
||||
p.ids[ptr] = p.lastID
|
||||
}
|
||||
return p.ids[ptr]
|
||||
}
|
||||
|
||||
// id returns the ID for the given address.
|
||||
func (p *pointerTracker) id(ptr uintptr) (int, bool) {
|
||||
if p.ids == nil {
|
||||
p.ids = make(map[uintptr]int)
|
||||
}
|
||||
id, ok := p.ids[ptr]
|
||||
return id, ok
|
||||
}
|
||||
|
||||
// reflector adds local state to the recursive reflection logic.
|
||||
type reflector struct {
|
||||
*Config
|
||||
*pointerTracker
|
||||
}
|
||||
|
||||
// follow handles following a possiblly-recursive reference to the given value
|
||||
// from the given ptr address.
|
||||
func (r *reflector) follow(ptr uintptr, val reflect.Value) node {
|
||||
if r.pointerTracker == nil {
|
||||
// Tracking disabled
|
||||
return r.val2node(val)
|
||||
}
|
||||
|
||||
// If a parent already followed this, emit a reference marker
|
||||
if r.seen(ptr) {
|
||||
id := r.keep(ptr)
|
||||
return ref{id}
|
||||
}
|
||||
|
||||
// Track the pointer we're following while on this recursive branch
|
||||
r.track(ptr)
|
||||
defer r.untrack(ptr)
|
||||
n := r.val2node(val)
|
||||
|
||||
// If the recursion used this ptr, wrap it with a target marker
|
||||
if id, ok := r.id(ptr); ok {
|
||||
return target{id, n}
|
||||
}
|
||||
|
||||
// Otherwise, return the node unadulterated
|
||||
return n
|
||||
}
|
||||
|
||||
func (r *reflector) val2node(val reflect.Value) node {
|
||||
if !val.IsValid() {
|
||||
return rawVal("nil")
|
||||
}
|
||||
|
||||
if val.CanInterface() {
|
||||
v := val.Interface()
|
||||
if formatter, ok := r.Formatter[val.Type()]; ok {
|
||||
if formatter != nil {
|
||||
res := reflect.ValueOf(formatter).Call([]reflect.Value{val})
|
||||
return rawVal(res[0].Interface().(string))
|
||||
}
|
||||
} else {
|
||||
if s, ok := v.(fmt.Stringer); ok && r.PrintStringers {
|
||||
return stringVal(s.String())
|
||||
}
|
||||
if t, ok := v.(encoding.TextMarshaler); ok && r.PrintTextMarshalers {
|
||||
if raw, err := t.MarshalText(); err == nil { // if NOT an error
|
||||
return stringVal(string(raw))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch kind := val.Kind(); kind {
|
||||
case reflect.Ptr:
|
||||
if val.IsNil() {
|
||||
return rawVal("nil")
|
||||
}
|
||||
return r.follow(val.Pointer(), val.Elem())
|
||||
case reflect.Interface:
|
||||
if val.IsNil() {
|
||||
return rawVal("nil")
|
||||
}
|
||||
return r.val2node(val.Elem())
|
||||
case reflect.String:
|
||||
return stringVal(val.String())
|
||||
case reflect.Slice:
|
||||
n := list{}
|
||||
length := val.Len()
|
||||
ptr := val.Pointer()
|
||||
for i := 0; i < length; i++ {
|
||||
n = append(n, r.follow(ptr, val.Index(i)))
|
||||
}
|
||||
return n
|
||||
case reflect.Array:
|
||||
n := list{}
|
||||
length := val.Len()
|
||||
for i := 0; i < length; i++ {
|
||||
n = append(n, r.val2node(val.Index(i)))
|
||||
}
|
||||
return n
|
||||
case reflect.Map:
|
||||
// Extract the keys and sort them for stable iteration
|
||||
keys := val.MapKeys()
|
||||
pairs := make([]mapPair, 0, len(keys))
|
||||
for _, key := range keys {
|
||||
pairs = append(pairs, mapPair{
|
||||
key: new(formatter).compactString(r.val2node(key)), // can't be cyclic
|
||||
value: val.MapIndex(key),
|
||||
})
|
||||
}
|
||||
sort.Sort(byKey(pairs))
|
||||
|
||||
// Process the keys into the final representation
|
||||
ptr, n := val.Pointer(), keyvals{}
|
||||
for _, pair := range pairs {
|
||||
n = append(n, keyval{
|
||||
key: pair.key,
|
||||
val: r.follow(ptr, pair.value),
|
||||
})
|
||||
}
|
||||
return n
|
||||
case reflect.Struct:
|
||||
n := keyvals{}
|
||||
typ := val.Type()
|
||||
fields := typ.NumField()
|
||||
for i := 0; i < fields; i++ {
|
||||
sf := typ.Field(i)
|
||||
if !r.IncludeUnexported && sf.PkgPath != "" {
|
||||
continue
|
||||
}
|
||||
field := val.Field(i)
|
||||
if r.SkipZeroFields && isZeroVal(field) {
|
||||
continue
|
||||
}
|
||||
n = append(n, keyval{sf.Name, r.val2node(field)})
|
||||
}
|
||||
return n
|
||||
case reflect.Bool:
|
||||
if val.Bool() {
|
||||
return rawVal("true")
|
||||
}
|
||||
return rawVal("false")
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return rawVal(fmt.Sprintf("%d", val.Int()))
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
return rawVal(fmt.Sprintf("%d", val.Uint()))
|
||||
case reflect.Uintptr:
|
||||
return rawVal(fmt.Sprintf("0x%X", val.Uint()))
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return rawVal(fmt.Sprintf("%v", val.Float()))
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
return rawVal(fmt.Sprintf("%v", val.Complex()))
|
||||
}
|
||||
|
||||
// Fall back to the default %#v if we can
|
||||
if val.CanInterface() {
|
||||
return rawVal(fmt.Sprintf("%#v", val.Interface()))
|
||||
}
|
||||
|
||||
return rawVal(val.String())
|
||||
}
|
||||
|
||||
type mapPair struct {
|
||||
key string
|
||||
value reflect.Value
|
||||
}
|
||||
|
||||
type byKey []mapPair
|
||||
|
||||
func (v byKey) Len() int { return len(v) }
|
||||
func (v byKey) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
|
||||
func (v byKey) Less(i, j int) bool { return v[i].key < v[j].key }
|
223
vendor/github.com/kylelemons/godebug/pretty/structure.go
generated
vendored
Normal file
223
vendor/github.com/kylelemons/godebug/pretty/structure.go
generated
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
// Copyright 2013 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package pretty
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// a formatter stores stateful formatting information as well as being
|
||||
// an io.Writer for simplicity.
|
||||
type formatter struct {
|
||||
*bufio.Writer
|
||||
*Config
|
||||
|
||||
// Self-referential structure tracking
|
||||
tagNumbers map[int]int // tagNumbers[id] = <#n>
|
||||
}
|
||||
|
||||
// newFormatter creates a new buffered formatter. For the output to be written
|
||||
// to the given writer, this must be accompanied by a call to write (or Flush).
|
||||
func newFormatter(cfg *Config, w io.Writer) *formatter {
|
||||
return &formatter{
|
||||
Writer: bufio.NewWriter(w),
|
||||
Config: cfg,
|
||||
tagNumbers: make(map[int]int),
|
||||
}
|
||||
}
|
||||
|
||||
func (f *formatter) write(n node) {
|
||||
defer f.Flush()
|
||||
n.format(f, "")
|
||||
}
|
||||
|
||||
func (f *formatter) tagFor(id int) int {
|
||||
if tag, ok := f.tagNumbers[id]; ok {
|
||||
return tag
|
||||
}
|
||||
if f.tagNumbers == nil {
|
||||
return 0
|
||||
}
|
||||
tag := len(f.tagNumbers) + 1
|
||||
f.tagNumbers[id] = tag
|
||||
return tag
|
||||
}
|
||||
|
||||
type node interface {
|
||||
format(f *formatter, indent string)
|
||||
}
|
||||
|
||||
func (f *formatter) compactString(n node) string {
|
||||
switch k := n.(type) {
|
||||
case stringVal:
|
||||
return string(k)
|
||||
case rawVal:
|
||||
return string(k)
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
f2 := newFormatter(&Config{Compact: true}, buf)
|
||||
f2.tagNumbers = f.tagNumbers // reuse tagNumbers just in case
|
||||
f2.write(n)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
type stringVal string
|
||||
|
||||
func (str stringVal) format(f *formatter, indent string) {
|
||||
f.WriteString(strconv.Quote(string(str)))
|
||||
}
|
||||
|
||||
type rawVal string
|
||||
|
||||
func (r rawVal) format(f *formatter, indent string) {
|
||||
f.WriteString(string(r))
|
||||
}
|
||||
|
||||
type keyval struct {
|
||||
key string
|
||||
val node
|
||||
}
|
||||
|
||||
type keyvals []keyval
|
||||
|
||||
func (l keyvals) format(f *formatter, indent string) {
|
||||
f.WriteByte('{')
|
||||
|
||||
switch {
|
||||
case f.Compact:
|
||||
// All on one line:
|
||||
for i, kv := range l {
|
||||
if i > 0 {
|
||||
f.WriteByte(',')
|
||||
}
|
||||
f.WriteString(kv.key)
|
||||
f.WriteByte(':')
|
||||
kv.val.format(f, indent)
|
||||
}
|
||||
case f.Diffable:
|
||||
f.WriteByte('\n')
|
||||
inner := indent + " "
|
||||
// Each value gets its own line:
|
||||
for _, kv := range l {
|
||||
f.WriteString(inner)
|
||||
f.WriteString(kv.key)
|
||||
f.WriteString(": ")
|
||||
kv.val.format(f, inner)
|
||||
f.WriteString(",\n")
|
||||
}
|
||||
f.WriteString(indent)
|
||||
default:
|
||||
keyWidth := 0
|
||||
for _, kv := range l {
|
||||
if kw := len(kv.key); kw > keyWidth {
|
||||
keyWidth = kw
|
||||
}
|
||||
}
|
||||
alignKey := indent + " "
|
||||
alignValue := strings.Repeat(" ", keyWidth)
|
||||
inner := alignKey + alignValue + " "
|
||||
// First and last line shared with bracket:
|
||||
for i, kv := range l {
|
||||
if i > 0 {
|
||||
f.WriteString(",\n")
|
||||
f.WriteString(alignKey)
|
||||
}
|
||||
f.WriteString(kv.key)
|
||||
f.WriteString(": ")
|
||||
f.WriteString(alignValue[len(kv.key):])
|
||||
kv.val.format(f, inner)
|
||||
}
|
||||
}
|
||||
|
||||
f.WriteByte('}')
|
||||
}
|
||||
|
||||
type list []node
|
||||
|
||||
func (l list) format(f *formatter, indent string) {
|
||||
if max := f.ShortList; max > 0 {
|
||||
short := f.compactString(l)
|
||||
if len(short) <= max {
|
||||
f.WriteString(short)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
f.WriteByte('[')
|
||||
|
||||
switch {
|
||||
case f.Compact:
|
||||
// All on one line:
|
||||
for i, v := range l {
|
||||
if i > 0 {
|
||||
f.WriteByte(',')
|
||||
}
|
||||
v.format(f, indent)
|
||||
}
|
||||
case f.Diffable:
|
||||
f.WriteByte('\n')
|
||||
inner := indent + " "
|
||||
// Each value gets its own line:
|
||||
for _, v := range l {
|
||||
f.WriteString(inner)
|
||||
v.format(f, inner)
|
||||
f.WriteString(",\n")
|
||||
}
|
||||
f.WriteString(indent)
|
||||
default:
|
||||
inner := indent + " "
|
||||
// First and last line shared with bracket:
|
||||
for i, v := range l {
|
||||
if i > 0 {
|
||||
f.WriteString(",\n")
|
||||
f.WriteString(inner)
|
||||
}
|
||||
v.format(f, inner)
|
||||
}
|
||||
}
|
||||
|
||||
f.WriteByte(']')
|
||||
}
|
||||
|
||||
type ref struct {
|
||||
id int
|
||||
}
|
||||
|
||||
func (r ref) format(f *formatter, indent string) {
|
||||
fmt.Fprintf(f, "<see #%d>", f.tagFor(r.id))
|
||||
}
|
||||
|
||||
type target struct {
|
||||
id int
|
||||
value node
|
||||
}
|
||||
|
||||
func (t target) format(f *formatter, indent string) {
|
||||
tag := fmt.Sprintf("<#%d> ", f.tagFor(t.id))
|
||||
switch {
|
||||
case f.Diffable, f.Compact:
|
||||
// no indent changes
|
||||
default:
|
||||
indent += strings.Repeat(" ", len(tag))
|
||||
}
|
||||
f.WriteString(tag)
|
||||
t.value.format(f, indent)
|
||||
}
|
Reference in New Issue
Block a user