本文整理汇总了Golang中github.com/wallyworld/core/environs/config.Config.AptHttpProxy方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.AptHttpProxy方法的具体用法?Golang Config.AptHttpProxy怎么用?Golang Config.AptHttpProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/wallyworld/core/environs/config.Config
的用法示例。
在下文中一共展示了Config.AptHttpProxy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Prepare
// Prepare implements environs.EnvironProvider.Prepare.
func (p environProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) {
// The user must not set bootstrap-ip; this is determined by the provider,
// and its presence used to determine whether the environment has yet been
// bootstrapped.
if _, ok := cfg.UnknownAttrs()["bootstrap-ip"]; ok {
return nil, fmt.Errorf("bootstrap-ip must not be specified")
}
err := checkLocalPort(cfg.StatePort(), "state port")
if err != nil {
return nil, err
}
err = checkLocalPort(cfg.APIPort(), "API port")
if err != nil {
return nil, err
}
// If the user has specified no values for any of the three normal
// proxies, then look in the environment and set them.
attrs := map[string]interface{}{
// We must not proxy SSH through the API server in a
// local provider environment. Besides not being useful,
// it may not work; there is no requirement for sshd to
// be available on machine-0.
"proxy-ssh": false,
}
setIfNotBlank := func(key, value string) {
if value != "" {
attrs[key] = value
}
}
logger.Tracef("Look for proxies?")
if cfg.HttpProxy() == "" &&
cfg.HttpsProxy() == "" &&
cfg.FtpProxy() == "" &&
cfg.NoProxy() == "" {
proxy := osenv.DetectProxies()
logger.Tracef("Proxies detected %#v", proxy)
setIfNotBlank("http-proxy", proxy.Http)
setIfNotBlank("https-proxy", proxy.Https)
setIfNotBlank("ftp-proxy", proxy.Ftp)
setIfNotBlank("no-proxy", proxy.NoProxy)
}
if cfg.AptHttpProxy() == "" &&
cfg.AptHttpsProxy() == "" &&
cfg.AptFtpProxy() == "" {
proxy, err := detectAptProxies()
if err != nil {
return nil, err
}
setIfNotBlank("apt-http-proxy", proxy.Http)
setIfNotBlank("apt-https-proxy", proxy.Https)
setIfNotBlank("apt-ftp-proxy", proxy.Ftp)
}
if len(attrs) > 0 {
cfg, err = cfg.Apply(attrs)
if err != nil {
return nil, err
}
}
return p.Open(cfg)
}