func loadActiveBans() { bans.Lock() defer bans.Unlock() // purge all the bans bans.users = make(map[Userid]time.Time) bans.ips = make(map[string]time.Time) bans.userips = make(map[Userid][]string) rows, err := db.Query(` SELECT targetuserid, ipaddress, endtimestamp FROM bans WHERE endtimestamp IS NULL OR endtimestamp > NOW() GROUP BY targetuserid, ipaddress `) if err != nil { B("Unable to get active bans: ", err) } for rows.Next() { var uid Userid var ipaddress sql.NullString var endtimestamp mysql.NullTime err = rows.Scan(&uid, &ipaddress, &endtimestamp) if err != nil { B("Unable to scan row: ", err) } if !endtimestamp.Valid { endtimestamp.Time = time.Now().UTC().AddDate(10, 0, 0) } if ipaddress.Valid { bans.ips[ipaddress.String] = endtimestamp.Time if _, ok := bans.userips[uid]; !ok { bans.userips[uid] = make([]string, 1) } bans.userips[uid] = append(bans.userips[uid], ipaddress.String) hub.stringipbans <- ipaddress.String } else { bans.users[uid] = endtimestamp.Time } } }
func (s *scanner) Scan(src interface{}) error { var err error switch s.value.Type().Kind() { case reflect.Struct: nt := mysql.NullTime{} err := nt.Scan(src) if err != nil { return err } s.value.Set(reflect.ValueOf(nt.Time)) case reflect.Bool: nb := sql.NullBool{} err := nb.Scan(src) if err != nil { return err } s.value.SetBool(nb.Bool) case reflect.String: ns := sql.NullString{} err = ns.Scan(src) if err != nil { return err } s.value.SetString(ns.String) case reflect.Int64: ni := sql.NullInt64{} err = ni.Scan(src) if err != nil { return err } s.value.SetInt(ni.Int64) case reflect.Float64: ni := sql.NullFloat64{} err = ni.Scan(src) if err != nil { return err } s.value.SetFloat(ni.Float64) } return nil }
func (csc CampaignStatusesCollection) Get(conn ConnectionInterface, campaignID string) (CampaignStatus, error) { campaign, err := csc.campaignsRepository.Get(conn, campaignID) if err != nil { panic(err) } counts, err := csc.messages.CountByStatus(conn, campaign.ID) if err != nil { panic(err) } status := CampaignStatusSending var completedTime mysql.NullTime if counts.Total > 0 && (counts.Failed+counts.Delivered) == counts.Total { status = CampaignStatusCompleted mostRecentlyUpdatedMessage, err := csc.messages.MostRecentlyUpdatedByCampaignID(conn, campaign.ID) if err != nil { panic(err) } completedTime.Time = mostRecentlyUpdatedMessage.UpdatedAt completedTime.Valid = true } return CampaignStatus{ CampaignID: campaign.ID, Status: status, TotalMessages: counts.Total, SentMessages: counts.Delivered, FailedMessages: counts.Failed, RetryMessages: counts.Retry, QueuedMessages: counts.Queued, StartTime: campaign.StartTime, CompletedTime: completedTime, }, nil }