为了账号安全,请及时绑定邮箱和手机立即绑定

为下这个为什么会包类型错误?

/**
* 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

问题下我这个接口为什么会报错?

正在回答

1 回答

type LogProcess struct {   

type LogProcess struct {   

rc chan string   

wc chan string   

read *Reader   

write *Write

}

read *Reader   

write *Write

把指针符去掉。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为下这个为什么会包类型错误?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信