mirror of https://github.com/h44z/wg-portal.git
				
				
				
			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 | ||||
| 
 | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"time" | ||||
| 
 | ||||
| 	"database/sql/driver" | ||||
| ) | ||||
| 
 | ||||
| type BaseModel struct { | ||||
|  | @ -21,6 +24,26 @@ func (PrivateString) String() string { | |||
| 	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 ( | ||||
| 	DisabledReasonExpired          = "expired" | ||||
| 	DisabledReasonDeleted          = "deleted" | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue