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


Golang Request.MultipartReader方法代码示例

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


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

示例1: BuildImageFromDockerfile

//Builds the image in a docker node.
func BuildImageFromDockerfile(w rest.ResponseWriter, r *rest.Request) {

	passedParams := PassedParams{}

	//If the Content-Type is multipart, parse it.  Otherwise unpack the json.
	if strings.Contains(r.Header.Get("Content-Type"), "multipart") == true {

		form, err := r.MultipartReader()
		TarPart, err := form.NextPart()
		TarData, err := ioutil.ReadAll(TarPart)
		JsonPart, err := form.NextPart()
		JsonData, _ := ioutil.ReadAll(JsonPart)

		err = json.Unmarshal(JsonData, &passedParams)
		if err != nil {
			rest.Error(w, err.Error(), 400)
			return
		}
		passedParams.TarFile = TarData

	} else {
		//Unpack the params that come in.
		err := r.DecodeJsonPayload(&passedParams)
		if err != nil {
			rest.Error(w, err.Error(), 400)
			return
		}
	}

	if Validate(passedParams) {
		//Create a uuid for the specific job.
		var jobid JobID
		jobid.JobIdentifier = JobUUIDString()

		//Open a redis connection.  c is type redis.Conn
		c := RedisConnection()

		//Set the status to building in the cache.
		n, err := c.Do("HSET", jobid.JobIdentifier, "status", "Building")
		if n == 0 {
			rest.Error(w, "Unable to access the redis cache.  Make sure the CACHE_PASSWORD is set.", 501)
			return
		}
		if err != nil {
			rest.Error(w, " err trigg Unable to access the redis cache.  Make sure the CACHE_PASSWORD is set.", 400)
			return
		}
		c.Do("HSET", jobid.JobIdentifier, "logs", "Fetching logs...")

		//Launch a goroutine to build, push, and delete.  Updates the cache as the process goes on.
		//Also pass it the file that came from the CLI?
		go BuildPushAndDeleteImage(jobid.JobIdentifier, passedParams, c)

		//Write the jobid back
		w.WriteJson(jobid)
	} else {
		//Params didn't validate.  Bad Request.
		rest.Error(w, "Insufficient Information.  Must provide at least an Image Name and a Dockerfile/Tarurl.", 400)
		return
	}

}
开发者ID:AnyBucket,项目名称:docker-builder,代码行数:63,代码来源:builder.go


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