mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-23 03:17:43 +08:00
30 lines
470 B
Go
30 lines
470 B
Go
package daemon
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
//SendCommand connects to the address on the network with a timeout and encodes the connection into JSON
|
|
func SendCommand(command *Command, server string) error {
|
|
|
|
conn, err := net.DialTimeout("tcp", server, time.Millisecond*300)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
enc := json.NewEncoder(conn)
|
|
err = enc.Encode(command)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
io.Copy(os.Stdout, conn)
|
|
|
|
return nil
|
|
}
|