Add some docs to constructors
This commit was moved from ipfs/go-ipfs-http-client@e34cd600e690bfa9bd20d6089b9335ac6090d4dd
Łukasz Magiera committed
Feb 19, 2019 at 23:26 UTC
aa4d6e16f13bd753b77d0a8fc2174e41af89310e
1 file changed
+17
-2
client/httpapi/api.go
+17
-2
@@ -22,6 +22,11 @@ const (
22
EnvDir = "IPFS_PATH"
23
)
24
25
+// HttpApi implements github.com/ipfs/interface-go-ipfs-core/CoreAPI using
26
+// IPFS HTTP API.
27
+//
28
+// For interface docs see
29
+// https://godoc.org/github.com/ipfs/interface-go-ipfs-core#CoreAPI
30
type HttpApi struct {
31
url string
32
httpcli gohttp.Client
@@ -29,6 +34,11 @@ type HttpApi struct {
34
applyGlobal func(*RequestBuilder)
35
}
36
37
+// NewLocalApi tries to construct new HttpApi instance communicating with local
38
+// IPFS daemon
39
+//
40
+// Daemon api address is pulled from the $IPFS_PATH/api file.
41
+// If $IPFS_PATH env var is not present, it defaults to ~/.ipfs
42
func NewLocalApi() (iface.CoreAPI, error) {
43
baseDir := os.Getenv(EnvDir)
44
if baseDir == "" {
@@ -38,8 +48,10 @@ func NewLocalApi() (iface.CoreAPI, error) {
48
return NewPathApi(baseDir)
49
}
50
41
-func NewPathApi(p string) (iface.CoreAPI, error) {
42
- a, err := ApiAddr(p)
51
+// NewPathApi constructs new HttpApi by pulling api address from specified
52
+// ipfspath. Api file should be located at $ipfspath/api
53
+func NewPathApi(ipfspath string) (iface.CoreAPI, error) {
54
+ a, err := ApiAddr(ipfspath)
55
if err != nil {
56
if err == os.ErrNotExist {
57
err = nil
@@ -49,6 +61,7 @@ func NewPathApi(p string) (iface.CoreAPI, error) {
61
return NewApi(a)
62
}
63
64
+// ApiAddr reads api file in specified ipfs path
65
func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
66
baseDir, err := homedir.Expand(ipfspath)
67
if err != nil {
@@ -65,6 +78,7 @@ func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
78
return ma.NewMultiaddr(strings.TrimSpace(string(api)))
79
}
80
81
+// NewApi constructs HttpApi with specified endpoint
82
func NewApi(a ma.Multiaddr) (*HttpApi, error) {
83
c := &gohttp.Client{
84
Transport: &gohttp.Transport{
@@ -76,6 +90,7 @@ func NewApi(a ma.Multiaddr) (*HttpApi, error) {
90
return NewApiWithClient(a, c)
91
}
92
93
+// NewApiWithClient constructs HttpApi with specified endpoint and custom http client
94
func NewApiWithClient(a ma.Multiaddr, c *gohttp.Client) (*HttpApi, error) {
95
_, url, err := manet.DialArgs(a)
96
if err != nil {