Exemplo n.º 1
0
func scanUser(user *data.User, rows *sql.Rows) error {
	var createTimeString string

	err := rows.Scan(
		&user.Username,
		&user.Password,
		&user.Salt,
		&user.Role,
		&user.TrustLevel,
		&createTimeString,
	)

	if err != nil {
		return err
	}

	createTime, err := time.Parse("2006-01-02 15:04:05", createTimeString) // this assumes UTC as timezone

	if err != nil {
		log.Println("User scanner failed to parse time.")
		return err
	}

	user.CreateTime = createTime

	return nil
}
Exemplo n.º 2
0
func TestReadUser(t *testing.T) {
	readUser := new(data.User)

	testRead(t, "/users/"+user.Username, readUser)

	readUser.CreateTime = user.CreateTime

	structJSONCompare(t, user, readUser)
}
Exemplo n.º 3
0
func TestSelectUser(t *testing.T) {
	selectedUser := new(data.User)
	selectedUser.Username = user.Username
	err := Select(selectedUser)

	if err != nil {
		t.Error(err)
	}

	t.Log(selectedUser.CreateTime.UTC())
	t.Log(user.CreateTime.UTC())

	selectedUser.CreateTime = user.CreateTime // Hack because MySQL will eat part of the timestamp and they won't match

	structJSONCompare(t, user, selectedUser)
}
Exemplo n.º 4
0
func scanUser(user *data.User, rows *sql.Rows) error {
	var createTimeString string
	var updateTimeString string
	var statusTimeString string

	err := rows.Scan(
		&user.Username,
		&user.Password,
		&user.Salt,
		&user.Role,
		&user.TrustLevel,
		&createTimeString,
		&user.Heading,
		&user.Lat,
		&user.Lng,
		&updateTimeString,
		&user.Status,
		&statusTimeString,
	)

	if err != nil {
		return err
	}

	// TODO: this is a hacky fix for null times
	if createTimeString == "0000-00-00 00:00:00" {
		createTimeString = "0001-01-01 00:00:00"
	}
	createTime, err := time.Parse("2006-01-02 15:04:05", createTimeString) // this assumes UTC as timezone

	if err != nil {
		log.Println("User scanner failed to parse create time.")
		return err
	}

	user.CreateTime = createTime

	// TODO: this is a hacky fix for null times
	if updateTimeString == "0000-00-00 00:00:00" {
		updateTimeString = "0001-01-01 00:00:00"
	}
	updateTime, err := time.Parse("2006-01-02 15:04:05", updateTimeString) // this assumes UTC as timezone

	if err != nil {
		log.Println("User scanner failed to parse update time.")
		return err
	}

	user.UpdateTime = updateTime

	// TODO: this is a hacky fix for null times
	if statusTimeString == "0000-00-00 00:00:00" {
		statusTimeString = "0001-01-01 00:00:00"
	}
	statusTime, err := time.Parse("2006-01-02 15:04:05", statusTimeString) // this assumes UTC as timezone

	if err != nil {
		log.Println("User scanner failed to parse time.")
		return err
	}

	user.StatusTime = statusTime

	return nil
}