本文整理汇总了Golang中github.com/ipfs/go-ipfs/repo/fsrepo.Open函数的典型用法代码示例。如果您正苦于以下问题:Golang Open函数的具体用法?Golang Open怎么用?Golang Open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Open函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: startupIPFS
func startupIPFS(dspath string, ctx *context.Context) (*core.IpfsNode, error) {
r, err := fsrepo.Open(dspath)
if err != nil {
config, err := config.Init(os.Stdout, 2048)
if err != nil {
return nil, err
}
if err := fsrepo.Init(dspath, config); err != nil {
return nil, err
}
r, err = fsrepo.Open(dspath)
if err != nil {
return nil, err
}
}
//fmt.Println(r)
node, err := core.NewNode(*ctx, &core.BuildCfg{Online: true, Repo: r})
if err != nil {
return nil, err
}
return node, nil
}
开发者ID:jamesunger,项目名称:ipboh,代码行数:27,代码来源:ipboh.go
示例2: createNode
func createNode(nd *Node, online bool, ctx context.Context) (*core.IpfsNode, error) {
// `nd` only contains the prepopulated fields as in New().
rp, err := fsrepo.Open(nd.Path)
if err != nil {
log.Errorf("Unable to open repo `%s`: %v", nd.Path, err)
return nil, err
}
swarmAddrs := []string{
fmt.Sprintf("/ip4/0.0.0.0/tcp/%d", nd.SwarmPort),
fmt.Sprintf("/ip6/::/tcp/%d", nd.SwarmPort),
}
if err := rp.SetConfigKey("Addresses.Swarm", swarmAddrs); err != nil {
return nil, err
}
cfg := &core.BuildCfg{
Repo: rp,
Online: online,
}
ipfsNode, err := core.NewNode(ctx, cfg)
if err != nil {
return nil, err
}
return ipfsNode, nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:29,代码来源:daemon.go
示例3: NewTmpDirNode
func NewTmpDirNode(ctx context.Context) (*core.IpfsNode, error) {
dir, err := ioutil.TempDir("", "ipfs-shell")
if err != nil {
return nil, fmt.Errorf("failed to get temp dir: %s", err)
}
cfg, err := config.Init(ioutil.Discard, 1024)
if err != nil {
return nil, err
}
err = fsrepo.Init(dir, cfg)
if err != nil {
return nil, fmt.Errorf("failed to init ephemeral node: %s", err)
}
repo, err := fsrepo.Open(dir)
if err != nil {
return nil, err
}
return core.NewNode(ctx, &core.BuildCfg{
Online: true,
Repo: repo,
})
}
开发者ID:noffle,项目名称:ipfs-embedded-shell,代码行数:26,代码来源:node.go
示例4: BuildNode
func BuildNode(ctx context.Context, dcConfig *DCConfig) (*core.IpfsNode, error) {
// Get a IPFS repo/config directory, and open it
ipfsPath, err := getIpfsPath(dcConfig.PoolIndex)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
repo, err := fsrepo.Open(ipfsPath)
if err != nil {
return nil, err
}
// Create the node with a config
node, err := core.NewNode(ctx, &core.BuildCfg{
Online: true,
Repo: repo,
})
if err != nil {
return nil, err
}
return node, nil
}
开发者ID:confiks,项目名称:ipfs-dc,代码行数:25,代码来源:initialization.go
示例5: constructNodeFunc
func (i *cmdInvocation) constructNodeFunc(ctx context.Context) func() (*core.IpfsNode, error) {
return func() (*core.IpfsNode, error) {
if i.req == nil {
return nil, errors.New("constructing node without a request")
}
cmdctx := i.req.InvocContext()
if cmdctx == nil {
return nil, errors.New("constructing node without a request context")
}
r, err := fsrepo.Open(i.req.InvocContext().ConfigRoot)
if err != nil { // repo is owned by the node
return nil, err
}
// ok everything is good. set it on the invocation (for ownership)
// and return it.
n, err := core.NewNode(ctx, &core.BuildCfg{
Online: cmdctx.Online,
Repo: r,
})
if err != nil {
return nil, err
}
i.node = n
return i.node, nil
}
}
开发者ID:robert0825,项目名称:go-ipfs,代码行数:29,代码来源:main.go
示例6: addDefaultAssets
func addDefaultAssets(out io.Writer, repoRoot string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
r, err := fsrepo.Open(repoRoot)
if err != nil { // NB: repo is owned by the node
return err
}
nd, err := core.NewNode(ctx, &core.BuildCfg{Repo: r})
if err != nil {
return err
}
defer nd.Close()
dkey, err := assets.SeedInitDocs(nd)
if err != nil {
return fmt.Errorf("init: seeding init docs failed: %s", err)
}
log.Debugf("init: seeded init docs %s", dkey)
if _, err = fmt.Fprintf(out, "to get started, enter:\n"); err != nil {
return err
}
_, err = fmt.Fprintf(out, "\n\tipfs cat /ipfs/%s/readme\n\n", dkey)
return err
}
开发者ID:Kubuxu,项目名称:go-ipfs,代码行数:28,代码来源:init.go
示例7: writeConfig
// TODO share func
func writeConfig(path string, cfg *config.Config) error {
// NB: This needs to run on the daemon.
r, err := fsrepo.Open(path)
if err != nil {
return err
}
defer r.Close()
return r.SetConfig(cfg)
}
开发者ID:thomas-gardner,项目名称:go-ipfs,代码行数:10,代码来源:tour.go
示例8: addDefaultAssets
func addDefaultAssets(out io.Writer, repoRoot string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
r, err := fsrepo.Open(repoRoot)
if err != nil { // NB: repo is owned by the node
return err
}
nd, err := core.NewIPFSNode(ctx, core.Offline(r))
if err != nil {
return err
}
defer nd.Close()
dirb := uio.NewDirectory(nd.DAG)
// add every file in the assets pkg
for fname, file := range assets.Init_dir {
buf := bytes.NewBufferString(file)
s, err := coreunix.Add(nd, buf)
if err != nil {
return err
}
k := key.B58KeyDecode(s)
if err := dirb.AddChild(fname, k); err != nil {
return err
}
}
dir := dirb.GetNode()
dkey, err := nd.DAG.Add(dir)
if err != nil {
return err
}
if err := nd.Pinning.Pin(ctx, dir, true); err != nil {
return err
}
if err := nd.Pinning.Flush(); err != nil {
return err
}
if _, err = fmt.Fprintf(out, "to get started, enter:\n"); err != nil {
return err
}
_, err = fmt.Fprintf(out, "\n\tipfs cat /ipfs/%s/readme\n\n", dkey)
return err
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:52,代码来源:init.go
示例9: NewSelf
//NewSelf make repo if needed ,starts daemon and returns Self obj.
func NewSelf(cfg *config.Config, rootPath string) *Self {
InitRepo(cfg.IpfsRepo)
n := &merkledag.Node{}
k, err := n.Key()
log.IfFatal(err)
//workaround "ERROR bitswap: failed to find any peer in table"
i := 0
var node *core.IpfsNode
var ctx context.Context
var cancel context.CancelFunc
for i = 0; i < 10; i++ {
log.Println("setting up node...")
r, err := fsrepo.Open(cfg.IpfsRepo)
log.IfFatal(err)
ctx, cancel = context.WithCancel(context.Background())
node, err = core.NewNode(ctx, &core.BuildCfg{
Repo: r,
Online: true,
})
log.IfFatal(err)
if err := node.Routing.Provide(ctx, k); log.If(err) {
cancel()
log.If(node.Close())
log.Println("retrying...")
continue
}
break
}
if i == 10 {
log.Fatal("cannot provide a key to network")
}
self := &Self{
RootPath: rootPath,
ipfsNode: node,
ctx: ctx,
cancel: cancel,
cfg: cfg,
}
self.follow = FromStringSlice(cfg.FollowPeers, self)
parent, err := self.ToPeer().GetDAGNode("")
if log.If(err) {
parent = &merkledag.Node{}
}
self.myIpns, err = parent.Key()
log.IfFatal(err)
if _, err = parent.GetNodeLink(rootPath); err != nil {
log.Println("initializing DAGs for saving status")
self.makeInitNodes(parent)
}
return self
}
开发者ID:utamaro,项目名称:core,代码行数:52,代码来源:self.go
示例10: SetupIpfs
func SetupIpfs() (*core.IpfsNode, error) {
// Assume the user has run 'ipfs init'
r, err := fsrepo.Open("~/.ipfs")
if err != nil {
return nil, err
}
cfg := &core.BuildCfg{
Repo: r,
Online: true,
}
return core.NewNode(context.Background(), cfg)
}
开发者ID:f3r,项目名称:examples,代码行数:14,代码来源:demo.go
示例11: main
func main() {
bsize := kingpin.Flag("blocksize", "blocksize to test with").Default("262144").Int64()
kingpin.Parse()
ipfsdir := getIpfsDir()
r, err := fsrepo.Open(ipfsdir)
if err != nil {
fmt.Printf("Failed to open ipfs repo at: %s: %s\n", ipfsdir, err)
fmt.Println("Please ensure ipfs has been initialized and that no daemon is running")
return
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
nd, err := core.NewNode(ctx, &core.BuildCfg{
Repo: r,
})
if err != nil {
fmt.Printf("failed to create node: %s\n", err)
return
}
cfg := &BenchCfg{
Blocksize: *bsize,
}
fmt.Println(cfg)
err = BenchmarkBlockRewrites(nd, cfg)
if err != nil {
panic(err)
}
err = BenchmarkRandomBlockWrites(nd, cfg)
if err != nil {
panic(err)
}
err = BenchmarkAdd(nd, cfg)
if err != nil {
panic(err)
}
err = BenchmarkDiskWrites(ipfsdir)
if err != nil {
panic(err)
}
}
开发者ID:whyrusleeping,项目名称:repobench,代码行数:48,代码来源:main.go
示例12: NewService
// create a new Service
func NewService(name string, location string) (Service, error) {
// Basic ipfsnode setup
repo, err := fsrepo.Open(location)
if err != nil {
return Service{}, err
}
nodeBuilder := core.NewNodeBuilder().Online()
nodeBuilder.SetRepo(repo)
ctx, cancel := context.WithCancel(context.Background())
node, err := nodeBuilder.Build(ctx)
if err != nil {
return Service{}, err
}
return Service{name, node, cancel, ctx, nil, make(chan bool), false}, nil
}
开发者ID:vijayee,项目名称:Account,代码行数:18,代码来源:ipfs.go
示例13: NewDefaultNodeWithFSRepo
func NewDefaultNodeWithFSRepo(ctx context.Context, repoPath string) (*core.IpfsNode, error) {
r, err := fsrepo.Open(repoPath)
if err != nil {
return nil, errgo.Notef(err, "opening fsrepo failed")
}
node, err := core.NewNode(ctx, &core.BuildCfg{
Online: true,
Repo: r,
})
if err != nil {
return nil, errgo.Notef(err, "ipfs NewNode() failed.")
}
// TODO: can we bootsrap localy/mdns first and fall back to default?
err = node.Bootstrap(core.DefaultBootstrapConfig)
if err != nil {
return nil, errgo.Notef(err, "ipfs Bootstrap() failed.")
}
return node, nil
}
开发者ID:noffle,项目名称:ipfs-embedded-shell,代码行数:19,代码来源:node.go
示例14: main
func main() {
bkp, err := fsrepo.BestKnownPath()
if err != nil {
panic(err)
}
r, err := fsrepo.Open(bkp)
if err != nil {
panic(err)
}
k := ds.NewKey(os.Args[1])
val, err := r.Datastore().Get(k)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println(string(val.([]byte)))
}
开发者ID:whyrusleeping,项目名称:dsq,代码行数:21,代码来源:dsq.go
示例15: main
func main() {
if len(os.Args) < 2 {
fmt.Println("Please give a peer ID as an argument")
return
}
target, err := peer.IDB58Decode(os.Args[1])
if err != nil {
panic(err)
}
// Basic ipfsnode setup
r, err := fsrepo.Open("~/.ipfs")
if err != nil {
panic(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg := &core.BuildCfg{
Repo: r,
Online: true,
}
nd, err := core.NewNode(ctx, cfg)
if err != nil {
panic(err)
}
fmt.Printf("I am peer %s dialing %s\n", nd.Identity, target)
con, err := corenet.Dial(nd, target, "/app/whyrusleeping")
if err != nil {
fmt.Println(err)
return
}
io.Copy(os.Stdout, con)
}
开发者ID:f3r,项目名称:examples,代码行数:40,代码来源:client.go
示例16: initializeIpnsKeyspace
func initializeIpnsKeyspace(repoRoot string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
r, err := fsrepo.Open(repoRoot)
if err != nil { // NB: repo is owned by the node
return err
}
nd, err := core.NewNode(ctx, &core.BuildCfg{Repo: r})
if err != nil {
return err
}
defer nd.Close()
err = nd.SetupOfflineRouting()
if err != nil {
return err
}
return namesys.InitializeKeyspace(ctx, nd.DAG, nd.Namesys, nd.Pinning, nd.PrivateKey)
}
开发者ID:Kubuxu,项目名称:go-ipfs,代码行数:22,代码来源:init.go
示例17: main
func main() {
// Basic ipfsnode setup
r, err := fsrepo.Open("~/.ipfs")
if err != nil {
panic(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg := &core.BuildCfg{
Repo: r,
Online: true,
}
nd, err := core.NewNode(ctx, cfg)
if err != nil {
panic(err)
}
list, err := corenet.Listen(nd, "/app/whyrusleeping")
if err != nil {
panic(err)
}
fmt.Printf("I am peer: %s\n", nd.Identity.Pretty())
for {
con, err := list.Accept()
if err != nil {
fmt.Println(err)
return
}
defer con.Close()
fmt.Fprintln(con, "Hello! This is whyrusleepings awesome ipfs service")
fmt.Printf("Connection from: %s\n", con.Conn().RemotePeer())
}
}
开发者ID:f3r,项目名称:examples,代码行数:39,代码来源:host.go
示例18: addDefaultAssets
func addDefaultAssets(out io.Writer, repoRoot string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
r, err := fsrepo.Open(repoRoot)
if err != nil { // NB: repo is owned by the node
return err
}
nd, err := core.NewNode(ctx, &core.BuildCfg{Repo: r})
if err != nil {
return err
}
defer func() {
log.If(nd.Close())
}()
dkey, err := assets.SeedInitDocs(nd)
if err != nil {
return fmt.Errorf("init: seeding init docs failed: %s", err)
}
log.Println("init: seeded init docs", dkey)
return nil
}
开发者ID:utamaro,项目名称:core,代码行数:24,代码来源:init_repo.go
示例19: run
func run(ipfsPath, watchPath string) error {
proc := process.WithParent(process.Background())
log.Printf("running IPFSWatch on '%s' using repo at '%s'...", watchPath, ipfsPath)
ipfsPath, err := homedir.Expand(ipfsPath)
if err != nil {
return err
}
watcher, err := fsnotify.NewWatcher()
if err != nil {
return err
}
defer watcher.Close()
if err := addTree(watcher, watchPath); err != nil {
return err
}
r, err := fsrepo.Open(ipfsPath)
if err != nil {
// TODO handle case: daemon running
// TODO handle case: repo doesn't exist or isn't initialized
return err
}
node, err := core.NewIPFSNode(context.Background(), core.Online(r))
if err != nil {
return err
}
defer node.Close()
if *http {
addr := "/ip4/127.0.0.1/tcp/5001"
var opts = []corehttp.ServeOption{
corehttp.GatewayOption(true),
corehttp.WebUIOption,
corehttp.CommandsOption(cmdCtx(node, ipfsPath)),
}
proc.Go(func(p process.Process) {
if err := corehttp.ListenAndServe(node, addr, opts...); err != nil {
return
}
})
}
interrupts := make(chan os.Signal)
signal.Notify(interrupts, os.Interrupt, os.Kill)
for {
select {
case <-interrupts:
return nil
case e := <-watcher.Events:
log.Printf("received event: %s", e)
isDir, err := IsDirectory(e.Name)
if err != nil {
continue
}
switch e.Op {
case fsnotify.Remove:
if isDir {
if err := watcher.Remove(e.Name); err != nil {
return err
}
}
default:
// all events except for Remove result in an IPFS.Add, but only
// directory creation triggers a new watch
switch e.Op {
case fsnotify.Create:
if isDir {
addTree(watcher, e.Name)
}
}
proc.Go(func(p process.Process) {
file, err := os.Open(e.Name)
if err != nil {
log.Println(err)
}
defer file.Close()
k, err := coreunix.Add(node, file)
if err != nil {
log.Println(err)
}
log.Printf("added %s... key: %s", e.Name, k)
})
}
case err := <-watcher.Errors:
log.Println(err)
}
}
return nil
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:93,代码来源:main.go
示例20: run
func run() error {
servers := config.DefaultSNRServers
fmt.Println("using gcr remotes:")
for _, p := range servers {
fmt.Println("\t", p)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cwd, err := os.Getwd()
if err != nil {
return err
}
repoPath := gopath.Join(cwd, config.DefaultPathName)
if err := ensureRepoInitialized(repoPath); err != nil {
}
repo, err := fsrepo.Open(repoPath)
if err != nil { // owned by node
return err
}
cfg, err := repo.Config()
if err != nil {
return err
}
cfg.Bootstrap = servers
if err := repo.SetConfig(cfg); err != nil {
return err
}
var addrs []ipfsaddr.IPFSAddr
for _, info := range servers {
addr, err := ipfsaddr.ParseString(info)
if err != nil {
return err
}
addrs = append(addrs, addr)
}
var infos []peer.PeerInfo
for _, addr := range addrs {
infos = append(infos, peer.PeerInfo{
ID: addr.ID(),
Addrs: []ma.Multiaddr{addr.Transport()},
})
}
node, err := core.NewNode(ctx, &core.BuildCfg{
Online: true,
Repo: repo,
Routing: corerouting.SupernodeClient(infos...),
})
if err != nil {
return err
}
defer node.Close()
opts := []corehttp.ServeOption{
corehttp.CommandsOption(cmdCtx(node, repoPath)),
corehttp.GatewayOption(false),
}
if *cat {
if err := runFileCattingWorker(ctx, node); err != nil {
return err
}
} else {
if err := runFileAddingWorker(node); err != nil {
return err
}
}
return corehttp.ListenAndServe(node, cfg.Addresses.API, opts...)
}
开发者ID:rdterner,项目名称:go-ipfs,代码行数:74,代码来源:main.go
注:本文中的github.com/ipfs/go-ipfs/repo/fsrepo.Open函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论