本文整理汇总了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
}
}