第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

2-3 節(jié)代碼,我的什么沒輸出呢,老鐵們幫忙看下??

package?main

import?(
???"strings"
???"fmt"
???"time"
???"os"
???"bufio"
???"io"
)

type?Reader3?interface?{
???read(rc?chan?[]byte)
}

type?Writer3?interface?{
???write(wc?chan?string)
}
type?ReadFromFile3?struct?{
???path?string
}
type?WriteToInfluxDB3?struct?{
???influxDBDsn?string
}
type?LogProcess3?struct?{
???rc?????chan?[]byte
???wc?????chan?string
???reader?Reader3
???writer?Writer3
}

//?1?讀取模塊
func?(r?*ReadFromFile3)?read(rc?chan?[]byte)?{
???fmt.Println("Begin?read?File")
???file,?e?:=?os.OpenFile(r.path,?os.O_WRONLY|os.O_APPEND,?os.ModePerm)
???if?e?!=?nil?{
??????panic(fmt.Sprintf("open?file?error:%s",?e.Error()))
???}

???//?從文件末尾開始逐行讀取文件內(nèi)容
???file.Seek(0,?2)
???rd?:=?bufio.NewReader(file)

???for?{
??????line,?err?:=?rd.ReadBytes('\n')

??????if?err?!=?io.EOF?{?//?到結(jié)尾
?????????fmt.Println(line)
?????????time.Sleep(500?*?time.Millisecond)
?????????continue
??????}?else?if?err?!=?nil?{
?????????panic(fmt.Sprintf("ReadBytes?error:%s",?err.Error()))
??????}
??????fmt.Println(">?",line)
??????//?rc?<-?line
??????rc?<-?line[:len(line)-1]
???}

}

func?(l?*LogProcess3)?process()?{
???//?解析模塊
???
???for?v?:=?range?l.rc?{
??????l.wc?<-?strings.ToUpper(string(v))
???}
}

//?3?寫入模塊
func?(w?*WriteToInfluxDB3)?write(wc?chan?string)?{
???fmt.Println(">>?",*&wc)?//?>>??0xc4200760c0?這里為什么是地址呢?
???for?v?:=?range?wc?{
??????fmt.Printf(v)
???}
}

func?main()?{
???read?:=?&ReadFromFile3{
??????path:?"/Users/xyang/go_code/src/xyang.com/logcollect/data/access.log",
??????//path:?"data/access.log",
???}

???writer?:=?&WriteToInfluxDB3{
??????influxDBDsn:?"username=?&password=?",
???}

???lp?:=?&LogProcess3{
??????rc:?????make(chan?[]byte),
??????wc:?????make(chan?string),
??????reader:?read,
??????writer:?writer,
???}

???go?lp.reader.read(lp.rc)
???go?lp.process()
???go?lp.writer.write(lp.wc)

???time.Sleep(30?*?time.Second)
}


正在回答

1 回答

file,?e?:=?os.OpenFile(r.path,?os.O_WRONLY|os.O_APPEND,?os.ModePerm)

改為:?

file,?e?:=?os.Open(r.path)



if?err?!=?io.EOF?改為:?if?err?==?io.EOF
0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Go并發(fā)編程案例解析
  • 參與學(xué)習(xí)       15269    人
  • 解答問題       56    個

課程帶你通過一個真實(shí)的線上日志監(jiān)控系統(tǒng)學(xué)習(xí)Golang以及并發(fā)的編程思想。

進(jìn)入課程

2-3 節(jié)代碼,我的什么沒輸出呢,老鐵們幫忙看下??

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號