Je ne comprends pas l'erreur, ceci est mon main.go que j'Execute dans la machine "A":Impossible d'utiliser (type [] octet) en tant que type io.Reader
package main
import (
"fmt"
"net"
"os"
"github.com/mistifyio/go-zfs"
)
func main() {
// Listen for incoming connections.
l, err := net.Listen("tcp", "192.168.99.5:9977")
if err != nil ...
// Close the listener when the application closes.
defer l.Close()
fmt.Println("Listening on " + CONN_HOST + ":" + CONN_PORT)
for {
// Listen for an incoming connection.
conn, err := l.Accept()
if err != nil ...
//Handle connections in a new goroutine.
go handleRequest(conn)
}
}
// Handles incoming requests.
func handleRequest(conn net.Conn) {
// Make a buffer to hold incoming data.
buff := make([]byte, 1024)
// Read the incoming connection into the buffer.
_, err := conn.Read(buff)
if err != nil {
fmt.Printf("Error reading: %s.\n", err.Error())
}
// ReceiveSnapshot
ds, err := zfs.ReceiveSnapshot(buff, "tank/replication")
if err != nil {
fmt.Printf("Error receiving: %s.\n", err.Error())
}
fmt.Printf("%s... done!\n", ds)
// Send a response back to person contacting us.
conn.Write([]byte("Received!"))
// Close the connection when you're done with it.
conn.Close()
}
Maintenant, je vous montrer la fonction ReceiveSnapshot de github.com/mistifyio/go-zfs/zfs.go:
type command struct {
Command string
Stdin io.Reader
Stdout io.Writer
}
func ReceiveSnapshot(input io.Reader, name string) (*Dataset, error) {
c := command{Command: "zfs", Stdin: input}
_, err := c.Run("receive", name)
if err != nil {
return nil, err
}
return GetDataset(name)
}
Je l'ai vu dans golang pkg la doc de io.Reader:
type Reader interface {
Read(p []byte) (n int, err error)
}
Pourquoi dois-je recevoir l'erreur ...
- ne peut pas utiliser buff (type [] octet) en tant que type io.Reader en argument zfs.ReceiveSnapshot: [] octet n'implémente pas io.Reader (manque de méthode Read)
... quand je fais go install
?
Qu'est-ce qui n'est pas clair à propos du message d'erreur? Un octet [] n'implémente pas la méthode Read d'un io.Reader, il ne peut donc pas être utilisé comme io.Reader. S'il vous plaît travailler à travers le chapitre Méthodes et Interfaces du Tour of Go (en commençant ici: https://tour.golang.org/methods/1) – Volker
Je sais que le message est clair mais si je le demande c'est parce que je ne le fais pas comprendre (et j'ai lu la tournée ...) la différence entre 'buff: = make ([] byte)' et la méthode Read 'Read (p [] byte)' – icarbajo