WorldLink
2019-06-10 19:31
/** * Created by GoLand * User: dollarkiller * Date: 19-6-10 * Time: 下午6:03 * */ package main import ( "fmt" "strings" ) type Reader interface { Read(chan string) } type Write interface { Write(chan string) } type LogProcess struct { rc chan string wc chan string read *Reader write *Write } type ReadFromFile struct { path string } func (r *ReadFromFile)Read(rc chan string) { msg := "message" rc <- msg } func (l *LogProcess)Process() { data := <-l.rc l.wc <- strings.ToUpper(data) } type WriteToInfluxDb struct { } func (w *WriteToInfluxDb)Write(wr chan string) { data := <-wr fmt.Println(data) } func main() { r := &ReadFromFile{ path:"/tmp/access.log", } w := &WriteToInfluxDb{} process := &LogProcess{ rc: make(chan string), wc: make(chan string), write: w, read: r, } process = process }
dollarkiller@worldlink:~/Github/Go-Log-monitoring/test$ go build # Go-Log-monitoring/test ./log_process.go:63:3: cannot use w (type *WriteToInfluxDb) as type *Write in field value: *Write is pointer to interface, not interface ./log_process.go:64:3: cannot use r (type *ReadFromFile) as type *Reader in field value: *Reader is pointer to interface, not interface
问题下我这个接口为什么会报错?
type
LogProcess struct {
type
LogProcess struct {
rc chan string
wc
chan string
read
*Reader
write *Write
}
read
*Reader
write *Write
把指针符去掉。
Go并发编程案例解析
15219 学习 · 53 问题
相似问题