当前位置: 首页>>代码示例>>Golang>>正文


Golang definitions.Do类代码示例

本文整理汇总了Golang中github.com/eris-ltd/eris-cli/definitions.Do的典型用法代码示例。如果您正苦于以下问题:Golang Do类的具体用法?Golang Do怎么用?Golang Do使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Do类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: PutFiles

func PutFiles(do *definitions.Do) error {
	ensureRunning()

	if do.Gateway != "" {
		_, err := url.Parse(do.Gateway)
		if err != nil {
			return fmt.Errorf("Invalid gateway URL provided %v\n", err)
		}
		logger.Debugf("Posting to %v\n", do.Gateway)
	} else {
		logger.Debugf("Posting to gateway.ipfs.io\n")
	}

	if do.AddDir {
		logger.Debugf("Gonna add the contents of a directory =>\t\t%s:%v\n", do.Name, do.Path)
		hashes, err := exportDir(do.Name, do.Gateway)
		if err != nil {
			return err
		}
		do.Result = hashes
	} else {
		logger.Debugf("Gonna Add a file =>\t\t%s:%v\n", do.Name, do.Path)
		hash, err := exportFile(do.Name, do.Gateway)
		if err != nil {
			return err
		}
		do.Result = hash
	}
	return nil
}
开发者ID:alexandrev,项目名称:eris-cli,代码行数:30,代码来源:handle.go

示例2: RmData

// TODO: skip errors flag
func RmData(do *definitions.Do) (err error) {
	if len(do.Operations.Args) == 0 {
		do.Operations.Args = []string{do.Name}
	}
	for _, name := range do.Operations.Args {
		do.Name = name
		if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
			log.WithField("=>", do.Name).Info("Removing data container")

			srv := definitions.BlankServiceDefinition()
			srv.Operations.SrvContainerName = util.ContainersName("data", do.Name, do.Operations.ContainerNumber)

			if err = perform.DockerRemove(srv.Service, srv.Operations, false, do.Volumes); err != nil {
				log.Errorf("Error removing %s: %v", do.Name, err)
				return err
			}

		} else {
			err = fmt.Errorf("I cannot find that data container for %s. Please check the data container name you sent me.", do.Name)
			log.Error(err)
			return err
		}

		if do.RmHF {
			log.WithField("=>", do.Name).Warn("Removing host directory")
			if err = os.RemoveAll(filepath.Join(DataContainersPath, do.Name)); err != nil {
				return err
			}
		}
	}

	do.Result = "success"
	return err
}
开发者ID:mxjxn,项目名称:eris-cli,代码行数:35,代码来源:manage.go

示例3: ImportKey

func ImportKey(do *definitions.Do) error {

	do.Name = "keys"
	do.Operations.ContainerNumber = 1
	if err := srv.EnsureRunning(do); err != nil {
		return err
	}

	do.Operations.Interactive = false
	dir := path.Join(ErisContainerRoot, "keys", "data", do.Address)
	do.Operations.Args = []string{"mkdir", dir} //need to mkdir for import
	if err := srv.ExecService(do); err != nil {
		return err
	}
	//src on host

	if do.Source == "" {
		do.Source = filepath.Join(KeysPath, "data", do.Address, do.Address)
	}
	//dest in container
	do.Destination = dir

	if err := data.ImportData(do); err != nil {
		return err
	}
	return nil
}
开发者ID:mxjxn,项目名称:eris-cli,代码行数:27,代码来源:writers.go

示例4: bootDependencies

// boot chain dependencies
// TODO: this currently only supports simple services (with no further dependencies)
func bootDependencies(chain *definitions.Chain, do *definitions.Do) error {
	if chain.Dependencies != nil {
		name := do.Name
		logger.Infoln("Booting chain dependencies", chain.Dependencies.Services, chain.Dependencies.Chains)
		for _, srvName := range chain.Dependencies.Services {
			do.Name = srvName
			srv, err := loaders.LoadServiceDefinition(do.Name, false, do.Operations.ContainerNumber)
			if err != nil {
				return err
			}

			// Start corresponding service.
			if !services.IsServiceRunning(srv.Service, srv.Operations) {
				name := strings.ToUpper(do.Name)
				logger.Infof("%s is not running. Starting now. Waiting for %s to become available \n", name, name)
				if err = perform.DockerRunService(srv.Service, srv.Operations); err != nil {
					return err
				}
			}

		}
		do.Name = name // undo side effects

		for _, chainName := range chain.Dependencies.Chains {
			chn, err := loaders.LoadChainDefinition(chainName, false, do.Operations.ContainerNumber)
			if err != nil {
				return err
			}
			if !IsChainRunning(chn) {
				return fmt.Errorf("chain %s depends on chain %s but %s is not running", chain.Name, chainName, chainName)
			}
		}
	}
	return nil
}
开发者ID:alexandrev,项目名称:eris-cli,代码行数:37,代码来源:operate.go

示例5: checkErisContainerRoot

// check path for ErisContainerRoot
// XXX this is opiniated & we may want to change in future
// for more flexibility with filesystem of data conts
func checkErisContainerRoot(do *definitions.Do, typ string) error {

	r, err := regexp.Compile(ErisContainerRoot)
	if err != nil {
		return err
	}

	switch typ {
	case "import":
		if r.MatchString(do.Destination) != true { //if not there join it
			do.Destination = path.Join(ErisContainerRoot, do.Destination)
			return nil
		} else { // matches: do nothing
			return nil
		}
	case "export":
		if r.MatchString(do.Source) != true {
			do.Source = path.Join(ErisContainerRoot, do.Source)
			return nil
		} else {
			return nil
		}
	}
	return nil
}
开发者ID:mxjxn,项目名称:eris-cli,代码行数:28,代码来源:operate.go

示例6: ManagePinned

func ManagePinned(do *definitions.Do) error {
	ensureRunning()
	if do.Rm && do.Hash != "" {
		return fmt.Errorf("Either remove a file by hash or all of them\n")
	}

	if do.Rm {
		logger.Infoln("Removing all cached files")
		hashes, err := rmAllPinned()
		if err != nil {
			return err
		}
		do.Result = hashes
	} else if do.Hash != "" {
		logger.Infof("Removing %v, from cache", do.Hash)
		hashes, err := rmPinnedByHash(do.Hash)
		if err != nil {
			return err
		}
		do.Result = hashes
	} else {
		logger.Debugf("Listing files pinned locally")
		hash, err := listPinned()
		if err != nil {
			return err
		}
		do.Result = hash
	}
	return nil
}
开发者ID:alexandrev,项目名称:eris-cli,代码行数:30,代码来源:handle.go

示例7: RenameAction

func RenameAction(do *definitions.Do) error {
	if do.Name == do.NewName {
		return fmt.Errorf("Cannot rename to same name")
	}

	do.Name = strings.Replace(do.Name, " ", "_", -1)
	do.NewName = strings.Replace(do.NewName, " ", "_", -1)
	act, _, err := LoadActionDefinition(do.Name)
	if err != nil {
		log.WithFields(log.Fields{
			"from": do.Name,
			"to":   do.NewName,
		}).Debug("Failed renaming action")
		return err
	}

	do.Name = strings.Replace(do.Name, " ", "_", -1)
	log.WithField("file", do.Name).Debug("Finding action definition file")
	oldFile := util.GetFileByNameAndType("actions", do.Name)
	if oldFile == "" {
		return fmt.Errorf("Could not find that action definition file.")
	}
	log.WithField("file", oldFile).Debug("Found action definition file")

	// if !strings.Contains(oldFile, ActionsPath) {
	// 	oldFile = filepath.Join(ActionsPath, oldFile) + ".toml"
	// }

	var newFile string
	newNameBase := strings.Replace(strings.Replace(do.NewName, " ", "_", -1), filepath.Ext(do.NewName), "", 1)

	if newNameBase == do.Name {
		newFile = strings.Replace(oldFile, filepath.Ext(oldFile), filepath.Ext(do.NewName), 1)
	} else {
		newFile = strings.Replace(oldFile, do.Name, do.NewName, 1)
		newFile = strings.Replace(newFile, " ", "_", -1)
	}

	if newFile == oldFile {
		log.Info("Not renaming the same file")
		return nil
	}

	act.Name = strings.Replace(newNameBase, "_", " ", -1)

	log.WithFields(log.Fields{
		"old": act.Name,
		"new": newFile,
	}).Debug("Writing new action definition file")
	err = WriteActionDefinitionFile(act, newFile)
	if err != nil {
		return err
	}

	log.WithField("file", oldFile).Debug("Removing old file")
	os.Remove(oldFile)

	return nil
}
开发者ID:mxjxn,项目名称:eris-cli,代码行数:59,代码来源:manage.go

示例8: RenameAction

func RenameAction(do *definitions.Do) error {
	if do.Name == do.NewName {
		return fmt.Errorf("Cannot rename to same name")
	}

	do.Name = strings.Replace(do.Name, " ", "_", -1)
	do.NewName = strings.Replace(do.NewName, " ", "_", -1)
	act, _, err := LoadActionDefinition(do.Name)
	if err != nil {
		logger.Debugf("About to fail. Name:NewName =>\t%s:%s", do.Name, do.NewName)
		return err
	}

	do.Name = strings.Replace(do.Name, " ", "_", -1)
	logger.Debugf("About to find defFile =>\t%s\n", do.Name)
	oldFile := util.GetFileByNameAndType("actions", do.Name)
	if oldFile == "" {
		return fmt.Errorf("Could not find that action definition file.")
	}
	logger.Debugf("Found defFile at =>\t\t%s\n", oldFile)

	if !strings.Contains(oldFile, ActionsPath) {
		oldFile = filepath.Join(ActionsPath, oldFile) + ".toml"
	}

	var newFile string
	newNameBase := strings.Replace(strings.Replace(do.NewName, " ", "_", -1), filepath.Ext(do.NewName), "", 1)

	if newNameBase == do.Name {
		newFile = strings.Replace(oldFile, filepath.Ext(oldFile), filepath.Ext(do.NewName), 1)
	} else {
		newFile = strings.Replace(oldFile, do.Name, do.NewName, 1)
		newFile = strings.Replace(newFile, " ", "_", -1)
	}

	if newFile == oldFile {
		logger.Infoln("Those are the same file. Not renaming")
		return nil
	}

	act.Name = strings.Replace(newNameBase, "_", " ", -1)

	logger.Debugf("About to write new def file =>\t%s:%s\n", act.Name, newFile)
	err = WriteActionDefinitionFile(act, newFile)
	if err != nil {
		return err
	}

	logger.Debugf("Removing old file =>\t\t%s\n", oldFile)
	os.Remove(oldFile)

	return nil
}
开发者ID:kustomzone,项目名称:eris-cli,代码行数:53,代码来源:manage.go

示例9: ExecData

func ExecData(do *definitions.Do) error {
	if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
		do.Name = util.DataContainersName(do.Name, do.Operations.ContainerNumber)
		logger.Infoln("Running exec on container with volumes from data container " + do.Name)
		if err := perform.DockerRunVolumesFromContainer(do.Name, do.Interactive, do.Args); err != nil {
			return err
		}
	} else {
		return fmt.Errorf("I cannot find that data container. Please check the data container name you sent me.")
	}
	do.Result = "success"
	return nil
}
开发者ID:slowtokyo,项目名称:eris-cli,代码行数:13,代码来源:operate.go

示例10: CheckoutChain

func CheckoutChain(do *definitions.Do) error {
	if do.Name == "" {
		do.Result = "nil"
		return util.NullHead()
	}

	curHead, _ := util.GetHead()
	if do.Name == curHead {
		do.Result = "no change"
		return nil
	}

	return util.ChangeHead(do.Name)
}
开发者ID:mxjxn,项目名称:eris-cli,代码行数:14,代码来源:manage.go

示例11: ListAll

//XXX chains and services only
func ListAll(do *definitions.Do, typ string) (err error) {
	quiet := do.Quiet
	var result string
	if do.All == true { //overrides all the functionality used for flags/tests to stdout a nice table
		resK, err := ListKnown(typ)
		if err != nil {
			return err
		}
		do.Result = resK //for testing but not rly needed
		knowns := strings.Split(resK, "\n")
		typs := fmt.Sprintf("The known %s on your host kind marmot:", typ)
		log.WithField("=>", knowns[0]).Warn(typs)
		knowns = append(knowns[:0], knowns[1:]...)
		for _, known := range knowns {
			log.WithField("=>", known).Warn()
		}

		result, err = PrintTableReport(typ, true, true) //when latter bool is true, former one will be ignored...
		if err != nil {
			return err
		}
		contType := fmt.Sprintf("Active %s containers:", typ)
		log.Warn(contType)
		log.Warn(result)
	} else {

		var resK, resR, resE string

		if do.Known {
			if resK, err = ListKnown(typ); err != nil {
				return err
			}
			do.Result = resK
		}
		if do.Running {
			if resR, err = ListRunningOrExisting(quiet, false, typ); err != nil {
				return err
			}
			do.Result = resR
		}
		if do.Existing {
			if resE, err = ListRunningOrExisting(quiet, true, typ); err != nil {
				return err
			}
			do.Result = resE
		}
	}
	return nil
}
开发者ID:antonylewis,项目名称:eris-cli,代码行数:50,代码来源:listing_functions.go

示例12: ThrowAwayChain

// Throw away chains are used for eris contracts
func ThrowAwayChain(do *definitions.Do) error {
	do.Name = do.Name + "_" + strings.Split(uuid.New(), "-")[0]
	do.Path = filepath.Join(ChainsPath, "default")
	logger.Debugf("Making a ThrowAwayChain =>\t%s:%s\n", do.Name, do.Path)

	if err := NewChain(do); err != nil {
		return err
	}

	logger.Debugf("ThrowAwayChain created =>\t%s\n", do.Name)
	do.Run = true  // turns on edb api
	StartChain(do) // XXX [csk]: may not need to do this now that New starts....
	logger.Debugf("ThrowAwayChain started =>\t%s\n", do.Name)
	return nil
}
开发者ID:alexandrev,项目名称:eris-cli,代码行数:16,代码来源:operate.go

示例13: NewChain

func NewChain(do *definitions.Do) error {
	// read chainID from genesis. genesis may be in dir
	// if no genesis or no genesis.chain_id, chainID = name
	var err error
	if do.GenesisFile = resolveGenesisFile(do.GenesisFile, do.Path); do.GenesisFile == "" {
		do.ChainID = do.Name
	} else {
		do.ChainID, err = getChainIDFromGenesis(do.GenesisFile, do.Name)
		if err != nil {
			return err
		}
	}
	logger.Debugf("Starting Setup for ChnID =>\t%s\n", do.ChainID)
	return setupChain(do, loaders.ErisChainNew)
}
开发者ID:slowtokyo,项目名称:eris-cli,代码行数:15,代码来源:operate.go

示例14: PlopChain

func PlopChain(do *definitions.Do) error {
	do.Name = do.ChainID
	rootDir := path.Join("/home/eris/.eris/blockchains", do.ChainID)
	switch do.Type {
	case "genesis":
		do.Args = []string{"cat", path.Join(rootDir, "genesis.json")}
	case "config":
		do.Args = []string{"cat", path.Join(rootDir, "config.toml")}
	case "status":
		do.Args = []string{"mintinfo", "--node-addr", "http://0.0.0.0:46657", "status"}
	default:
		return fmt.Errorf("unknown plop option %s", do.Type)
	}
	return ExecChain(do)
}
开发者ID:jumanjiman,项目名称:eris-cli,代码行数:15,代码来源:manage.go

示例15: NewService

func NewService(do *definitions.Do) error {
	srv := definitions.BlankServiceDefinition()
	srv.Name = do.Name
	srv.Service.Name = do.Name
	srv.Service.Image = do.Operations.Args[0]
	srv.Service.AutoData = true

	var err error
	//get maintainer info
	srv.Maintainer.Name, srv.Maintainer.Email, err = config.GitConfigUser()
	if err != nil {
		log.Debug(err.Error())
	}

	log.WithFields(log.Fields{
		"service": srv.Service.Name,
		"image":   srv.Service.Image,
	}).Debug("Creating a new service definition file")
	err = WriteServiceDefinitionFile(srv, filepath.Join(ServicesPath, do.Name+".toml"))
	if err != nil {
		return err
	}
	do.Result = "success"
	return nil
}
开发者ID:antonylewis,项目名称:eris-cli,代码行数:25,代码来源:manage.go


注:本文中的github.com/eris-ltd/eris-cli/definitions.Do类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。