1
0
mirror of https://github.com/docker/docs.git synced 2026-10-31 10:34:26 +03:00

gofmt check

Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
This commit is contained in:
Xian Chaobo
2015-04-10 19:08:00 +08:00
parent ccc32635d5
commit 34e0c78d1d
4 changed files with 67 additions and 67 deletions

View File

@@ -4,15 +4,15 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path"
"runtime"
"sort"
"strconv"
"strings"
"os"
"io"
"path"
dockerfilters "github.com/docker/docker/pkg/parsers/filters"
"github.com/docker/swarm/cluster"
@@ -275,36 +275,36 @@ func postImagesCreate(c *context, w http.ResponseWriter, r *http.Request) {
// POST /images/load
func postImagesLoad(c *context, w http.ResponseWriter, r *http.Request) {
//cache tar file
tmpImageDir, err := ioutil.TempDir("", "docker-import-")
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
defer os.RemoveAll(tmpImageDir)
//cache tar file
tmpImageDir, err := ioutil.TempDir("", "docker-import-")
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
defer os.RemoveAll(tmpImageDir)
repoTarFile := path.Join(tmpImageDir, "repo.tar")
tarFile, err := os.Create(repoTarFile)
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
if _, err := io.Copy(tarFile, r.Body); err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
tarFile.Close()
// call cluster to load image on every node
wf := NewWriteFlusher(w)
callback := func(what, status string) {
if status == "" {
fmt.Fprintf(wf, "%s:Loading Image...\n", what)
} else {
fmt.Fprintf(wf, "%s:Loading Image... %s\n", what,status)
}
}
c.cluster.Load(repoTarFile, callback)
repoTarFile := path.Join(tmpImageDir, "repo.tar")
tarFile, err := os.Create(repoTarFile)
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
if _, err := io.Copy(tarFile, r.Body); err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
tarFile.Close()
// call cluster to load image on every node
wf := NewWriteFlusher(w)
callback := func(what, status string) {
if status == "" {
fmt.Fprintf(wf, "%s:Loading Image...\n", what)
} else {
fmt.Fprintf(wf, "%s:Loading Image... %s\n", what, status)
}
}
c.cluster.Load(repoTarFile, callback)
}
// GET /events

View File

@@ -33,11 +33,11 @@ type Cluster interface {
// `status` is the current status, like "", "in progress" or "downloaded
Pull(name string, callback func(what, status string))
// Load images
// `callback` can be called multiple time
// `what` is what is being loaded
// `status` is the current status, like "", "in progress" or "loaded"
Load(tarFile string, callback func(what, status string))
// Load images
// `callback` can be called multiple time
// `what` is what is being loaded
// `status` is the current status, like "", "in progress" or "loaded"
Load(tarFile string, callback func(what, status string))
// Return some info about the cluster, like nb or containers / images
// It is pretty open, so the implementation decides what to return.

View File

@@ -5,10 +5,10 @@ import (
"errors"
"fmt"
"net"
"os"
"strings"
"sync"
"time"
"os"
log "github.com/Sirupsen/logrus"
"github.com/samalba/dockerclient"
@@ -414,15 +414,15 @@ func (e *Engine) Pull(image string) error {
// Load an image on the engine
func (e *Engine) Load(tarFile string) error {
file, err := os.Open(tarFile)
if err != nil {
return err
}
file, err := os.Open(tarFile)
if err != nil {
return err
}
if err := e.client.LoadImage(file); err != nil {
return err
}
return nil
if err := e.client.LoadImage(file); err != nil {
return err
}
return nil
}
// RegisterEventHandler registers an event handler.

View File

@@ -240,27 +240,27 @@ func (c *Cluster) Pull(name string, callback func(what, status string)) {
// Load image
func (c *Cluster) Load(tarFile string, callback func(what, status string)) {
size := len(c.engines)
done := make(chan bool, size)
for _, n := range c.engines {
go func(nn *cluster.Engine) {
if callback != nil {
callback(nn.Name, "")
}
err := nn.Load(tarFile)
if callback != nil {
if err != nil {
callback(nn.Name, err.Error())
} else {
callback(nn.Name, "loaded")
}
}
done <- true
}(n)
}
for i := 0; i < size; i++ {
<-done
}
size := len(c.engines)
done := make(chan bool, size)
for _, n := range c.engines {
go func(nn *cluster.Engine) {
if callback != nil {
callback(nn.Name, "")
}
err := nn.Load(tarFile)
if callback != nil {
if err != nil {
callback(nn.Name, err.Error())
} else {
callback(nn.Name, "loaded")
}
}
done <- true
}(n)
}
for i := 0; i < size; i++ {
<-done
}
}
// Containers returns all the containers in the cluster.