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

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

讀取模塊結(jié)束,當(dāng)前的代碼

package?main

import?(
???"fmt"
???"strings"
???"time"
???"os"
???"bufio"
???"io"
)
//?interface
type?Reader?interface?{
???Read(rc?chan?string)
}

type?Writer?interface?{
???Write(wc?chan?string)
}

type?LogProcess?struct?{
???rc??chan?string???//?in?file?get?message
???wc??chan?string???//?out?message?in?writer
????read?Reader
????write?Writer
}

func?(l?*LogProcess)?Process()??{
???for?v?:=?range?l.rc?{
??????l.wc?<-?strings.ToUpper(string(v))
???}
}
type?ReadFromFile?struct?{
???path??????????string????//?file?storage?path
}
/*
???1.?讀取模塊
??????a.?打開文件
??????b.?從文件?末尾?開始逐行讀取
?*/
func?(r?*ReadFromFile)?Read(rc?chan?string){
???//?line?:=?"string?in?message"

???file,?err?:=?os.Open(r.path)
???if?err?!=?nil?{
??????panic(fmt.Sprintf("open?file?error:?%s",?err.Error()))
???}
???defer?file.Close()

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

???for?{
??????//?why?is?not?use?method?rd.ReadString()
??????line,?err?:=?rd.ReadString('\n')
??????if?err?!=?nil?{
?????????if?err?==?io.EOF?{
????????????time.Sleep(500?*?time.Microsecond)
????????????continue
?????????}
?????????panic(fmt.Sprintf("ReadString?error:?%s",?err.Error()))
??????}
??????//rc?<-?line[:len(line)-1]
??????rc?<-?strings.TrimSpace(line)
???}

}

type?WriterToinfluxDB?struct?{
???influxDBDsn???string????//?influxDB?dsn
}

func?(w?*WriterToinfluxDB)?Write(wc?chan?string)?{

???for?v?:=?range?wc?{
??????fmt.Println(v)
???}
}



func?main()?{
???r?:=?&ReadFromFile{
??????path:?"/tmp/access.log",
???}

???w?:=?&WriterToinfluxDB{
??????influxDBDsn:?"username$password",
???}

???lp?:=?&LogProcess{
??????rc:?make(chan?string),
??????wc:?make(chan?string),
??????read:?r,
??????write:?w,
???}

???go?lp.read.Read(lp.rc)
???go?lp.Process()
???go?lp.write.Write(lp.wc)


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

}


正在回答

1 回答

嘎哈哈哈哈哈哈哈哈

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

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

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

進(jìn)入課程

讀取模塊結(jié)束,當(dāng)前的代碼

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

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

幫助反饋 APP下載

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

公眾號(hào)

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