本文整理匯總了Golang中gate/core.Config.Eval方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.Eval方法的具體用法?Golang Config.Eval怎麽用?Golang Config.Eval使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gate/core.Config
的用法示例。
在下文中一共展示了Config.Eval方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: networkConfig
func networkConfig(config core.Config) (host, port string) {
var e error
host, e = config.Eval("", "connection", "host", os.Getenv)
if e != nil {
host = "127.0.0.1"
}
port, e = config.Eval("", "connection", "port", os.Getenv)
if e != nil {
port = "8532"
}
return
}
示例3: 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
}
示例4: 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
}
示例5: newScp
func newScp(name string, srv server.Server, config core.Config, remoter Remoter) (Remote, error) {
result := &scp{
properties{
allowed: ScpAllowedKeys,
properties: make(map[string]string),
},
srv,
remoter,
name,
nil,
}
file := name + ".rc"
for key, mandatory := range ScpAllowedKeys {
value, err := config.Eval(file, "remote", key, os.Getenv)
if err != nil && mandatory {
return nil, err
}
if value != "" {
result.properties.setProperty(key, value)
}
}
return result, nil
}