This repository was archived by the owner on Aug 12, 2020. It is now read-only.
  
  
  
  
    
    
    
      
    
  
  
    
File tree Expand file tree Collapse file tree 2 files changed +55
-4
lines changed Expand file tree Collapse file tree 2 files changed +55
-4
lines changed Original file line number Diff line number Diff line change 1+ package  main
2+ 
3+ import  (
4+ 	"io" 
5+ 	"net/http" 
6+ 
7+ 	u "github.com/ipfs/go-ipfs-util" 
8+ 	"github.com/ipfs/go-ipfs/core" 
9+ 	"github.com/ipfs/go-ipfs/core/coreunix" 
10+ 	"github.com/ipfs/go-ipfs/repo/fsrepo" 
11+ 	"golang.org/x/net/context" 
12+ )
13+ 
14+ var  gnode  * core.IpfsNode 
15+ 
16+ func  ServeIpfsRand (w  http.ResponseWriter , r  * http.Request ) {
17+ 	read  :=  io .LimitReader (u .NewTimeSeededRand (), 2048 )
18+ 
19+ 	str , err  :=  coreunix .Add (gnode , read )
20+ 	if  err  !=  nil  {
21+ 		w .WriteHeader (504 )
22+ 		w .Write ([]byte (err .Error ()))
23+ 	} else  {
24+ 		w .Write ([]byte (str ))
25+ 	}
26+ }
27+ 
28+ func  main () {
29+ 	r , err  :=  fsrepo .Open ("~/.ipfs" )
30+ 	if  err  !=  nil  {
31+ 		panic (err )
32+ 	}
33+ 
34+ 	// Make our 'master' context and defer cancelling it 
35+ 	ctx , cancel  :=  context .WithCancel (context .Background ())
36+ 	defer  cancel ()
37+ 
38+ 	cfg  :=  & core.BuildCfg {
39+ 		Repo :   r ,
40+ 		Online : true ,
41+ 	}
42+ 
43+ 	node , err  :=  core .NewNode (ctx , cfg )
44+ 	if  err  !=  nil  {
45+ 		panic (err )
46+ 	}
47+ 
48+ 	// Set the global node for access in the handler 
49+ 	gnode  =  node 
50+ 
51+ 	http .HandleFunc ("/ipfsobject" , ServeIpfsRand )
52+ 	http .ListenAndServe (":8080" , nil )
53+ }
Original file line number Diff line number Diff line change @@ -11,14 +11,12 @@ package main
1111import ( 
1212	"io" 
1313	"net/http" 
14- 	"os" 
1514
15+ 	u "github.com/ipfs/go-ipfs-util" 
1616	"github.com/ipfs/go-ipfs/core" 
1717	"github.com/ipfs/go-ipfs/core/coreunix" 
1818	"github.com/ipfs/go-ipfs/repo/fsrepo" 
19- 	u "github.com/ipfs/go-ipfs/util" 
20- 
21- 	"code.google.com/p/go.net/context" 
19+ 	"golang.org/x/net/context" 
2220) 
2321``` 
2422
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments