api.go 389 B

12345678910111213141516171819202122232425262728
  1. package ipfs_api
  2. import (
  3. "log"
  4. ipfs "github.com/ipfs/go-ipfs-api"
  5. )
  6. var sh *ipfs.Shell
  7. func reset() {
  8. if sh == nil || !sh.IsUp() {
  9. sh = ipfs.NewShell("127.0.0.1:5001")
  10. if id, err := sh.ID(); err == nil {
  11. v0, _, _ := sh.Version()
  12. log.Println("ipfs version", v0, "node", id.ID, "online")
  13. }
  14. }
  15. }
  16. func Shell() *ipfs.Shell {
  17. reset()
  18. return sh
  19. }
  20. func init() {
  21. reset()
  22. }