[root@sltvb7v2wy3 jia_methods]# cat exercise_reader.go
package main
import "github.com/Go-zh/tour/reader"
type MyReader struct{}
// TODO: Add a Read([]byte) (int, error) method to MyReader.
func (r MyReader) Read(p []byte) (int, error) {
for i := 0; i < len(p); i++ {
p[i] = 'A'
}
return len(p), nil
}
func main() {
reader.Validate(MyReader{})
}
[root@sltvb7v2wy3 jia_methods]# gor exercise_reader.go
exercise_reader.go:3:8: no required module provides package github.com/Go-zh/tour/reader: go.mod file not found in current directory or any parent directory; see 'go help modules'
[root@sltvb7v2wy3 jia_methods]# go mod init example.com/exercise_reader.go
go: creating new go.mod: module example.com/exercise_reader.go
go: to add module requirements and sums:
go mod tidy
[root@sltvb7v2wy3 jia_methods]# go mod tidy
go: finding module for package github.com/Go-zh/tour/reader
go: downloading github.com/Go-zh/tour v0.0.0-20210601082505-f4baf0dba327
go: found github.com/Go-zh/tour/reader in github.com/Go-zh/tour v0.0.0-20210601082505-f4baf0dba327
[root@sltvb7v2wy3 jia_methods]# gor exercise_reader.go
OK!
网友评论