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
Commits
d6657edf
Unverified
Commit
d6657edf
authored
Jul 12, 2017
by
Jakub Sztandera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make codeclimate a bit more happy
License: MIT Signed-off-by:
Jakub Sztandera
<
kubuxu@protonmail.ch
>
parent
cfad4608
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
+20
-10
core/coredag/dagtransl.go
core/coredag/dagtransl.go
+20
-10
No files found.
core/coredag/dagtransl.go
View file @
d6657edf
...
...
@@ -9,30 +9,38 @@ import (
ipldcbor
"gx/ipfs/QmemYymP73eVdTUUMZEiSpiHeZQKNJdT5dP2iuHssZh1sR/go-ipld-cbor"
)
// DagParser is function used for parsing stream into Node
type
DagParser
func
(
r
io
.
Reader
)
([]
node
.
Node
,
error
)
// FormatParsers is used for mapping format descriptors to DagParsers
type
FormatParsers
map
[
string
]
DagParser
// InputEncParsers is used for mapping input encodings to FormatParsers
type
InputEncParsers
map
[
string
]
FormatParsers
// DefaultInputEncParsers is InputEncParser that is used everywhere
var
DefaultInputEncParsers
=
InputEncParsers
{
"json"
:
D
efaultJsonParsers
,
"raw"
:
D
efaultRawParsers
,
"json"
:
d
efaultJsonParsers
,
"raw"
:
d
efaultRawParsers
,
}
var
D
efaultJsonParsers
=
FormatParsers
{
"cbor"
:
C
borJsonParser
,
"dag-cbor"
:
C
borJsonParser
,
var
d
efaultJsonParsers
=
FormatParsers
{
"cbor"
:
c
borJsonParser
,
"dag-cbor"
:
c
borJsonParser
,
}
var
D
efaultRawParsers
=
FormatParsers
{
"cbor"
:
C
borRawParser
,
"dag-cbor"
:
C
borRawParser
,
var
d
efaultRawParsers
=
FormatParsers
{
"cbor"
:
c
borRawParser
,
"dag-cbor"
:
c
borRawParser
,
}
// ParseInputs uses DefaultInputEncParsers to parse io.Reader described by
// input encoding and format to an instance of ipld Node
func
ParseInputs
(
ienc
,
format
string
,
r
io
.
Reader
)
([]
node
.
Node
,
error
)
{
return
DefaultInputEncParsers
.
ParseInputs
(
ienc
,
format
,
r
)
}
// AddParser adds DagParser under give input encoding and format
func
(
iep
InputEncParsers
)
AddParser
(
ienv
,
format
string
,
f
DagParser
)
{
m
,
ok
:=
iep
[
ienv
]
if
!
ok
{
...
...
@@ -43,6 +51,8 @@ func (iep InputEncParsers) AddParser(ienv, format string, f DagParser) {
m
[
format
]
=
f
}
// ParseInputs parses io.Reader described by input encoding and format to
// an instance of ipld Node
func
(
iep
InputEncParsers
)
ParseInputs
(
ienc
,
format
string
,
r
io
.
Reader
)
([]
node
.
Node
,
error
)
{
pset
,
ok
:=
iep
[
ienc
]
if
!
ok
{
...
...
@@ -57,7 +67,7 @@ func (iep InputEncParsers) ParseInputs(ienc, format string, r io.Reader) ([]node
return
parser
(
r
)
}
func
C
borJsonParser
(
r
io
.
Reader
)
([]
node
.
Node
,
error
)
{
func
c
borJsonParser
(
r
io
.
Reader
)
([]
node
.
Node
,
error
)
{
nd
,
err
:=
ipldcbor
.
FromJson
(
r
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -66,7 +76,7 @@ func CborJsonParser(r io.Reader) ([]node.Node, error) {
return
[]
node
.
Node
{
nd
},
nil
}
func
C
borRawParser
(
r
io
.
Reader
)
([]
node
.
Node
,
error
)
{
func
c
borRawParser
(
r
io
.
Reader
)
([]
node
.
Node
,
error
)
{
data
,
err
:=
ioutil
.
ReadAll
(
r
)
if
err
!=
nil
{
return
nil
,
err
...
...
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