api.go 657 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package ipfs_api
  2. import (
  3. "log"
  4. "github.com/ipfs/go-ipfs-api"
  5. "github.com/streamrail/concurrent-map"
  6. "net/http"
  7. )
  8. var sh *MyShell
  9. var Addr = "127.0.0.1:5001"
  10. type MyShell struct {
  11. shell.Shell
  12. Url string
  13. Client *http.Client
  14. cache cmap.ConcurrentMap
  15. }
  16. func reset() {
  17. if sh == nil {
  18. sh = &MyShell{
  19. Url: Addr,
  20. Client: http.DefaultClient,
  21. cache: cmap.New(),
  22. }
  23. sh.Shell = *shell.NewShellWithClient(sh.Url, sh.Client)
  24. if id, err := sh.ID(); err == nil {
  25. v0, _, _ := sh.Version()
  26. log.Println("ipfs version", v0, "node", id.ID, "online")
  27. }
  28. }
  29. }
  30. func Shell() *MyShell {
  31. reset()
  32. return sh
  33. }
  34. func init() {
  35. reset()
  36. }