mirror of
https://github.com/h44z/wg-portal
synced 2025-02-26 05:49:14 +00:00
Implement custom Value and Scan methods for PrivateString type (#231)
This commit is contained in:
parent
38310d6ff2
commit
1d862c01d5
@ -1,7 +1,10 @@
|
|||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"database/sql/driver"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BaseModel struct {
|
type BaseModel struct {
|
||||||
@ -21,6 +24,26 @@ func (PrivateString) String() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ps PrivateString) Value() (driver.Value, error) {
|
||||||
|
if len(ps) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return string(ps), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *PrivateString) Scan(value interface{}) error {
|
||||||
|
if value == nil {
|
||||||
|
*ps = ""
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
strValue, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("invalid type for PrivateString")
|
||||||
|
}
|
||||||
|
*ps = PrivateString(strValue)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DisabledReasonExpired = "expired"
|
DisabledReasonExpired = "expired"
|
||||||
DisabledReasonDeleted = "deleted"
|
DisabledReasonDeleted = "deleted"
|
||||||
|
Loading…
Reference in New Issue
Block a user