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
2906f852
Commit
2906f852
authored
Jun 22, 2015
by
Mike Danese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow conversions.Scheme to expose intermidiate versioned api object
parent
5bd928fe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
13 deletions
+20
-13
decode.go
pkg/conversion/decode.go
+20
-13
No files found.
pkg/conversion/decode.go
View file @
2906f852
...
@@ -22,31 +22,38 @@ import (
...
@@ -22,31 +22,38 @@ import (
"fmt"
"fmt"
)
)
// Decode converts a JSON string back into a pointer to an api object.
func
(
s
*
Scheme
)
DecodeToVersionedObject
(
data
[]
byte
)
(
obj
interface
{},
version
,
kind
string
,
err
error
)
{
// Deduces the type based upon the fields added by the MetaInsertionFactory
version
,
kind
,
err
=
s
.
DataVersionAndKind
(
data
)
// technique. The object will be converted, if necessary, into the
// s.InternalVersion type before being returned. Decode will not decode
// objects without version set unless InternalVersion is also "".
func
(
s
*
Scheme
)
Decode
(
data
[]
byte
)
(
interface
{},
error
)
{
version
,
kind
,
err
:=
s
.
DataVersionAndKind
(
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
}
}
if
version
==
""
&&
s
.
InternalVersion
!=
""
{
if
version
==
""
&&
s
.
InternalVersion
!=
""
{
return
nil
,
fmt
.
Errorf
(
"version not set in '%s'"
,
string
(
data
))
return
nil
,
""
,
""
,
fmt
.
Errorf
(
"version not set in '%s'"
,
string
(
data
))
}
}
if
kind
==
""
{
if
kind
==
""
{
return
nil
,
fmt
.
Errorf
(
"kind not set in '%s'"
,
string
(
data
))
return
nil
,
""
,
""
,
fmt
.
Errorf
(
"kind not set in '%s'"
,
string
(
data
))
}
}
obj
,
err
:
=
s
.
NewObject
(
version
,
kind
)
obj
,
err
=
s
.
NewObject
(
version
,
kind
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
""
,
""
,
err
}
}
if
err
:=
json
.
Unmarshal
(
data
,
obj
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
data
,
obj
);
err
!=
nil
{
return
nil
,
err
return
nil
,
""
,
""
,
err
}
}
return
}
// Decode converts a JSON string back into a pointer to an api object.
// Deduces the type based upon the fields added by the MetaInsertionFactory
// technique. The object will be converted, if necessary, into the
// s.InternalVersion type before being returned. Decode will not decode
// objects without version set unless InternalVersion is also "".
func
(
s
*
Scheme
)
Decode
(
data
[]
byte
)
(
interface
{},
error
)
{
obj
,
version
,
kind
,
err
:=
s
.
DecodeToVersionedObject
(
data
)
if
err
!=
nil
{
return
nil
,
err
}
// Version and Kind should be blank in memory.
// Version and Kind should be blank in memory.
if
err
:=
s
.
SetVersionAndKind
(
""
,
""
,
obj
);
err
!=
nil
{
if
err
:=
s
.
SetVersionAndKind
(
""
,
""
,
obj
);
err
!=
nil
{
return
nil
,
err
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