mirror of
https://github.com/1f349/tulip.git
synced 2024-12-22 00:04:09 +00:00
Add value method to UserLocale and UserZone
This commit is contained in:
parent
5751f0296b
commit
33b5c99234
@ -2,6 +2,7 @@ package types
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"golang.org/x/text/language"
|
||||
@ -9,6 +10,7 @@ import (
|
||||
|
||||
var (
|
||||
_ sql.Scanner = &UserLocale{}
|
||||
_ driver.Valuer = &UserLocale{}
|
||||
_ json.Marshaler = &UserLocale{}
|
||||
_ json.Unmarshaler = &UserLocale{}
|
||||
)
|
||||
@ -27,7 +29,13 @@ func (l *UserLocale) Scan(src any) error {
|
||||
l.Tag = lang
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l UserLocale) Value() (driver.Value, error) {
|
||||
return l.Tag.String(), nil
|
||||
}
|
||||
|
||||
func (l UserLocale) MarshalJSON() ([]byte, error) { return json.Marshal(l.Tag.String()) }
|
||||
|
||||
func (l *UserLocale) UnmarshalJSON(bytes []byte) error {
|
||||
var a string
|
||||
err := json.Unmarshal(bytes, &a)
|
||||
|
@ -29,12 +29,15 @@ func (l *UserZone) Scan(src any) error {
|
||||
l.Location = loc
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l UserZone) Value() (driver.Value, error) {
|
||||
return l.Location.String(), nil
|
||||
}
|
||||
|
||||
func (l UserZone) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(l.Location.String())
|
||||
}
|
||||
|
||||
func (l *UserZone) UnmarshalJSON(bytes []byte) error {
|
||||
var a string
|
||||
err := json.Unmarshal(bytes, &a)
|
||||
|
Loading…
Reference in New Issue
Block a user