Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
04119d30
Commit
04119d30
authored
Feb 08, 2018
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make working with arrays easier
parent
e8d80ffd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
encoding_test.go
encoding_test.go
+20
-0
writer.go
writer.go
+4
-0
No files found.
encoding_test.go
View file @
04119d30
...
@@ -35,3 +35,23 @@ func TestMakeTypedEncoder(t *testing.T) {
...
@@ -35,3 +35,23 @@ func TestMakeTypedEncoder(t *testing.T) {
t
.
Fatal
(
"expected: "
,
expErr
)
t
.
Fatal
(
"expected: "
,
expErr
)
}
}
}
}
func
TestMakeTypedEncoderArrays
(
t
*
testing
.
T
)
{
f
:=
MakeTypedEncoder
(
func
(
req
*
Request
,
w
io
.
Writer
,
v
[]
fooTestObj
)
error
{
if
len
(
v
)
!=
2
{
return
fmt
.
Errorf
(
"bad"
)
}
return
nil
})
req
:=
&
Request
{}
encoderFunc
:=
f
(
req
)
buf
:=
new
(
bytes
.
Buffer
)
encoder
:=
encoderFunc
(
buf
)
if
err
:=
encoder
.
Encode
([]
fooTestObj
{{
true
},
{
false
}});
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
writer.go
View file @
04119d30
...
@@ -76,6 +76,10 @@ func (r *readerResponse) RawNext() (interface{}, error) {
...
@@ -76,6 +76,10 @@ func (r *readerResponse) RawNext() (interface{}, error) {
r
.
once
.
Do
(
func
()
{
close
(
r
.
emitted
)
})
r
.
once
.
Do
(
func
()
{
close
(
r
.
emitted
)
})
v
:=
m
.
Get
()
v
:=
m
.
Get
()
// because working with pointers to arrays is annoying
if
t
:=
reflect
.
TypeOf
(
v
);
t
.
Kind
()
==
reflect
.
Ptr
&&
t
.
Elem
()
.
Kind
()
==
reflect
.
Slice
{
v
=
reflect
.
ValueOf
(
v
)
.
Elem
()
.
Interface
()
}
return
v
,
nil
return
v
,
nil
}
}
...
...
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