types: shared data types
This commit is contained in:
parent
b5420f9dbd
commit
608f05d395
52
types/log_scores.go
Normal file
52
types/log_scores.go
Normal file
@ -0,0 +1,52 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type LogScoreAttributes struct {
|
||||
Leap int8 `json:"leap,omitempty"`
|
||||
Stratum int8 `json:"stratum,omitempty"`
|
||||
NoResponse bool `json:"no_response,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Warning string `json:"warning,omitempty"`
|
||||
|
||||
FromLSID int `json:"from_ls_id,omitempty"`
|
||||
FromSSID int `json:"from_ss_id,omitempty"`
|
||||
}
|
||||
|
||||
func (lsa *LogScoreAttributes) String() string {
|
||||
b, err := json.Marshal(lsa)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (lsa *LogScoreAttributes) Value() (driver.Value, error) {
|
||||
return json.Marshal(lsa)
|
||||
}
|
||||
|
||||
func (lsa *LogScoreAttributes) Scan(value interface{}) error {
|
||||
var source []byte
|
||||
_t := LogScoreAttributes{}
|
||||
|
||||
switch v := value.(type) {
|
||||
case []uint8:
|
||||
source = v
|
||||
case string:
|
||||
source = []byte(v)
|
||||
case nil:
|
||||
return nil
|
||||
default:
|
||||
return errors.New("incompatible type for StringInterfaceMap")
|
||||
}
|
||||
err := json.Unmarshal(source, &_t)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*lsa = _t
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user