33 lines
544 B
Go
33 lines
544 B
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
"database/sql/driver"
|
|
"log"
|
|
)
|
|
|
|
type NullTime struct {
|
|
Time time.Time
|
|
Valid bool // Valid is true if Time is not NULL
|
|
}
|
|
|
|
// Scan implements the Scanner interface.
|
|
func (nt *NullTime) Scan(value interface{}) error {
|
|
nt.Time, nt.Valid = value.(time.Time)
|
|
return nil
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (nt NullTime) Value() (driver.Value, error) {
|
|
if !nt.Valid {
|
|
return nil, nil
|
|
}
|
|
return nt.Time, nil
|
|
}
|
|
|
|
func checkErr(err error) {
|
|
if err != nil {
|
|
log.Print(err)
|
|
panic(err)
|
|
}
|
|
} |