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


Golang Config.CIRequest方法代码示例

本文整理汇总了Golang中github.com/jkellerer/jenkins-client-launcher/launcher/util.Config.CIRequest方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.CIRequest方法的具体用法?Golang Config.CIRequest怎么用?Golang Config.CIRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jkellerer/jenkins-client-launcher/launcher/util.Config的用法示例。


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

示例1: downloadJar

func (self *JenkinsClientDownloader) downloadJar(config *util.Config) error {
	util.GOut("DOWNLOAD", "Getting latest Jenkins client %v", (config.CIHostURI + "/" + ClientJarURL))

	// Create the HTTP request.
	request, err := config.CIRequest("GET", ClientJarURL, nil)
	if err != nil {
		return err
	}

	if fi, err := os.Stat(ClientJarName); err == nil {
		request.Header.Add("If-Modified-Since", fi.ModTime().Format(http.TimeFormat))
	}

	// Perform the HTTP request.
	var source io.ReadCloser
	sourceTime := time.Now()
	if response, err := config.CIClient().Do(request); err == nil {
		defer response.Body.Close()

		source = response.Body

		if response.StatusCode == 304 {
			util.GOut("DOWNLOAD", "Jenkins client is up-to-date, no need to download.")
			return nil
		} else if response.StatusCode != 200 {
			return fmt.Errorf("Failed downloading jenkins client. Cause: HTTP-%v %v", response.StatusCode, response.Status)
		}

		if value := response.Header.Get("Last-Modified"); value != "" {
			if time, err := http.ParseTime(value); err == nil {
				sourceTime = time
			}
		}
	} else {
		return fmt.Errorf("Failed downloading jenkins client. Connect failed. Cause: %v", err)
	}

	target, err := os.Create(ClientJarDownloadName)
	defer target.Close()

	if err != nil {
		return fmt.Errorf("Failed downloading jenkins client. Cannot create local file. Cause: %v", err)
	}

	if _, err = io.Copy(target, source); err == nil {
		target.Close()
		if err = os.Remove(ClientJarName); err == nil || os.IsNotExist(err) {
			if err = os.Rename(ClientJarDownloadName, ClientJarName); err == nil {
				os.Chtimes(ClientJarName, sourceTime, sourceTime)
			}
		}
		return err
	} else {
		return fmt.Errorf("Failed downloading jenkins client. Transfer failed. Cause: %v", err)
	}
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:56,代码来源:clientjar.go

示例2: invokeSystemGC

func (self *FullGCInvoker) invokeSystemGC(config *util.Config) {
	// curl -d "script=System.gc()" -X POST http://user:[email protected]/ci/computer/%s/scriptText
	postBody := strings.NewReader(fmt.Sprintf(FullGCPostBody, url.QueryEscape(FullGCScript)))
	request, err := config.CIRequest("POST", fmt.Sprintf(FullGCURL, config.ClientName), postBody)
	if err == nil {
		if response, err := config.CIClient().Do(request); err == nil {
			response.Body.Close()
			if response.StatusCode != 200 {
				util.GOut("gc", "ERROR: Failed invoking full GC as node request in Jenkins failed with %s", response.Status)
			}
		} else {
			util.GOut("gc", "ERROR: Failed invoking full GC as Jenkins cannot be contacted. Cause: %v", err)
		}
	}
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:15,代码来源:gc.go


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