mirror of
https://github.com/h44z/wg-portal.git
synced 2025-10-04 07:26:18 +00:00
Implement custom Value and Scan methods for PrivateString type (#231)
This commit is contained in:
@@ -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"
|
||||||
|
Reference in New Issue
Block a user