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

Commit 308cc11

Browse files
committed
chore: deprecate all types and stub them to Kubo
1 parent b19af5f commit 308cc11

24 files changed

+183
-3437
lines changed

Makefile

Lines changed: 0 additions & 4 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,10 @@
11
# go-ipfs-http-api
22

3-
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](https://protocol.ai)
4-
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.io/)
5-
[![](https://img.shields.io/badge/matrix-%23ipfs-blue.svg?style=flat-square)](https://app.element.io/#/room/#ipfs:matrix.org)
6-
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
7-
[![GoDoc](https://godoc.org/github.com/ipfs/go-ipfs-http-api?status.svg)](https://godoc.org/github.com/ipfs/go-ipfs-http-api)
3+
# ⚠️ This package is no longer being maintained here. ⚠️
84

9-
> IPFS CoreAPI implementation using HTTP API
5+
It has been moved into kubo's repo at [`github.com/ipfs/kubo/client/rpc`](https://pkg.go.dev/github.com/ipfs/kubo/client/rpc).
106

11-
This package is experimental and subject to change. If you need to depend on
12-
something less likely to change, please use
13-
[go-ipfs-api](https://github.com/ipfs/go-ipfs-api). If you'd like the latest and
14-
greatest features, please use _this_ package.
15-
16-
## Documentation
17-
18-
https://godoc.org/github.com/ipfs/go-ipfs-http-api
19-
20-
### Example
21-
22-
Pin file on your local IPFS node based on its CID:
23-
24-
```go
25-
package main
26-
27-
import (
28-
"context"
29-
"fmt"
30-
31-
ipfsClient "github.com/ipfs/go-ipfs-http-client"
32-
path "github.com/ipfs/interface-go-ipfs-core/path"
33-
)
34-
35-
func main() {
36-
// "Connect" to local node
37-
node, err := ipfsClient.NewLocalApi()
38-
if err != nil {
39-
fmt.Printf(err)
40-
return
41-
}
42-
// Pin a given file by its CID
43-
ctx := context.Background()
44-
cid := "bafkreidtuosuw37f5xmn65b3ksdiikajy7pwjjslzj2lxxz2vc4wdy3zku"
45-
p := path.New(cid)
46-
err = node.Pin().Add(ctx, p)
47-
if err != nil {
48-
fmt.Printf(err)
49-
return
50-
}
51-
return
52-
}
53-
```
54-
55-
## Contribute
56-
57-
Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/go-ipfs-http-api/issues)!
58-
59-
This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
60-
61-
### Want to hack on IPFS?
62-
63-
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
7+
This allows that any updates or change to kubo's coreapi is immediately reflected on the client too.
648

659
## License
6610

api.go

Lines changed: 68 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,215 +1,109 @@
1+
// Deprecated: This repo has moved inside Kubo in order to make it easier to
2+
// keep kubo and the http-client in sync, please use github.com/ipfs/kubo/client/rpc instead.
13
package httpapi
24

35
import (
4-
"errors"
5-
"fmt"
6+
"context"
67
"net/http"
7-
"os"
8-
"path/filepath"
9-
"strings"
108

11-
iface "github.com/ipfs/boxo/coreiface"
12-
caopts "github.com/ipfs/boxo/coreiface/options"
13-
"github.com/mitchellh/go-homedir"
9+
"github.com/ipfs/kubo/client/rpc"
1410
ma "github.com/multiformats/go-multiaddr"
15-
manet "github.com/multiformats/go-multiaddr/net"
1611
)
1712

18-
const (
19-
DefaultPathName = ".ipfs"
20-
DefaultPathRoot = "~/" + DefaultPathName
21-
DefaultApiFile = "api"
22-
EnvDir = "IPFS_PATH"
23-
)
13+
// Deprecated: use [rpc.DefaultPathName] instead.
14+
const DefaultPathName = rpc.DefaultPathName
2415

25-
// ErrApiNotFound if we fail to find a running daemon.
26-
var ErrApiNotFound = errors.New("ipfs api address could not be found")
27-
28-
// HttpApi implements github.com/ipfs/interface-go-ipfs-core/CoreAPI using
29-
// IPFS HTTP API.
30-
//
31-
// For interface docs see
32-
// https://godoc.org/github.com/ipfs/interface-go-ipfs-core#CoreAPI
33-
type HttpApi struct {
34-
url string
35-
httpcli http.Client
36-
Headers http.Header
37-
applyGlobal func(*requestBuilder)
38-
}
16+
// Deprecated: use [rpc.DefaultPathRoot] instead.
17+
const DefaultPathRoot = rpc.DefaultPathRoot
3918

40-
// NewLocalApi tries to construct new HttpApi instance communicating with local
41-
// IPFS daemon
42-
//
43-
// Daemon api address is pulled from the $IPFS_PATH/api file.
44-
// If $IPFS_PATH env var is not present, it defaults to ~/.ipfs
45-
func NewLocalApi() (*HttpApi, error) {
46-
baseDir := os.Getenv(EnvDir)
47-
if baseDir == "" {
48-
baseDir = DefaultPathRoot
49-
}
19+
// Deprecated: use [rpc.DefaultApiFile] instead.
20+
const DefaultApiFile = rpc.DefaultApiFile
5021

51-
return NewPathApi(baseDir)
52-
}
22+
// Deprecated: use [rpc.EnvDir] instead.
23+
const EnvDir = rpc.EnvDir
5324

54-
// NewPathApi constructs new HttpApi by pulling api address from specified
55-
// ipfspath. Api file should be located at $ipfspath/api
56-
func NewPathApi(ipfspath string) (*HttpApi, error) {
57-
a, err := ApiAddr(ipfspath)
58-
if err != nil {
59-
if os.IsNotExist(err) {
60-
err = ErrApiNotFound
61-
}
62-
return nil, err
63-
}
64-
return NewApi(a)
65-
}
25+
// Deprecated: use [rpc.ErrApiNotFound] instead.
26+
var ErrApiNotFound = rpc.ErrApiNotFound
6627

67-
// ApiAddr reads api file in specified ipfs path
68-
func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
69-
baseDir, err := homedir.Expand(ipfspath)
70-
if err != nil {
71-
return nil, err
72-
}
28+
// Deprecated: use [rpc.HttpApi] instead.
29+
type HttpApi = rpc.HttpApi
7330

74-
apiFile := filepath.Join(baseDir, DefaultApiFile)
31+
// Deprecated: use [rpc.BlockAPI] instead.
32+
type BlockAPI = rpc.BlockAPI
7533

76-
api, err := os.ReadFile(apiFile)
77-
if err != nil {
78-
return nil, err
79-
}
34+
// Deprecated: use [rpc.HttpDagServ] instead.
35+
type HttpDagServ = rpc.HttpDagServ
8036

81-
return ma.NewMultiaddr(strings.TrimSpace(string(api)))
82-
}
37+
// Deprecated: use [rpc.DhtAPI] instead.
38+
type DhtAPI = rpc.DhtAPI
8339

84-
// NewApi constructs HttpApi with specified endpoint
85-
func NewApi(a ma.Multiaddr) (*HttpApi, error) {
86-
c := &http.Client{
87-
Transport: &http.Transport{
88-
Proxy: http.ProxyFromEnvironment,
89-
DisableKeepAlives: true,
90-
},
91-
}
92-
93-
return NewApiWithClient(a, c)
94-
}
40+
// Deprecated: use [rpc.KeyAPI] instead.
41+
type KeyAPI = rpc.KeyAPI
9542

96-
// NewApiWithClient constructs HttpApi with specified endpoint and custom http client
97-
func NewApiWithClient(a ma.Multiaddr, c *http.Client) (*HttpApi, error) {
98-
_, url, err := manet.DialArgs(a)
99-
if err != nil {
100-
return nil, err
101-
}
102-
103-
if a, err := ma.NewMultiaddr(url); err == nil {
104-
_, host, err := manet.DialArgs(a)
105-
if err == nil {
106-
url = host
107-
}
108-
}
109-
110-
proto := "http://"
111-
112-
// By default, DialArgs is going to provide details suitable for connecting
113-
// a socket to, but not really suitable for making an informed choice of http
114-
// protocol. For multiaddresses specifying tls and/or https we want to make
115-
// a https request instead of a http request.
116-
protocols := a.Protocols()
117-
for _, p := range protocols {
118-
if p.Code == ma.P_HTTPS || p.Code == ma.P_TLS {
119-
proto = "https://"
120-
break
121-
}
122-
}
123-
124-
return NewURLApiWithClient(proto+url, c)
125-
}
43+
// Deprecated: use [rpc.NameAPI] instead.
44+
type NameAPI = rpc.NameAPI
12645

127-
func NewURLApiWithClient(url string, c *http.Client) (*HttpApi, error) {
128-
api := &HttpApi{
129-
url: url,
130-
httpcli: *c,
131-
Headers: make(map[string][]string),
132-
applyGlobal: func(*requestBuilder) {},
133-
}
134-
135-
// We don't support redirects.
136-
api.httpcli.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
137-
return fmt.Errorf("unexpected redirect")
138-
}
139-
return api, nil
140-
}
46+
// Deprecated: use [rpc.ObjectAPI] instead.
47+
type ObjectAPI = rpc.ObjectAPI
14148

142-
func (api *HttpApi) WithOptions(opts ...caopts.ApiOption) (iface.CoreAPI, error) {
143-
options, err := caopts.ApiOptions(opts...)
144-
if err != nil {
145-
return nil, err
146-
}
49+
// Deprecated: use [rpc.PinAPI] instead.
50+
type PinAPI = rpc.PinAPI
14751

148-
subApi := *api
149-
subApi.applyGlobal = func(req *requestBuilder) {
150-
if options.Offline {
151-
req.Option("offline", options.Offline)
152-
}
153-
}
52+
// Deprecated: use [rpc.PubsubAPI] instead.
53+
type PubsubAPI = rpc.PubsubAPI
15454

155-
return &subApi, nil
156-
}
55+
// Deprecated: use [rpc.RoutingAPI] instead.
56+
type RoutingAPI = rpc.RoutingAPI
15757

158-
func (api *HttpApi) Request(command string, args ...string) RequestBuilder {
159-
headers := make(map[string]string)
160-
if api.Headers != nil {
161-
for k := range api.Headers {
162-
headers[k] = api.Headers.Get(k)
163-
}
164-
}
165-
return &requestBuilder{
166-
command: command,
167-
args: args,
168-
shell: api,
169-
headers: headers,
170-
}
171-
}
58+
// Deprecated: use [rpc.SwarmAPI] instead.
59+
type SwarmAPI = rpc.SwarmAPI
17260

173-
func (api *HttpApi) Unixfs() iface.UnixfsAPI {
174-
return (*UnixfsAPI)(api)
175-
}
61+
// Deprecated: use [rpc.UnixfsAPI] instead.
62+
type UnixfsAPI = rpc.UnixfsAPI
17663

177-
func (api *HttpApi) Block() iface.BlockAPI {
178-
return (*BlockAPI)(api)
64+
// Deprecated: use [rpc.NewLocalApi] instead.
65+
func NewLocalApi() (*HttpApi, error) {
66+
return rpc.NewLocalApi()
17967
}
18068

181-
func (api *HttpApi) Dag() iface.APIDagService {
182-
return (*HttpDagServ)(api)
69+
// Deprecated: use [rpc.NewPathApi] instead.
70+
func NewPathApi(ipfspath string) (*HttpApi, error) {
71+
return rpc.NewPathApi(ipfspath)
18372
}
18473

185-
func (api *HttpApi) Name() iface.NameAPI {
186-
return (*NameAPI)(api)
74+
// Deprecated: use [rpc.ApiAddr] instead.
75+
func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
76+
return rpc.ApiAddr(ipfspath)
18777
}
18878

189-
func (api *HttpApi) Key() iface.KeyAPI {
190-
return (*KeyAPI)(api)
79+
// Deprecated: use [rpc.NewApi] instead.
80+
func NewApi(a ma.Multiaddr) (*HttpApi, error) {
81+
return rpc.NewApi(a)
19182
}
19283

193-
func (api *HttpApi) Pin() iface.PinAPI {
194-
return (*PinAPI)(api)
84+
// Deprecated: use [rpc.NewApiWithClient] instead.
85+
func NewApiWithClient(a ma.Multiaddr, c *http.Client) (*HttpApi, error) {
86+
return rpc.NewApiWithClient(a, c)
19587
}
19688

197-
func (api *HttpApi) Object() iface.ObjectAPI {
198-
return (*ObjectAPI)(api)
89+
// Deprecated: use [rpc.NewURLApiWithClient] instead.
90+
func NewURLApiWithClient(url string, c *http.Client) (*HttpApi, error) {
91+
return rpc.NewURLApiWithClient(url, c)
19992
}
20093

201-
func (api *HttpApi) Dht() iface.DhtAPI {
202-
return (*DhtAPI)(api)
203-
}
94+
// Deprecated: use [rpc.Request] instead.
95+
type Request = rpc.Request
20496

205-
func (api *HttpApi) Swarm() iface.SwarmAPI {
206-
return (*SwarmAPI)(api)
97+
// Deprecated: use [rpc.NewRequest] instead.
98+
func NewRequest(ctx context.Context, url, command string, args ...string) *Request {
99+
return rpc.NewRequest(ctx, url, command, args...)
207100
}
208101

209-
func (api *HttpApi) PubSub() iface.PubSubAPI {
210-
return (*PubsubAPI)(api)
211-
}
102+
// Deprecated: use [rpc.RequestBuilder] instead.
103+
type RequestBuilder = rpc.RequestBuilder
212104

213-
func (api *HttpApi) Routing() iface.RoutingAPI {
214-
return (*RoutingAPI)(api)
215-
}
105+
// Deprecated: use [rpc.Error] instead.
106+
type Error = rpc.Error
107+
108+
// Deprecated: use [rpc.Response] instead.
109+
type Response = rpc.Response

0 commit comments

Comments
 (0)