package util import ( "database/sql" "reflect" "strconv" "strings" "time" ) type NullTime sql.NullTime func (nv *NullTime) Scan(value interface{}) error { var i sql.NullTime if err := i.Scan(value); err != nil { return err } // if nil then make Valid false if reflect.TypeOf(value) == nil { *nv = NullTime{i.Time, false} } else { *nv = NullTime{i.Time, true} } return nil } func ReplaceSQL(old, searchPattern string) string { tmpCount := strings.Count(old, searchPattern) for m := 1; m <= tmpCount; m++ { old = strings.Replace(old, searchPattern, "$"+strconv.Itoa(m), 1) } return old } func ParseNullDateTime(v sql.NullTime) time.Time { var time time.Time // if v.Valid { // time = v.Time // return &time // } return time }