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


Golang errors.Decorated函数代码示例

本文整理汇总了Golang中gate/core/errors.Decorated函数的典型用法代码示例。如果您正苦于以下问题:Golang Decorated函数的具体用法?Golang Decorated怎么用?Golang Decorated使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: Pager

func (self *interaction) Pager(text string) (err error) {
	pipe := make(chan io.WriteCloser, 1)

	prepare := func(cmd *exec.Cmd) (err error) {
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		p, err := cmd.StdinPipe()
		if err != nil {
			return errors.Decorated(err)
		}
		pipe <- p
		return
	}

	run := func(cmd *exec.Cmd) (err error) {
		p := <-pipe
		p.Write([]byte(text))
		err = p.Close()
		if err != nil {
			return errors.Decorated(err)
		}
		return
	}

	err = exec.Command(prepare, run, "less", "-R")
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:27,代码来源:pager.go

示例2: xclip

func xclip(name string, selection string) (err error) {
	pipe := make(chan io.WriteCloser, 1)

	prepare := func(cmd *exec.Cmd) (err error) {
		p, err := cmd.StdinPipe()
		if err != nil {
			return errors.Decorated(err)
		}
		pipe <- p
		return
	}

	run := func(cmd *exec.Cmd) (err error) {
		p := <-pipe
		p.Write([]byte(name))
		err = p.Close()
		if err != nil {
			return errors.Decorated(err)
		}
		return
	}

	err = exec.Command(prepare, run, "xclip", "-selection", selection)
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:25,代码来源:xclip.go

示例3: Command

// Spawn a given command.
//  - prepare() is called after the command creation but before actually starting it
//  - run() is called while the command is running and before waiting for its completion
func Command(prepare func(cmd *Cmd) error, run func(cmd *Cmd) error, command string, arguments ...string) (err error) {
	cmd := exec.Command(command, arguments...)

	if prepare != nil {
		err = prepare((*Cmd)(cmd))
		if err != nil {
			return
		}
	}

	err = cmd.Start()
	if err != nil {
		return errors.Decorated(err)
	}

	if run != nil {
		err = run((*Cmd)(cmd))
		if err != nil {
			return
		}
	}

	err = cmd.Wait()
	if err != nil {
		return errors.Decorated(err)
	}

	return
}
开发者ID:cadrian,项目名称:gate,代码行数:32,代码来源:exec.go

示例4: ReadPassword

func (self *interaction) ReadPassword(text string) (result string, err error) {
	command, err := self.config.Eval("", "password", "command", os.Getenv)
	if err != nil {
		return
	}
	env := func(name string) string {
		switch name {
		case "TEXT":
			return text
		}
		return ""
	}
	arguments, err := self.config.Eval("", "password", "arguments", env)
	if err != nil {
		return
	}

	buffer := &bytes.Buffer{}

	type barrierData struct {
		n   int64
		err error
	}
	barrier := make(chan barrierData)

	prepare := func(cmd *exec.Cmd) (err error) {
		out, err := cmd.StdoutPipe()
		if err != nil {
			return errors.Decorated(err)
		}

		go func() {
			n, err := buffer.ReadFrom(out)
			barrier <- barrierData{n, err}
		}()
		return
	}

	resulter := make(chan string, 1)

	run := func(cmd *exec.Cmd) (err error) {
		data := <-barrier
		if data.err != nil {
			return errors.Decorated(err)
		}

		// the last character is a \n -- ignore it
		resulter <- string(buffer.Bytes()[:data.n-1])

		return
	}

	err = exec.Command(prepare, run, "bash", "-c", fmt.Sprintf("%s %s", command, arguments))
	if err != nil {
		return
	}

	result = <-resulter
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:60,代码来源:readpass.go

示例5: ListConfigFiles

func (self *config) ListConfigFiles() (result []string, err error) {
	xdg, err := self.Xdg()
	if err != nil {
		return
	}
	config_path, err := xdg.ConfigHome()
	if err != nil {
		return
	}
	config, err := os.Open(config_path)
	if err != nil {
		err = errors.Decorated(err)
		return
	}
	names, err := config.Readdirnames(0)
	if err != nil {
		err = errors.Decorated(err)
		return
	}
	result = make([]string, 0, len(names)-1)
	for _, name := range names {
		if name != "config.rc" && strings.HasSuffix(name, ".rc") {
			result = append(result, name)
		}
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:27,代码来源:config.go

示例6: displayMenu

func displayMenu(config core.Config, srv server.Server, list []string) (err error) {
	command, err := config.Eval("", "menu", "command", os.Getenv)
	if err != nil {
		return
	}
	arguments, err := config.Eval("", "menu", "arguments", nil)
	if err != nil {
		return
	}

	barrier := make(chan error)
	pipe := make(chan io.WriteCloser, 1)

	prepare := func(cmd *exec.Cmd) (err error) {
		p, err := cmd.StdinPipe()
		if err != nil {
			return errors.Decorated(err)
		}

		out, err := cmd.StdoutPipe()
		if err != nil {
			return errors.Decorated(err)
		}

		mmi, err := ui.Ui(srv, config)
		if err != nil {
			return
		}

		go clipboard(mmi, out, barrier)

		pipe <- p
		return
	}

	run := func(cmd *exec.Cmd) (err error) {
		p := <-pipe

		for _, entry := range list {
			p.Write([]byte(entry + "\n"))
		}

		err = p.Close()
		if err != nil {
			return errors.Decorated(err)
		}

		e := <-barrier
		if e != io.EOF {
			err = errors.Decorated(e)
		}
		return
	}

	err = exec.Command(prepare, run, "bash", "-c", fmt.Sprintf("%s %s", command, arguments))

	return
}
开发者ID:cadrian,项目名称:gate,代码行数:58,代码来源:menu.go

示例7: save

func (self *vault) save(config core.Config) (err error) {
	outstream, err := self.out()
	if err != nil {
		return errors.Decorated(err)
	}
	defer outstream.Close()

	cipher, err := config.Eval("", "vault", "openssl.cipher", os.Getenv)
	if err != nil {
		return err
	}

	pipe := make(chan io.WriteCloser, 1)

	prepare := func(cmd *exec.Cmd) (err error) {
		cmd.Env = append(os.Environ(), fmt.Sprintf("VAULT_MASTER=%s", self.master))
		cmd.Stdout = outstream
		p, err := cmd.StdinPipe()
		if err != nil {
			return errors.Decorated(err)
		}
		pipe <- p
		return
	}

	run := func(cmd *exec.Cmd) (err error) {
		p := <-pipe
		for _, k := range self.data {
			code := k.Encoded()
			n, err := p.Write([]byte(code))
			if err != nil {
				return errors.Decorated(err)
			}
			if n < len(code) {
				return errors.Newf("Incomplete write")
			}
		}
		err = p.Close()
		if err != nil {
			return errors.Decorated(err)
		}
		return
	}

	err = exec.Command(prepare, run, "openssl", cipher, "-a", "-pass", "env:VAULT_MASTER")

	return
}
开发者ID:cadrian,项目名称:gate,代码行数:48,代码来源:vault.go

示例8: Ping

func (self *httpChannelClient) Ping(info string, reply *string) (err error) {
	err = self.client.Call("Gate.Ping", info, reply)
	if err != nil {
		err = errors.Decorated(err)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:7,代码来源:http.go

示例9: SetMaster

func (self *httpChannelClient) SetMaster(master string, reply *bool) (err error) {
	err = self.client.Call("Gate.SetMaster", master, reply)
	if err != nil {
		err = errors.Decorated(err)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:7,代码来源:http.go

示例10: Set

func (self *httpChannelClient) Set(args server.SetArgs, reply *string) (err error) {
	err = self.client.Call("Gate.Set", args, reply)
	if err != nil {
		err = errors.Decorated(err)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:7,代码来源:http.go

示例11: Save

func (self *httpChannelClient) Save(force bool, reply *bool) (err error) {
	err = self.client.Call("Gate.Save", force, reply)
	if err != nil {
		err = errors.Decorated(err)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:7,代码来源:http.go

示例12: Merge

func (self *httpChannelClient) Merge(args server.MergeArgs, reply *bool) (err error) {
	err = self.client.Call("Gate.Merge", args, reply)
	if err != nil {
		err = errors.Decorated(err)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:7,代码来源:http.go

示例13: List

func (self *httpChannelClient) List(filter string, reply *[]string) (err error) {
	err = self.client.Call("Gate.List", filter, reply)
	if err != nil {
		err = errors.Decorated(err)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:7,代码来源:http.go

示例14: Get

func (self *httpChannelClient) Get(name string, reply *string) (err error) {
	err = self.client.Call("Gate.Get", name, reply)
	if err != nil {
		err = errors.Decorated(err)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:7,代码来源:http.go

示例15: IsOpen

func (self *httpChannelClient) IsOpen(thenClose bool, reply *bool) (err error) {
	err = self.client.Call("Gate.IsOpen", thenClose, reply)
	if err != nil {
		err = errors.Decorated(err)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:7,代码来源:http.go


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