main.go 764 Bytes
Newer Older
keks's avatar
keks committed
1 2 3
package main

import (
4
	"context"
keks's avatar
keks committed
5 6 7 8
	"os"

	"github.com/ipfs/go-ipfs-cmds/examples/adder"

Steven Allen's avatar
Steven Allen committed
9
	//cmds "github.com/ipfs/go-ipfs-cmds"
Steven Allen's avatar
Steven Allen committed
10 11 12
	cmds "github.com/ipfs/go-ipfs-cmds"
	cli "github.com/ipfs/go-ipfs-cmds/cli"
	http "github.com/ipfs/go-ipfs-cmds/http"
keks's avatar
keks committed
13 14 15 16
)

func main() {
	// parse the command path, arguments and options from the command line
17
	req, err := cli.Parse(context.TODO(), os.Args[1:], os.Stdin, adder.RootCmd)
keks's avatar
keks committed
18 19 20 21
	if err != nil {
		panic(err)
	}

22 23
	req.Options["encoding"] = cmds.Text

keks's avatar
keks committed
24 25 26 27
	// create http rpc client
	client := http.NewClient(":6798")

	// create an emitter
Steven Allen's avatar
Steven Allen committed
28
	re, err := cli.NewResponseEmitter(os.Stdout, os.Stderr, req)
Steven Allen's avatar
Steven Allen committed
29 30 31
	if err != nil {
		panic(err)
	}
keks's avatar
keks committed
32

33 34
	// send request to server
	err = client.Execute(req, re, nil)
Steven Allen's avatar
Steven Allen committed
35
	if err != nil {
36
		panic(err)
Steven Allen's avatar
Steven Allen committed
37
	}
keks's avatar
keks committed
38
}