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-unixfs
Commits
a3a84375
Commit
a3a84375
authored
10 years ago
by
Matt Bell
Committed by
Juan Batiz-Benet
10 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: Added marshalling to Response
parent
95b0dd29
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
2 deletions
+33
-2
commands/response.go
commands/response.go
+33
-2
No files found.
commands/response.go
View file @
a3a84375
package
commands
import
(
"fmt"
"strings"
"encoding/json"
"encoding/xml"
)
type
ErrorType
uint
const
(
Normal
ErrorType
=
iota
// general errors
...
...
@@ -13,6 +20,19 @@ type Error struct {
code
ErrorType
}
type
EncodingType
string
const
(
Json
=
"json"
Xml
=
"xml"
// TODO: support more encoding types
)
type
Marshaller
func
(
v
interface
{})([]
byte
,
error
)
var
marshallers
=
map
[
EncodingType
]
Marshaller
{
Json
:
json
.
Marshal
,
Xml
:
xml
.
Marshal
,
}
type
Response
struct
{
req
*
Request
Error
error
...
...
@@ -29,6 +49,17 @@ func (r *Response) FormatError() Error {
return
Error
{
r
.
Error
.
Error
(),
r
.
ErrorType
}
}
/*func (r *Response) Encode() ([]byte, error) {
func
(
r
*
Response
)
Marshal
()
([]
byte
,
error
)
{
enc
:=
r
.
req
.
Option
(
"enc"
)
if
enc
==
nil
{
return
nil
,
fmt
.
Errorf
(
"No encoding type was specified"
)
}
encType
:=
EncodingType
(
strings
.
ToLower
(
enc
.
(
string
)))
}*/
marshaller
,
ok
:=
marshallers
[
encType
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"No marshaller found for encoding type '%s'"
,
enc
)
}
return
marshaller
(
r
.
Value
)
}
This diff is collapsed.
Click to expand it.
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