本文整理匯總了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}