Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Add some docs to constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Feb 19, 2019
1 parent fd7858d commit e34cd60
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@ const (
EnvDir = "IPFS_PATH"
)

// HttpApi implements github.com/ipfs/interface-go-ipfs-core/CoreAPI using
// IPFS HTTP API.
//
// For interface docs see
// https://godoc.org/github.com/ipfs/interface-go-ipfs-core#CoreAPI
type HttpApi struct {
url string
httpcli gohttp.Client

applyGlobal func(*RequestBuilder)
}

// NewLocalApi tries to construct new HttpApi instance communicating with local
// IPFS daemon
//
// Daemon api address is pulled from the $IPFS_PATH/api file.
// If $IPFS_PATH env var is not present, it defaults to ~/.ipfs
func NewLocalApi() (iface.CoreAPI, error) {
baseDir := os.Getenv(EnvDir)
if baseDir == "" {
Expand All @@ -38,8 +48,10 @@ func NewLocalApi() (iface.CoreAPI, error) {
return NewPathApi(baseDir)
}

func NewPathApi(p string) (iface.CoreAPI, error) {
a, err := ApiAddr(p)
// NewPathApi constructs new HttpApi by pulling api address from specified
// ipfspath. Api file should be located at $ipfspath/api
func NewPathApi(ipfspath string) (iface.CoreAPI, error) {
a, err := ApiAddr(ipfspath)
if err != nil {
if err == os.ErrNotExist {
err = nil
Expand All @@ -49,6 +61,7 @@ func NewPathApi(p string) (iface.CoreAPI, error) {
return NewApi(a)
}

// ApiAddr reads api file in specified ipfs path
func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
baseDir, err := homedir.Expand(ipfspath)
if err != nil {
Expand All @@ -65,6 +78,7 @@ func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
return ma.NewMultiaddr(strings.TrimSpace(string(api)))
}

// NewApi constructs HttpApi with specified endpoint
func NewApi(a ma.Multiaddr) (*HttpApi, error) {
c := &gohttp.Client{
Transport: &gohttp.Transport{
Expand All @@ -76,6 +90,7 @@ func NewApi(a ma.Multiaddr) (*HttpApi, error) {
return NewApiWithClient(a, c)
}

// NewApiWithClient constructs HttpApi with specified endpoint and custom http client
func NewApiWithClient(a ma.Multiaddr, c *gohttp.Client) (*HttpApi, error) {
_, url, err := manet.DialArgs(a)
if err != nil {
Expand Down

0 comments on commit e34cd60

Please sign in to comment.