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
10c1234c
Commit
10c1234c
authored
May 24, 2016
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add WrapUpdatedObjectInfo helper
parent
1ef19062
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
update.go
pkg/api/rest/update.go
+41
-0
No files found.
pkg/api/rest/update.go
View file @
10c1234c
...
...
@@ -173,3 +173,44 @@ func (i *defaultUpdatedObjectInfo) UpdatedObject(ctx api.Context, oldObj runtime
return
newObj
,
nil
}
// wrappedUpdatedObjectInfo allows wrapping an existing objInfo and
// chaining additional transformations/checks on the result of UpdatedObject()
type
wrappedUpdatedObjectInfo
struct
{
// obj is the updated object
objInfo
UpdatedObjectInfo
// transformers is an optional list of transforming functions that modify or
// replace obj using information from the context, old object, or other sources.
transformers
[]
TransformFunc
}
// WrapUpdatedObjectInfo returns an UpdatedObjectInfo impl that delegates to
// the specified objInfo, then calls the passed transformers
func
WrapUpdatedObjectInfo
(
objInfo
UpdatedObjectInfo
,
transformers
...
TransformFunc
)
UpdatedObjectInfo
{
return
&
wrappedUpdatedObjectInfo
{
objInfo
,
transformers
}
}
// Preconditions satisfies the UpdatedObjectInfo interface.
func
(
i
*
wrappedUpdatedObjectInfo
)
Preconditions
()
*
api
.
Preconditions
{
return
i
.
objInfo
.
Preconditions
()
}
// UpdatedObject satisfies the UpdatedObjectInfo interface.
// It delegates to the wrapped objInfo and passes the result through any configured transformers.
func
(
i
*
wrappedUpdatedObjectInfo
)
UpdatedObject
(
ctx
api
.
Context
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
newObj
,
err
:=
i
.
objInfo
.
UpdatedObject
(
ctx
,
oldObj
)
if
err
!=
nil
{
return
newObj
,
err
}
// Allow any configured transformers to update the new object or error
for
_
,
transformer
:=
range
i
.
transformers
{
newObj
,
err
=
transformer
(
ctx
,
newObj
,
oldObj
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
newObj
,
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