Skip to content

Commit

Permalink
👻 Add As/With to v11 Setting (#546)
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Lucidi <slucidi@redhat.com>
  • Loading branch information
mansam authored Oct 27, 2023
1 parent 8389678 commit c3a832b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions migration/v11/model/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ type Setting struct {
Value JSON `gorm:"type:json"`
}

//
// With updates the value of the Setting with the json representation
// of the `value` parameter.
func (r *Setting) With(value interface{}) (err error) {
r.Value, err = json.Marshal(value)
if err != nil {
err = liberr.Wrap(err)
}
return
}

//
// As unmarshalls the value of the Setting into the `ptr` parameter.
func (r *Setting) As(ptr interface{}) (err error) {
err = json.Unmarshal(r.Value, ptr)
if err != nil {
err = liberr.Wrap(err)
}
return
}

type Bucket struct {
Model
Path string `gorm:"<-:create;uniqueIndex"`
Expand Down

0 comments on commit c3a832b

Please sign in to comment.