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

Golang proxy.Settings类代码示例

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

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



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

示例1: GetProxySettings

// GetProxySettings is defined on the PackageManager interface.
func (apt *apt) GetProxySettings() (proxy.Settings, error) {
	var res proxy.Settings

	args := strings.Fields(apt.cmder.GetProxyCmd())
	if len(args) <= 1 {
		return proxy.Settings{}, fmt.Errorf("expected at least 2 arguments, got %d %v", len(args), args)
	}

	cmd := exec.Command(args[0], args[1:]...)
	out, err := CommandOutput(cmd)

	if err != nil {
		logger.Errorf("command failed: %v\nargs: %#v\n%s",
			err, args, string(out))
		return res, fmt.Errorf("command failed: %v", err)
	}

	output := string(bytes.Join(proxyRE.FindAll(out, -1), []byte("\n")))

	for _, match := range proxyRE.FindAllStringSubmatch(output, -1) {
		switch match[1] {
		case "http":
			res.Http = match[2]
		case "https":
			res.Https = match[2]
		case "ftp":
			res.Ftp = match[2]
		}
	}

	return res, nil
}
开发者ID:anastasiamac,项目名称:utils,代码行数:33,代码来源:apt.go


示例2: TestSetEnvironmentValues

func (s *proxySuite) TestSetEnvironmentValues(c *gc.C) {
	s.PatchEnvironment("http_proxy", "initial")
	s.PatchEnvironment("HTTP_PROXY", "initial")
	s.PatchEnvironment("https_proxy", "initial")
	s.PatchEnvironment("HTTPS_PROXY", "initial")
	s.PatchEnvironment("ftp_proxy", "initial")
	s.PatchEnvironment("FTP_PROXY", "initial")
	s.PatchEnvironment("no_proxy", "initial")
	s.PatchEnvironment("NO_PROXY", "initial")

	proxySettings := proxy.Settings{
		Http:  "http proxy",
		Https: "https proxy",
		// Ftp left blank to show clearing env.
		NoProxy: "10.0.3.1,localhost",
	}
	proxySettings.SetEnvironmentValues()

	obtained := proxy.DetectProxies()

	c.Assert(obtained, gc.DeepEquals, proxySettings)

	c.Assert(os.Getenv("http_proxy"), gc.Equals, "http proxy")
	c.Assert(os.Getenv("HTTP_PROXY"), gc.Equals, "http proxy")
	c.Assert(os.Getenv("https_proxy"), gc.Equals, "https proxy")
	c.Assert(os.Getenv("HTTPS_PROXY"), gc.Equals, "https proxy")
	c.Assert(os.Getenv("ftp_proxy"), gc.Equals, "")
	c.Assert(os.Getenv("FTP_PROXY"), gc.Equals, "")
	c.Assert(os.Getenv("no_proxy"), gc.Equals, "10.0.3.1,localhost")
	c.Assert(os.Getenv("NO_PROXY"), gc.Equals, "10.0.3.1,localhost")
}
开发者ID:juju,项目名称:utils,代码行数:31,代码来源:proxy_test.go


示例3: GetProxySettings

// GetProxySettings is defined on the PackageManager interface.
func (yum *yum) GetProxySettings() (proxy.Settings, error) {
	var res proxy.Settings

	args := strings.Fields(yum.cmder.GetProxyCmd())
	if len(args) <= 1 {
		return proxy.Settings{}, fmt.Errorf("expected at least 2 arguments, got %d %v", len(args), args)
	}

	cmd := exec.Command(args[0], args[1:]...)
	out, err := CommandOutput(cmd)

	if err != nil {
		logger.Errorf("command failed: %v\nargs: %#v\n%s",
			err, args, string(out))
		return res, fmt.Errorf("command failed: %v", err)
	}

	for _, match := range strings.Split(string(out), "\n") {
		fields := strings.Split(match, "=")
		if len(fields) != 2 {
			continue
		}

		if strings.HasPrefix(fields[0], "https") {
			res.Https = strings.TrimSpace(fields[1])
		} else if strings.HasPrefix(fields[0], "http") {
			res.Http = strings.TrimSpace(fields[1])
		} else if strings.HasPrefix(fields[0], "ftp") {
			res.Ftp = strings.TrimSpace(fields[1])
		}
	}

	return res, nil
}
开发者ID:rogpeppe,项目名称:juju-utils,代码行数:35,代码来源:yum.go


示例4: TestAsScriptEnvironmentOneValue

func (s *proxySuite) TestAsScriptEnvironmentOneValue(c *gc.C) {
	proxies := proxy.Settings{
		Http: "some-value",
	}
	expected := `
export http_proxy=some-value
export HTTP_PROXY=some-value`[1:]
	c.Assert(proxies.AsScriptEnvironment(), gc.Equals, expected)
}
开发者ID:juju,项目名称:utils,代码行数:9,代码来源:proxy_test.go


示例5: TestAsEnvironmentValuesOneValue

func (s *proxySuite) TestAsEnvironmentValuesOneValue(c *gc.C) {
	proxies := proxy.Settings{
		Http: "some-value",
	}
	expected := []string{
		"http_proxy=some-value",
		"HTTP_PROXY=some-value",
	}
	c.Assert(proxies.AsEnvironmentValues(), gc.DeepEquals, expected)
}
开发者ID:juju,项目名称:utils,代码行数:10,代码来源:proxy_test.go


示例6: handleProxyValues

func (w *proxyWorker) handleProxyValues(proxySettings proxyutils.Settings) {
	proxySettings.SetEnvironmentValues()
	if proxySettings != w.proxy || w.first {
		logger.Debugf("new proxy settings %#v", proxySettings)
		w.proxy = proxySettings
		if err := w.writeEnvironment(); err != nil {
			// It isn't really fatal, but we should record it.
			logger.Errorf("error writing proxy environment file: %v", err)
		}
	}
}
开发者ID:makyo,项目名称:juju,代码行数:11,代码来源:proxyupdater.go


示例7: TestProxyConfigMap

func (s *ConfigSuite) TestProxyConfigMap(c *gc.C) {
	s.addJujuFiles(c)
	cfg := newTestConfig(c, testing.Attrs{})
	proxySettings := proxy.Settings{
		Http:    "http proxy",
		Https:   "https proxy",
		Ftp:     "ftp proxy",
		NoProxy: "no proxy",
	}
	cfg, err := cfg.Apply(config.ProxyConfigMap(proxySettings))
	c.Assert(err, gc.IsNil)
	c.Assert(cfg.ProxySettings(), gc.DeepEquals, proxySettings)
	// Apt proxy and proxy differ by the content of the no-proxy values.
	proxySettings.NoProxy = ""
	c.Assert(cfg.AptProxySettings(), gc.DeepEquals, proxySettings)
}
开发者ID:klyachin,项目名称:juju,代码行数:16,代码来源:config_test.go


示例8: TestAsScriptEnvironmentAllValue

func (s *proxySuite) TestAsScriptEnvironmentAllValue(c *gc.C) {
	proxies := proxy.Settings{
		Http:    "some-value",
		Https:   "special",
		Ftp:     "who uses this?",
		NoProxy: "10.0.3.1,localhost",
	}
	expected := `
export http_proxy=some-value
export HTTP_PROXY=some-value
export https_proxy=special
export HTTPS_PROXY=special
export ftp_proxy=who uses this?
export FTP_PROXY=who uses this?
export no_proxy=10.0.3.1,localhost
export NO_PROXY=10.0.3.1,localhost`[1:]
	c.Assert(proxies.AsScriptEnvironment(), gc.Equals, expected)
}
开发者ID:juju,项目名称:utils,代码行数:18,代码来源:proxy_test.go


示例9: TestAsEnvironmentValuesAllValue

func (s *proxySuite) TestAsEnvironmentValuesAllValue(c *gc.C) {
	proxies := proxy.Settings{
		Http:    "some-value",
		Https:   "special",
		Ftp:     "who uses this?",
		NoProxy: "10.0.3.1,localhost",
	}
	expected := []string{
		"http_proxy=some-value",
		"HTTP_PROXY=some-value",
		"https_proxy=special",
		"HTTPS_PROXY=special",
		"ftp_proxy=who uses this?",
		"FTP_PROXY=who uses this?",
		"no_proxy=10.0.3.1,localhost",
		"NO_PROXY=10.0.3.1,localhost",
	}
	c.Assert(proxies.AsEnvironmentValues(), gc.DeepEquals, expected)
}
开发者ID:juju,项目名称:utils,代码行数:19,代码来源:proxy_test.go


示例10: TestAsEnvironmentValuesEmpty

func (s *proxySuite) TestAsEnvironmentValuesEmpty(c *gc.C) {
	proxies := proxy.Settings{}
	c.Assert(proxies.AsEnvironmentValues(), gc.HasLen, 0)
}
开发者ID:juju,项目名称:utils,代码行数:4,代码来源:proxy_test.go


示例11: TestAsScriptEnvironmentEmpty

func (s *proxySuite) TestAsScriptEnvironmentEmpty(c *gc.C) {
	proxies := proxy.Settings{}
	c.Assert(proxies.AsScriptEnvironment(), gc.Equals, "")
}
开发者ID:juju,项目名称:utils,代码行数:4,代码来源:proxy_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang series.GetOSFromSeries函数代码示例发布时间:2022-05-23
下一篇:
Golang proxy.DetectProxies函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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