Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
a636e44e
Commit
a636e44e
authored
Dec 12, 2014
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a side-by-side diff option for verbose output
Make regular diff better by eliding pointer values
parent
771c5389
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
4 deletions
+48
-4
diff.go
pkg/util/diff.go
+48
-4
No files found.
pkg/util/diff.go
View file @
a636e44e
...
@@ -17,8 +17,11 @@ limitations under the License.
...
@@ -17,8 +17,11 @@ limitations under the License.
package
util
package
util
import
(
import
(
"bytes"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"strings"
"text/tabwriter"
"github.com/davecgh/go-spew/spew"
"github.com/davecgh/go-spew/spew"
)
)
...
@@ -64,13 +67,54 @@ func ObjectDiff(a, b interface{}) string {
...
@@ -64,13 +67,54 @@ func ObjectDiff(a, b interface{}) string {
// can't figure out why reflect.DeepEqual is returning false and nothing is
// can't figure out why reflect.DeepEqual is returning false and nothing is
// showing you differences. This will.
// showing you differences. This will.
func
ObjectGoPrintDiff
(
a
,
b
interface
{})
string
{
func
ObjectGoPrintDiff
(
a
,
b
interface
{})
string
{
return
StringDiff
(
spew
.
Sprintf
(
"%#v"
,
a
),
spew
.
Sprintf
(
"%#v"
,
b
),
)
}
// ObjectGoPrintSideBySide prints a and b as textual dumps side by side,
// enabling easy visual scanning for mismatches.
func
ObjectGoPrintSideBySide
(
a
,
b
interface
{})
string
{
s
:=
spew
.
ConfigState
{
s
:=
spew
.
ConfigState
{
Indent
:
" "
,
Indent
:
" "
,
// Extra deep spew.
// Extra deep spew.
DisableMethods
:
true
,
DisableMethods
:
true
,
}
}
return
StringDiff
(
sA
:=
s
.
Sdump
(
a
)
s
.
Sdump
(
a
),
sB
:=
s
.
Sdump
(
b
)
s
.
Sdump
(
b
),
)
linesA
:=
strings
.
Split
(
sA
,
"
\n
"
)
linesB
:=
strings
.
Split
(
sB
,
"
\n
"
)
width
:=
0
for
_
,
s
:=
range
linesA
{
l
:=
len
(
s
)
if
l
>
width
{
width
=
l
}
}
for
_
,
s
:=
range
linesB
{
l
:=
len
(
s
)
if
l
>
width
{
width
=
l
}
}
buf
:=
&
bytes
.
Buffer
{}
w
:=
tabwriter
.
NewWriter
(
buf
,
width
,
0
,
1
,
' '
,
0
)
max
:=
len
(
linesA
)
if
len
(
linesB
)
>
max
{
max
=
len
(
linesB
)
}
for
i
:=
0
;
i
<
max
;
i
++
{
var
a
,
b
string
if
i
<
len
(
linesA
)
{
a
=
linesA
[
i
]
}
if
i
<
len
(
linesB
)
{
b
=
linesB
[
i
]
}
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\n
"
,
a
,
b
)
}
w
.
Flush
()
return
buf
.
String
()
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment