• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang errors.Decorated函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Stop

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


示例17: Unset

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


示例18: proxy

func proxy(config core.Config) (result server.Server, err error) {
	result = _proxy
	if result == nil {
		s, err := serverimpl.Proxy(config, startServer)
		if err != nil {
			return
		}

		var isopen bool
		err = s.IsOpen(false, &isopen)
		if err != nil {
			err = errors.Decorated(err)
			return
		}

		if !isopen {
			err = openVault(s, config)
			if err != nil {
				return
			}
		}

		result = s
		_proxy = result
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:27,代码来源:proxy.go


示例19: storeProperties

func (self *properties) storeProperties(out io.Writer) (err error) {
	if err != nil {
		return errors.Decorated(err)
	}

	for property, value := range self.properties {
		if value != "" {
			_, err = out.Write([]byte(fmt.Sprintf("%s = %s\n", property, value)))
			if err != nil {
				return errors.Decorated(err)
			}
		}
	}

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


示例20: Open

func (self *vault) Open(master string, config core.Config) (err error) {
	instream, err := self.in()
	if err != nil {
		return errors.Decorated(err)
	}
	defer instream.Close()

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

	barrier := make(chan error)

	prepare := func(cmd *exec.Cmd) (err error) {
		cmd.Env = append(os.Environ(), fmt.Sprintf("VAULT_MASTER=%s", master))
		cmd.Stdin = instream

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

		go self.decode(self, out, barrier)

		return
	}

	run := func(cmd *exec.Cmd) (err error) {
		e := <-barrier
		if e != io.EOF {
			err = errors.Decorated(e)
		}

		return
	}

	err = exec.Command(prepare, run, "openssl", cipher, "-d", "-a", "-pass", "env:VAULT_MASTER")
	if err != nil {
		return
	}

	self.master = master
	self.open = true
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:46,代码来源:vault.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang errors.Newf函数代码示例发布时间:2022-05-24
下一篇:
Golang core.Config类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap