You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.3 KiB
62 lines
1.3 KiB
3 years ago
|
package sharedmodel
|
||
|
|
||
|
import (
|
||
|
"database/sql/driver"
|
||
|
"encoding/json"
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
|
||
|
"whiteboxsystems.nl/openkvpoc/openkv"
|
||
|
)
|
||
|
|
||
|
type Protocol struct {
|
||
|
Protocol string
|
||
|
AuthMethods AuthMethodArray
|
||
|
}
|
||
|
|
||
|
type ProtocolArray []Protocol
|
||
|
|
||
|
// Scan scan value into Jsonb, implements sql.Scanner interface
|
||
|
func (j *ProtocolArray) Scan(value interface{}) error {
|
||
|
bytes, ok := value.([]byte)
|
||
|
if !ok {
|
||
|
return errors.New(fmt.Sprint("Failed to unmarshal ProtocolArray value:", value))
|
||
|
}
|
||
|
|
||
|
result := []Protocol{}
|
||
|
err := json.Unmarshal(bytes, &result)
|
||
|
*j = ProtocolArray(result)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// Value return json value, implement driver.Valuer interface
|
||
|
func (j ProtocolArray) Value() (driver.Value, error) {
|
||
|
if len(j) == 0 {
|
||
|
return nil, nil
|
||
|
}
|
||
|
return json.Marshal(j)
|
||
|
}
|
||
|
|
||
|
type AuthMethodArray []openkv.AuthMethod
|
||
|
|
||
|
// Scan scan value into Jsonb, implements sql.Scanner interface
|
||
|
func (j *AuthMethodArray) Scan(value interface{}) error {
|
||
|
bytes, ok := value.([]byte)
|
||
|
if !ok {
|
||
|
return errors.New(fmt.Sprint("Failed to unmarshal AuthMethodArray value:", value))
|
||
|
}
|
||
|
|
||
|
result := []openkv.AuthMethod{}
|
||
|
err := json.Unmarshal(bytes, &result)
|
||
|
*j = AuthMethodArray(result)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// Value return json value, implement driver.Valuer interface
|
||
|
func (j AuthMethodArray) Value() (driver.Value, error) {
|
||
|
if len(j) == 0 {
|
||
|
return nil, nil
|
||
|
}
|
||
|
return json.Marshal(j)
|
||
|
}
|