2
0

Expand pgtype.Value interface

- Include and rename ConvertFrom to Set
- Add Get
- Include AssignTo
This commit is contained in:
Jack Christensen
2017-03-11 19:53:02 -06:00
parent 542eac08c6
commit 57494a6a0f
74 changed files with 568 additions and 185 deletions
+17 -1
View File
@@ -10,7 +10,7 @@ type Json struct {
Status Status
}
func (dst *Json) ConvertFrom(src interface{}) error {
func (dst *Json) Set(src interface{}) error {
switch value := src.(type) {
case string:
*dst = Json{Bytes: []byte(value), Status: Present}
@@ -37,6 +37,22 @@ func (dst *Json) ConvertFrom(src interface{}) error {
return nil
}
func (dst *Json) Get() interface{} {
switch dst.Status {
case Present:
var i interface{}
err := json.Unmarshal(dst.Bytes, &i)
if err != nil {
return dst
}
return i
case Null:
return nil
default:
return dst.Status
}
}
func (src *Json) AssignTo(dst interface{}) error {
switch v := dst.(type) {
case *string: