本文整理匯總了Golang中github.com/eris-ltd/eris-cli/definitions.Do.Result方法的典型用法代碼示例。如果您正苦於以下問題:Golang Do.Result方法的具體用法?Golang Do.Result怎麽用?Golang Do.Result使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/eris-ltd/eris-cli/definitions.Do
的用法示例。
在下文中一共展示了Do.Result方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: 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)
}
示例4: 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
}
示例5: RmData
func RmData(do *definitions.Do) error {
if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
logger.Infoln("Removing data container " + do.Name)
srv := definitions.BlankServiceDefinition()
srv.Operations.SrvContainerName = util.ContainersName("data", do.Name, do.Operations.ContainerNumber)
err := perform.DockerRemove(srv.Service, srv.Operations, false)
if err != nil {
return err
}
} else {
return fmt.Errorf("I cannot find that data container. Please check the data container name you sent me.")
}
if do.RmHF {
logger.Println("Removing host folder " + do.Name)
err := os.RemoveAll(path.Join(DataContainersPath, do.Name))
if err != nil {
return err
}
}
do.Result = "success"
return nil
}
示例6: ImportService
func ImportService(do *definitions.Do) error {
fileName := filepath.Join(ServicesPath, do.Name)
if filepath.Ext(fileName) == "" {
fileName = fileName + ".toml"
}
var err error
if log.GetLevel() > 0 {
err = ipfs.GetFromIPFS(do.Hash, fileName, "", os.Stdout)
} else {
err = ipfs.GetFromIPFS(do.Hash, fileName, "", bytes.NewBuffer([]byte{}))
}
if err != nil {
return err
}
_, err = loaders.LoadServiceDefinition(do.Name, false, 0)
//XXX add protections?
if err != nil {
return fmt.Errorf("Your service definition file looks improperly formatted and will not marshal.")
}
do.Result = "success"
return nil
}
示例7: 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
}
示例8: ImportService
func ImportService(do *definitions.Do) error {
fileName := filepath.Join(ServicesPath, do.Name)
if filepath.Ext(fileName) == "" {
fileName = fileName + ".toml"
}
s := strings.Split(do.Path, ":")
if s[0] == "ipfs" {
var err error
if logger.Level > 0 {
err = ipfs.GetFromIPFS(s[1], fileName, "", logger.Writer)
} else {
err = ipfs.GetFromIPFS(s[1], fileName, "", bytes.NewBuffer([]byte{}))
}
if err != nil {
return err
}
return nil
}
if strings.Contains(s[0], "github") {
logger.Errorln("https://twitter.com/ryaneshea/status/595957712040628224")
return nil
}
do.Result = "success"
return fmt.Errorf("I do not know how to get that file. Sorry.")
}
示例9: ImportService
func ImportService(do *definitions.Do) error {
fileName := filepath.Join(ServicesPath, do.Name)
if filepath.Ext(fileName) == "" {
fileName = fileName + ".toml"
}
var err error
if logger.Level > 0 {
err = ipfs.GetFromIPFS(do.Hash, fileName, "", logger.Writer)
} else {
err = ipfs.GetFromIPFS(do.Hash, fileName, "", bytes.NewBuffer([]byte{}))
}
if err != nil {
return err
//return fmt.Errorf("I do not know how to get that file. Sorry. %v\n", err)
}
_, err = loaders.LoadServiceDefinition(do.Name, false, 0)
//XXX add protections?
if err != nil {
return fmt.Errorf("Your service defintion file looks improperly formatted and will not marshal.")
}
do.Result = "success"
return nil
}
示例10: NewService
func NewService(do *definitions.Do) error {
srv := definitions.BlankServiceDefinition()
srv.Name = do.Name
srv.Service.Name = do.Name
srv.Service.Image = do.Args[0]
srv.Service.AutoData = true
//get maintainer info
uName, err := gitconfig.Username()
if err != nil {
logger.Debugf("Could not find git user.name, setting service.Maintainer.Name = \"\"")
uName = ""
}
email, err := gitconfig.Email()
if err != nil {
logger.Debugf("Could not find git user.email, setting service.Maintainer.Email = \"\"")
email = ""
}
srv.Maintainer.Name = uName
srv.Maintainer.Email = email
logger.Debugf("Creating a new srv def file =>\t%s:%s\n", srv.Service.Name, srv.Service.Image)
err = WriteServiceDefinitionFile(srv, path.Join(ServicesPath, do.Name+".toml"))
if err != nil {
return err
}
do.Result = "success"
return nil
}
示例11: 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
}
示例12: PutPackage
// TODO: finish when the PR which is blocking
// eris files put --dir is integrated into
// ipfs
func PutPackage(do *definitions.Do) error {
// do.Name = args[0]
var hash string = ""
do.Result = hash
return nil
}
示例13: RmService
func RmService(do *definitions.Do) error {
for _, servName := range do.Args {
service, err := loaders.LoadServiceDefinition(servName, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if IsServiceExisting(service.Service, service.Operations) {
err = perform.DockerRemove(service.Service, service.Operations, do.RmD)
if err != nil {
return err
}
}
if do.File {
oldFile := util.GetFileByNameAndType("services", servName)
if err != nil {
return err
}
oldFile = path.Join(ServicesPath, oldFile) + ".toml"
logger.Printf("Removing file =>\t\t%s\n", oldFile)
if err := os.Remove(oldFile); err != nil {
return err
}
}
}
do.Result = "success"
return nil
}
示例14: ImportData
// ImportData does what it says. It imports from a host's Source to a Dest
// in a data container. It returns an error.
//
// do.Name - name of the data container to use (required)
// do.Operations.ContainerNumber - container number (optional)
// do.Source - directory which should be imported (required)
// do.Destination - directory to _unload_ the payload into (required)
//
func ImportData(do *definitions.Do) error {
log.WithFields(log.Fields{
"from": do.Source,
"to": do.Destination,
}).Debug("Importing")
if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
srv := PretendToBeAService(do.Name, do.Operations.ContainerNumber)
service, exists := perform.ContainerExists(srv.Operations)
if !exists {
return fmt.Errorf("There is no data container for that service.")
}
if err := checkErisContainerRoot(do, "import"); err != nil {
return err
}
containerName := util.DataContainersName(do.Name, do.Operations.ContainerNumber)
os.Chdir(do.Source)
reader, err := util.Tar(do.Source, 0)
if err != nil {
return err
}
defer reader.Close()
opts := docker.UploadToContainerOptions{
InputStream: reader,
Path: do.Destination,
NoOverwriteDirNonDir: true,
}
log.WithField("=>", containerName).Info("Copying into container")
log.WithField("path", do.Source).Debug()
if err := util.DockerClient.UploadToContainer(service.ID, opts); err != nil {
return err
}
doChown := definitions.NowDo()
doChown.Operations.DataContainerName = containerName
doChown.Operations.ContainerType = "data"
doChown.Operations.ContainerNumber = do.Operations.ContainerNumber
//required b/c `docker cp` (UploadToContainer) goes in as root
doChown.Operations.Args = []string{"chown", "--recursive", "eris", do.Destination}
_, err = perform.DockerRunData(doChown.Operations, nil)
if err != nil {
return fmt.Errorf("Error changing owner: %v\n", err)
}
} else {
log.WithField("name", do.Name).Info("Data container does not exist.")
ops := loaders.LoadDataDefinition(do.Name, do.Operations.ContainerNumber)
if err := perform.DockerCreateData(ops); err != nil {
return fmt.Errorf("Error creating data container %v.", err)
}
return ImportData(do)
}
do.Result = "success"
return nil
}
示例15: StartChain
func StartChain(do *definitions.Do) error {
logger.Infoln("Ensuring Key Server is Started.")
//should it take a flag? keys server may be running another cNum
// XXX: currently we don't use or need a key server.
// plus this should be specified in a service def anyways
keysService, err := loaders.LoadServiceDefinition("keys", false, 1)
if err != nil {
return err
}
err = perform.DockerRun(keysService.Service, keysService.Operations)
if err != nil {
return err
}
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
logger.Infoln("Cannot start a chain I cannot find.")
do.Result = "no file"
return nil
}
if chain.Name == "" {
logger.Infoln("Cannot start a chain without a name.")
do.Result = "no name"
return nil
}
chain.Service.Command = loaders.ErisChainStart
if do.Run {
chain.Service.Command = loaders.ErisChainStartApi
}
util.OverWriteOperations(chain.Operations, do.Operations)
chain.Service.Environment = append(chain.Service.Environment, "CHAIN_ID="+chain.ChainID)
logger.Infof("StartChainRaw to DockerRun =>\t%s\n", chain.Service.Name)
logger.Debugf("\twith ChainID =>\t\t%v\n", chain.ChainID)
logger.Debugf("\twith Environment =>\t%v\n", chain.Service.Environment)
logger.Debugf("\twith AllPortsPublshd =>\t%v\n", chain.Operations.PublishAllPorts)
if err := perform.DockerRun(chain.Service, chain.Operations); err != nil {
do.Result = "error"
return err
}
return nil
}