当前位置: 首页>>代码示例>>Golang>>正文


Golang List.Iter方法代码示例

本文整理汇总了Golang中container/list.List.Iter方法的典型用法代码示例。如果您正苦于以下问题:Golang List.Iter方法的具体用法?Golang List.Iter怎么用?Golang List.Iter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在container/list.List的用法示例。


在下文中一共展示了List.Iter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: eachReport

func eachReport(l *list.List) <-chan Report {
	ch := make(chan Report, l.Len())
	for val := range l.Iter() {
		if name, ok := val.(Report); !ok {
			panic("typecast error")
		} else {
			ch <- name
		}
	}
	close(ch)
	return ch
}
开发者ID:remogatto,项目名称:gospecify,代码行数:12,代码来源:basicReporter.go

示例2: handlingINOUT

// handlingINOUT(): handle inputs from client, and send it to all other client via channels.
func handlingINOUT(IN <-chan string, lst *list.List) {
	for {
		Log("handlingINOUT(): wait for input")
		input := <-IN // input, get from client
		// send to all client back
		Log("handlingINOUT(): handling input: ", input)
		for value := range lst.Iter() {
			client := value.(ClientChat)
			Log("handlingINOUT(): send to client: ", client.Name)
			client.IN <- input
		}
	}
}
开发者ID:eryx,项目名称:tips.go,代码行数:14,代码来源:chat-server.go

示例3: dumpDHT

// Dump the DHT
// First line of response is number of items
// It is important that the DHT is delivered in one go as
// otherwise there will be sync issues. Imagine you dump a bit now, then delete
// a message what was part of that dump and then dump some more, the delete would
// be lost.
// Will this work for 1,000,000 messages in the DHT?
func (myDHTServer *DHTServerStruct) dumpDHT(con *net.TCPConn) {

	// Query DHT
	sql := fmt.Sprintf("SELECT id,sha1,mailbox,size,orignodeid FROM DHT order by id")
	G_dhtDBLock.Lock()
	stmt, serr := myDHTServer.dht.Prepare(sql)
	defer stmt.Finalize()
	defer G_dhtDBLock.Unlock()
	if serr == nil {
		var id int
		var sha1 string
		var mailbox string
		var size int
		var orignodeid int

		var r list.List
		r.Init()
		stmt.Exec()
		rowcount := 0
		for stmt.Next() {
			err := stmt.Scan(&id, &sha1, &mailbox, &size, &orignodeid)
			if err != nil {
				myDHTServer.logger.Logf(LMIN, "Unexpected error using DB: %s", err)
				break
			}
			reply := fmt.Sprintf("%d,%s,%s,%d,%d\r\n", id, sha1, mailbox, size, orignodeid)
			r.PushBack(reply)
			rowcount++
		}

		con.Write([]byte(fmt.Sprintf("%d\r\n", rowcount)))

		for c := range r.Iter() {
			con.Write([]byte(c.(string)))
		}
	} else {
		myDHTServer.logger.Logf(LMIN, "Unexpected error using DB (%s): %s", sql, serr)
	}
}
开发者ID:GoogleSourceExpoted,项目名称:goesmtp,代码行数:46,代码来源:DHTServer.go

示例4: sendNewMessageLog

// Send the New Message Log to a remote node
// First line of response is number of items
func (myDHTServer *DHTServerStruct) sendNewMessageLog(con *net.TCPConn, hid string) {

	// Query newMessageLog
	sql := fmt.Sprintf("SELECT id, sha1, mailbox, size FROM newMessageLog where id > %s order by id", hid)
	G_nmlDBLock.Lock()
	stmt, serr := myDHTServer.nml.Prepare(sql)
	defer stmt.Finalize()
	defer G_nmlDBLock.Unlock()
	if serr == nil {
		var id int
		var sha1 string
		var mailbox string
		var size int

		var r list.List
		r.Init()
		stmt.Exec()
		rowcount := 0
		for stmt.Next() {
			err := stmt.Scan(&id, &sha1, &mailbox, &size)
			if err != nil {
				myDHTServer.logger.Logf(LMIN, "Unexpected error using DB: %s", err)
				break
			}
			reply := fmt.Sprintf("%d,%s,%s,%d,%s\r\n", id, sha1, mailbox, size, G_nodeID)
			r.PushBack(reply)
			rowcount++
		}

		con.Write([]byte(fmt.Sprintf("%d\r\n", rowcount)))

		for c := range r.Iter() {
			con.Write([]byte(c.(string)))
		}
	} else {
		myDHTServer.logger.Logf(LMIN, "Unexpected error using DB (%s): %s", sql, serr)
	}
}
开发者ID:GoogleSourceExpoted,项目名称:goesmtp,代码行数:40,代码来源:DHTServer.go

示例5: main

func main() {
	lst := new(list.List)
	for _ = range lst.Iter() {
	}
}
开发者ID:28240885,项目名称:the-way-to-go_ZH_CN,代码行数:5,代码来源:iteration_list.go


注:本文中的container/list.List.Iter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。