當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Snowflake.IsZero方法代碼示例

本文整理匯總了Golang中euphoria/io/heim/proto/snowflake.Snowflake.IsZero方法的典型用法代碼示例。如果您正苦於以下問題:Golang Snowflake.IsZero方法的具體用法?Golang Snowflake.IsZero怎麽用?Golang Snowflake.IsZero使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在euphoria/io/heim/proto/snowflake.Snowflake的用法示例。


在下文中一共展示了Snowflake.IsZero方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Latest

func (log *memLog) Latest(ctx scope.Context, n int, before snowflake.Snowflake) ([]proto.Message, error) {
	log.Lock()
	defer log.Unlock()

	end := len(log.msgs)
	if !before.IsZero() {
		for end > 0 && !log.msgs[end-1].ID.Before(before) {
			end--
		}
	}

	start := end - n
	if start < 0 {
		start = 0
	}

	slice := make([]*proto.Message, 0, n)
	for _, msg := range log.msgs[start:] {
		if time.Time(msg.Deleted).IsZero() {
			slice = append(slice, maybeTruncate(msg))
			if len(slice) >= n {
				break
			}
		}
	}
	if len(slice) == 0 {
		return []proto.Message{}, nil
	}

	messages := make([]proto.Message, len(slice))
	for i, msg := range slice {
		messages[i] = *msg
	}
	return messages, nil
}
開發者ID:logan,項目名稱:heim,代碼行數:35,代碼來源:log.go

示例2: latest

func (b *Backend) latest(ctx scope.Context, room *Room, n int, before snowflake.Snowflake) (
	[]proto.Message, error) {

	if n <= 0 {
		return nil, nil
	}
	// TODO: define constant
	if n > 1000 {
		n = 1000
	}

	var query string
	args := []interface{}{room.Name, n}

	// Get the time before which messages will be expired
	nDays, err := b.DbMap.SelectInt("SELECT retention_days FROM room WHERE name = $1", room.Name)
	if err != nil {
		return nil, err
	}
	if nDays == 0 {
		if before.IsZero() {
			query = ("SELECT room, id, previous_edit_id, parent, posted, edited, deleted," +
				" session_id, sender_id, sender_name, server_id, server_era, content, encryption_key_id" +
				" FROM message WHERE room = $1 AND deleted IS NULL ORDER BY id DESC LIMIT $2")
		} else {
			query = ("SELECT room, id, previous_edit_id, parent, posted, edited, deleted," +
				" session_id, sender_id, sender_name, server_id, server_era, content, encryption_key_id" +
				" FROM message WHERE room = $1 AND id < $3 AND deleted IS NULL ORDER BY id DESC LIMIT $2")
			args = append(args, before.String())
		}
	} else {
		threshold := time.Now().Add(time.Duration(-nDays) * 24 * time.Hour)
		if before.IsZero() {
			query = ("SELECT room, id, previous_edit_id, parent, posted, edited, deleted," +
				" session_id, sender_id, sender_name, server_id, server_era, content, encryption_key_id" +
				" FROM message WHERE room = $1 AND posted > $3 AND deleted IS NULL ORDER BY id DESC LIMIT $2")
		} else {
			query = ("SELECT room, id, previous_edit_id, parent, posted, edited, deleted," +
				" session_id, sender_id, sender_name, server_id, server_era, content, encryption_key_id" +
				" FROM message WHERE room = $1 AND id < $3 AND deleted IS NULL AND posted > $4 ORDER BY id DESC LIMIT $2")
			args = append(args, before.String())
		}
		args = append(args, threshold)
	}

	msgs, err := b.DbMap.Select(Message{}, query, args...)
	if err != nil {
		return nil, err
	}

	results := make([]proto.Message, len(msgs))
	for i, row := range msgs {
		msg := row.(*Message)
		results[len(msgs)-i-1] = msg.ToBackend()
	}

	return results, nil
}
開發者ID:rmasoni,項目名稱:heim,代碼行數:58,代碼來源:backend.go

示例3: latest

func (b *Backend) latest(ctx scope.Context, rb *RoomBinding, n int, before snowflake.Snowflake) (
	[]proto.Message, error) {

	if n <= 0 {
		return nil, nil
	}
	// TODO: define constant
	if n > 1000 {
		n = 1000
	}

	var query string
	args := []interface{}{rb.RoomName, n}

	// Get the time before which messages will be expired
	nDays, err := b.DbMap.SelectInt("SELECT retention_days FROM room WHERE name = $1", rb.RoomName)
	if err != nil {
		return nil, err
	}
	cols, err := allColumns(b.DbMap, Message{}, "")
	if err != nil {
		return nil, err
	}
	if nDays == 0 {
		if before.IsZero() {
			query = fmt.Sprintf("SELECT %s FROM message WHERE room = $1 AND deleted IS NULL ORDER BY id DESC LIMIT $2", cols)
		} else {
			query = fmt.Sprintf("SELECT %s FROM message WHERE room = $1 AND id < $3 AND deleted IS NULL ORDER BY id DESC LIMIT $2", cols)
			args = append(args, before.String())
		}
	} else {
		threshold := time.Now().Add(time.Duration(-nDays) * 24 * time.Hour)
		if before.IsZero() {
			query = fmt.Sprintf("SELECT %s FROM message WHERE room = $1 AND posted > $3 AND deleted IS NULL ORDER BY id DESC LIMIT $2", cols)
		} else {
			query = fmt.Sprintf(
				"SELECT %s FROM message WHERE room = $1 AND id < $3 AND deleted IS NULL AND posted > $4 ORDER BY id DESC LIMIT $2", cols)
			args = append(args, before.String())
		}
		args = append(args, threshold)
	}

	msgs, err := b.DbMap.Select(Message{}, query, args...)
	if err != nil {
		return nil, err
	}

	results := make([]proto.Message, len(msgs))
	for i, row := range msgs {
		msg := row.(*Message)
		results[len(msgs)-i-1] = msg.ToTransmission()
	}

	return results, nil
}
開發者ID:logan,項目名稱:heim,代碼行數:55,代碼來源:backend.go


注:本文中的euphoria/io/heim/proto/snowflake.Snowflake.IsZero方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。