Use Go casing convention for JSON(B)
This commit is contained in:
+20
-20
@@ -6,44 +6,44 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Json struct {
|
||||
type JSON struct {
|
||||
Bytes []byte
|
||||
Status Status
|
||||
}
|
||||
|
||||
func (dst *Json) Set(src interface{}) error {
|
||||
func (dst *JSON) Set(src interface{}) error {
|
||||
if src == nil {
|
||||
*dst = Json{Status: Null}
|
||||
*dst = JSON{Status: Null}
|
||||
return nil
|
||||
}
|
||||
|
||||
switch value := src.(type) {
|
||||
case string:
|
||||
*dst = Json{Bytes: []byte(value), Status: Present}
|
||||
*dst = JSON{Bytes: []byte(value), Status: Present}
|
||||
case *string:
|
||||
if value == nil {
|
||||
*dst = Json{Status: Null}
|
||||
*dst = JSON{Status: Null}
|
||||
} else {
|
||||
*dst = Json{Bytes: []byte(*value), Status: Present}
|
||||
*dst = JSON{Bytes: []byte(*value), Status: Present}
|
||||
}
|
||||
case []byte:
|
||||
if value == nil {
|
||||
*dst = Json{Status: Null}
|
||||
*dst = JSON{Status: Null}
|
||||
} else {
|
||||
*dst = Json{Bytes: value, Status: Present}
|
||||
*dst = JSON{Bytes: value, Status: Present}
|
||||
}
|
||||
default:
|
||||
buf, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*dst = Json{Bytes: buf, Status: Present}
|
||||
*dst = JSON{Bytes: buf, Status: Present}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dst *Json) Get() interface{} {
|
||||
func (dst *JSON) Get() interface{} {
|
||||
switch dst.Status {
|
||||
case Present:
|
||||
var i interface{}
|
||||
@@ -59,7 +59,7 @@ func (dst *Json) Get() interface{} {
|
||||
}
|
||||
}
|
||||
|
||||
func (src *Json) AssignTo(dst interface{}) error {
|
||||
func (src *JSON) AssignTo(dst interface{}) error {
|
||||
switch v := dst.(type) {
|
||||
case *string:
|
||||
if src.Status != Present {
|
||||
@@ -90,21 +90,21 @@ func (src *Json) AssignTo(dst interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dst *Json) DecodeText(ci *ConnInfo, src []byte) error {
|
||||
func (dst *JSON) DecodeText(ci *ConnInfo, src []byte) error {
|
||||
if src == nil {
|
||||
*dst = Json{Status: Null}
|
||||
*dst = JSON{Status: Null}
|
||||
return nil
|
||||
}
|
||||
|
||||
*dst = Json{Bytes: src, Status: Present}
|
||||
*dst = JSON{Bytes: src, Status: Present}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dst *Json) DecodeBinary(ci *ConnInfo, src []byte) error {
|
||||
func (dst *JSON) DecodeBinary(ci *ConnInfo, src []byte) error {
|
||||
return dst.DecodeText(ci, src)
|
||||
}
|
||||
|
||||
func (src *Json) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
|
||||
func (src *JSON) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
|
||||
switch src.Status {
|
||||
case Null:
|
||||
return nil, nil
|
||||
@@ -115,14 +115,14 @@ func (src *Json) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
|
||||
return append(buf, src.Bytes...), nil
|
||||
}
|
||||
|
||||
func (src *Json) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
|
||||
func (src *JSON) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
|
||||
return src.EncodeText(ci, buf)
|
||||
}
|
||||
|
||||
// Scan implements the database/sql Scanner interface.
|
||||
func (dst *Json) Scan(src interface{}) error {
|
||||
func (dst *JSON) Scan(src interface{}) error {
|
||||
if src == nil {
|
||||
*dst = Json{Status: Null}
|
||||
*dst = JSON{Status: Null}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ func (dst *Json) Scan(src interface{}) error {
|
||||
}
|
||||
|
||||
// Value implements the database/sql/driver Valuer interface.
|
||||
func (src *Json) Value() (driver.Value, error) {
|
||||
func (src *JSON) Value() (driver.Value, error) {
|
||||
switch src.Status {
|
||||
case Present:
|
||||
return string(src.Bytes), nil
|
||||
|
||||
Reference in New Issue
Block a user