本文整理汇总了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
}
示例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
}
}
}
示例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)
}
}
示例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)
}
}
示例5: main
func main() {
lst := new(list.List)
for _ = range lst.Iter() {
}
}