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
361f13dd
Commit
361f13dd
authored
Aug 15, 2016
by
Kris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add JSON encoding handlers to unstructured objects
parent
69e0740b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
types.go
pkg/runtime/types.go
+31
-0
No files found.
pkg/runtime/types.go
View file @
361f13dd
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
runtime
package
runtime
import
(
import
(
"bytes"
"fmt"
"fmt"
"github.com/golang/glog"
"github.com/golang/glog"
...
@@ -138,6 +139,21 @@ type Unstructured struct {
...
@@ -138,6 +139,21 @@ type Unstructured struct {
Object
map
[
string
]
interface
{}
Object
map
[
string
]
interface
{}
}
}
// MarshalJSON ensures that the unstructured object produces proper
// JSON when passed to Go's standard JSON library.
func
(
u
*
Unstructured
)
MarshalJSON
()
([]
byte
,
error
)
{
var
buf
bytes
.
Buffer
err
:=
UnstructuredJSONScheme
.
Encode
(
u
,
&
buf
)
return
buf
.
Bytes
(),
err
}
// UnmarshalJSON ensures that the unstructured object properly decodes
// JSON when passed to Go's standard JSON library.
func
(
u
*
Unstructured
)
UnmarshalJSON
(
b
[]
byte
)
error
{
_
,
_
,
err
:=
UnstructuredJSONScheme
.
Decode
(
b
,
nil
,
u
)
return
err
}
func
getNestedField
(
obj
map
[
string
]
interface
{},
fields
...
string
)
interface
{}
{
func
getNestedField
(
obj
map
[
string
]
interface
{},
fields
...
string
)
interface
{}
{
var
val
interface
{}
=
obj
var
val
interface
{}
=
obj
for
_
,
field
:=
range
fields
{
for
_
,
field
:=
range
fields
{
...
@@ -450,6 +466,21 @@ type UnstructuredList struct {
...
@@ -450,6 +466,21 @@ type UnstructuredList struct {
Items
[]
*
Unstructured
`json:"items"`
Items
[]
*
Unstructured
`json:"items"`
}
}
// MarshalJSON ensures that the unstructured list object produces proper
// JSON when passed to Go's standard JSON library.
func
(
u
*
UnstructuredList
)
MarshalJSON
()
([]
byte
,
error
)
{
var
buf
bytes
.
Buffer
err
:=
UnstructuredJSONScheme
.
Encode
(
u
,
&
buf
)
return
buf
.
Bytes
(),
err
}
// UnmarshalJSON ensures that the unstructured list object properly
// decodes JSON when passed to Go's standard JSON library.
func
(
u
*
UnstructuredList
)
UnmarshalJSON
(
b
[]
byte
)
error
{
_
,
_
,
err
:=
UnstructuredJSONScheme
.
Decode
(
b
,
nil
,
u
)
return
err
}
func
(
u
*
UnstructuredList
)
setNestedField
(
value
interface
{},
fields
...
string
)
{
func
(
u
*
UnstructuredList
)
setNestedField
(
value
interface
{},
fields
...
string
)
{
if
u
.
Object
==
nil
{
if
u
.
Object
==
nil
{
u
.
Object
=
make
(
map
[
string
]
interface
{})
u
.
Object
=
make
(
map
[
string
]
interface
{})
...
...
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