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


Golang sockets.Dial函数代码示例

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


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

示例1: step

func (cmds asyncRunCommands) step(c *gc.C, ctx *context) {
	commands := strings.Join(cmds, "\n")
	args := uniter.RunCommandsArgs{
		Commands:       commands,
		RelationId:     -1,
		RemoteUnitName: "",
	}

	var socketPath string
	if runtime.GOOS == "windows" {
		socketPath = `\\.\pipe\unit-u-0-run`
	} else {
		socketPath = filepath.Join(ctx.path, "run.socket")
	}

	ctx.wg.Add(1)
	go func() {
		defer ctx.wg.Done()
		// make sure the socket exists
		client, err := sockets.Dial(socketPath)
		// Don't use asserts in go routines.
		if !c.Check(err, jc.ErrorIsNil) {
			return
		}
		defer client.Close()

		var result utilexec.ExecResponse
		err = client.Call(uniter.JujuRunEndpoint, args, &result)
		if c.Check(err, jc.ErrorIsNil) {
			c.Check(result.Code, gc.Equals, 0)
			c.Check(string(result.Stdout), gc.Equals, "")
			c.Check(string(result.Stderr), gc.Equals, "")
		}
	}()
}
开发者ID:bac,项目名称:juju,代码行数:35,代码来源:util_test.go

示例2: executeInUnitContext

func (c *RunCommand) executeInUnitContext() (*exec.ExecResponse, error) {
	unitDir := agent.Dir(cmdutil.DataDir, c.unit)
	logger.Debugf("looking for unit dir %s", unitDir)
	// make sure the unit exists
	_, err := os.Stat(unitDir)
	if os.IsNotExist(err) {
		return nil, errors.Errorf("unit %q not found on this machine", c.unit.Id())
	} else if err != nil {
		return nil, errors.Trace(err)
	}

	relationId, err := checkRelationId(c.relationId)
	if err != nil {
		return nil, errors.Trace(err)
	}

	if len(c.remoteUnitName) > 0 && relationId == -1 {
		return nil, errors.Errorf("remote unit: %s, provided without a relation", c.remoteUnitName)
	}
	client, err := sockets.Dial(c.socketPath())
	if err != nil {
		return nil, errors.Trace(err)
	}
	defer client.Close()

	var result exec.ExecResponse
	args := uniter.RunCommandsArgs{
		Commands:        c.commands,
		RelationId:      relationId,
		RemoteUnitName:  c.remoteUnitName,
		ForceRemoteUnit: c.forceRemoteUnit,
	}
	err = client.Call(uniter.JujuRunEndpoint, args, &result)
	return &result, errors.Trace(err)
}
开发者ID:imoapps,项目名称:juju,代码行数:35,代码来源:run.go

示例3: Call

func (s *ServerSuite) Call(c *gc.C, req jujuc.Request) (resp exec.ExecResponse, err error) {
	client, err := sockets.Dial(s.sockPath)
	c.Assert(err, jc.ErrorIsNil)
	defer client.Close()
	err = client.Call("Jujuc.Main", req, &resp)
	return resp, err
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:server_test.go

示例4: jujuCMain

// jujuCMain uses JUJU_CONTEXT_ID and JUJU_AGENT_SOCKET to ask a running unit agent
// to execute a Command on our behalf. Individual commands should be exposed
// by symlinking the command name to this executable.
func jujuCMain(commandName string, args []string) (code int, err error) {
	code = 1
	contextId, err := getenv("JUJU_CONTEXT_ID")
	if err != nil {
		return
	}
	dir, err := getwd()
	if err != nil {
		return
	}
	req := jujuc.Request{
		ContextId:   contextId,
		Dir:         dir,
		CommandName: commandName,
		Args:        args[1:],
	}
	socketPath, err := getenv("JUJU_AGENT_SOCKET")
	if err != nil {
		return
	}
	client, err := sockets.Dial(socketPath)
	if err != nil {
		return
	}
	defer client.Close()
	var resp exec.ExecResponse
	err = client.Call("Jujuc.Main", req, &resp)
	if err != nil {
		return
	}
	os.Stdout.Write(resp.Stdout)
	os.Stderr.Write(resp.Stderr)
	return resp.Code, nil
}
开发者ID:zhouqt,项目名称:juju,代码行数:37,代码来源:main.go

示例5: TestClientCall

func (s *ListenerSuite) TestClientCall(c *gc.C) {
	s.NewRunListener(c)

	client, err := sockets.Dial(s.socketPath)
	c.Assert(err, gc.IsNil)
	defer client.Close()

	var result exec.ExecResponse
	err = client.Call(uniter.JujuRunEndpoint, "some-command", &result)
	c.Assert(err, gc.IsNil)

	c.Assert(string(result.Stdout), gc.Equals, "some-command stdout")
	c.Assert(string(result.Stderr), gc.Equals, "some-command stderr")
	c.Assert(result.Code, gc.Equals, 42)
}
开发者ID:kapilt,项目名称:juju,代码行数:15,代码来源:runlistener_test.go

示例6: jujuCMain

// jujuCMain uses JUJU_CONTEXT_ID and JUJU_AGENT_SOCKET to ask a running unit agent
// to execute a Command on our behalf. Individual commands should be exposed
// by symlinking the command name to this executable.
func jujuCMain(commandName string, ctx *cmd.Context, args []string) (code int, err error) {
	code = 1
	contextId, err := getenv("JUJU_CONTEXT_ID")
	if err != nil {
		return
	}
	dir, err := getwd()
	if err != nil {
		return
	}
	req := jujuc.Request{
		ContextId:   contextId,
		Dir:         dir,
		CommandName: commandName,
		Args:        args[1:],
	}
	socketPath, err := getenv("JUJU_AGENT_SOCKET")
	if err != nil {
		return
	}
	client, err := sockets.Dial(socketPath)
	if err != nil {
		return
	}
	defer client.Close()
	var resp exec.ExecResponse
	err = client.Call("Jujuc.Main", req, &resp)
	if err != nil && err.Error() == jujuc.ErrNoStdin.Error() {
		req.Stdin, err = ioutil.ReadAll(os.Stdin)
		if err != nil {
			err = errors.Annotate(err, "cannot read stdin")
			return
		}
		req.StdinSet = true
		err = client.Call("Jujuc.Main", req, &resp)
	}
	if err != nil {
		return
	}
	os.Stdout.Write(resp.Stdout)
	os.Stderr.Write(resp.Stderr)
	return resp.Code, nil
}
开发者ID:kakamessi99,项目名称:juju,代码行数:46,代码来源:main.go

示例7: TestClientCall

func (s *ListenerSuite) TestClientCall(c *gc.C) {
	s.NewRunListener(c)

	client, err := sockets.Dial(s.socketPath)
	c.Assert(err, jc.ErrorIsNil)
	defer client.Close()

	var result exec.ExecResponse
	args := uniter.RunCommandsArgs{
		Commands:        "some-command",
		RelationId:      -1,
		RemoteUnitName:  "",
		ForceRemoteUnit: false,
	}
	err = client.Call(uniter.JujuRunEndpoint, args, &result)
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(string(result.Stdout), gc.Equals, "some-command stdout")
	c.Assert(string(result.Stderr), gc.Equals, "some-command stderr")
	c.Assert(result.Code, gc.Equals, 42)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:21,代码来源:runlistener_test.go

示例8: executeInUnitContext

func (c *RunCommand) executeInUnitContext() (*exec.ExecResponse, error) {
	unitDir := filepath.Join(AgentDir, c.unit)
	logger.Debugf("looking for unit dir %s", unitDir)
	// make sure the unit exists
	_, err := os.Stat(unitDir)
	if os.IsNotExist(err) {
		return nil, fmt.Errorf("unit %q not found on this machine", c.unit)
	} else if err != nil {
		return nil, err
	}
	// make sure the socket exists
	socketPath := c.sockPath()
	client, err := sockets.Dial(socketPath)
	if err != nil {
		return nil, err
	}
	defer client.Close()

	var result exec.ExecResponse
	err = client.Call(uniter.JujuRunEndpoint, c.commands, &result)
	return &result, err
}
开发者ID:kapilt,项目名称:juju,代码行数:22,代码来源:run.go


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