Browse code

drop/omit

Victor Vieux authored on 2013/06/04 22:51:12
Showing 12 changed files
... ...
@@ -21,7 +21,7 @@ const INDEX_SERVER = "https://index.docker.io/v1"
21 21
 //const INDEX_SERVER = "http://indexstaging-docker.dotcloud.com/"
22 22
 
23 23
 var (
24
-	ErrConfigFileMissing error = errors.New("The Auth config file is missing")
24
+	ErrConfigFileMissing = errors.New("The Auth config file is missing")
25 25
 )
26 26
 
27 27
 type AuthConfig struct {
... ...
@@ -222,11 +222,11 @@ func (b *builderClient) commit(id string) error {
222 222
 	if id == "" {
223 223
 		cmd := b.config.Cmd
224 224
 		b.config.Cmd = []string{"true"}
225
-		if cid, err := b.run(); err != nil {
225
+		cid, err := b.run()
226
+		if err != nil {
226 227
 			return err
227
-		} else {
228
-			id = cid
229 228
 		}
229
+		id = cid
230 230
 		b.config.Cmd = cmd
231 231
 	}
232 232
 
... ...
@@ -272,11 +272,11 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error {
272 272
 			utils.Debugf("[BUILDER] Cache miss")
273 273
 		}
274 274
 
275
-		if cid, err := b.run(); err != nil {
275
+		cid, err := b.run()
276
+		if err != nil {
276 277
 			return err
277
-		} else {
278
-			id = cid
279 278
 		}
279
+		id = cid
280 280
 	}
281 281
 
282 282
 	container := b.runtime.Get(id)
... ...
@@ -159,11 +159,11 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
159 159
 		file = os.Stdin
160 160
 	} else {
161 161
 		// Send Dockerfile from arg/Dockerfile (deprecate later)
162
-		if f, err := os.Open(path.Join(cmd.Arg(0), "Dockerfile")); err != nil {
162
+		f, err := os.Open(path.Join(cmd.Arg(0), "Dockerfile"))
163
+		if err != nil {
163 164
 			return err
164
-		} else {
165
-			file = f
166 165
 		}
166
+		file = f
167 167
 		// Send context from arg
168 168
 		// Create a FormFile multipart for the context if needed
169 169
 		// FIXME: Use NewTempArchive in order to have the size and avoid too much memory usage?
... ...
@@ -176,21 +176,21 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
176 176
 		if err != nil {
177 177
 			return err
178 178
 		}
179
-		if wField, err := w.CreateFormFile("Context", filepath.Base(absPath)+"."+compression.Extension()); err != nil {
179
+		wField, err := w.CreateFormFile("Context", filepath.Base(absPath)+"."+compression.Extension())
180
+		if err != nil {
180 181
 			return err
181
-		} else {
182
-			// FIXME: Find a way to have a progressbar for the upload too
183
-			sf := utils.NewStreamFormatter(false)
184
-			io.Copy(wField, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, sf.FormatProgress("Caching Context", "%v/%v (%v)"), sf))
185 182
 		}
183
+		// FIXME: Find a way to have a progressbar for the upload too
184
+		sf := utils.NewStreamFormatter(false)
185
+		io.Copy(wField, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, sf.FormatProgress("Caching Context", "%v/%v (%v)"), sf))
186 186
 		multipartBody = io.MultiReader(multipartBody, boundary)
187 187
 	}
188 188
 	// Create a FormFile multipart for the Dockerfile
189
-	if wField, err := w.CreateFormFile("Dockerfile", "Dockerfile"); err != nil {
189
+	wField, err := w.CreateFormFile("Dockerfile", "Dockerfile")
190
+	if err != nil {
190 191
 		return err
191
-	} else {
192
-		io.Copy(wField, file)
193 192
 	}
193
+	io.Copy(wField, file)
194 194
 	multipartBody = io.MultiReader(multipartBody, boundary)
195 195
 
196 196
 	v := &url.Values{}
... ...
@@ -276,9 +276,8 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
276 276
 	oldState, err := term.SetRawTerminal()
277 277
 	if err != nil {
278 278
 		return err
279
-	} else {
280
-		defer term.RestoreTerminal(oldState)
281 279
 	}
280
+	defer term.RestoreTerminal(oldState)
282 281
 
283 282
 	cmd := Subcmd("login", "", "Register or Login to the docker registry server")
284 283
 	if err := cmd.Parse(args); err != nil {
... ...
@@ -1417,11 +1416,11 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in *os.Fi
1417 1417
 	})
1418 1418
 
1419 1419
 	if in != nil && setRawTerminal && term.IsTerminal(in.Fd()) && os.Getenv("NORAW") == "" {
1420
-		if oldState, err := term.SetRawTerminal(); err != nil {
1420
+		oldState, err := term.SetRawTerminal()
1421
+		if err != nil {
1421 1422
 			return err
1422
-		} else {
1423
-			defer term.RestoreTerminal(oldState)
1424 1423
 		}
1424
+		defer term.RestoreTerminal(oldState)
1425 1425
 	}
1426 1426
 	sendStdin := utils.Go(func() error {
1427 1427
 		_, err := io.Copy(rwc, in)
... ...
@@ -431,14 +431,14 @@ func (container *Container) Start() error {
431 431
 
432 432
 	// Create the requested volumes volumes
433 433
 	for volPath := range container.Config.Volumes {
434
-		if c, err := container.runtime.volumes.Create(nil, container, "", "", nil); err != nil {
434
+		c, err := container.runtime.volumes.Create(nil, container, "", "", nil)
435
+		if err != nil {
435 436
 			return err
436
-		} else {
437
-			if err := os.MkdirAll(path.Join(container.RootfsPath(), volPath), 0755); err != nil {
438
-				return nil
439
-			}
440
-			container.Volumes[volPath] = c.Id
441 437
 		}
438
+		if err := os.MkdirAll(path.Join(container.RootfsPath(), volPath), 0755); err != nil {
439
+			return nil
440
+		}
441
+		container.Volumes[volPath] = c.Id
442 442
 	}
443 443
 
444 444
 	if container.Config.VolumesFrom != "" {
... ...
@@ -573,12 +573,12 @@ func (container *Container) allocateNetwork() error {
573 573
 	}
574 574
 	container.NetworkSettings.PortMapping = make(map[string]string)
575 575
 	for _, spec := range container.Config.PortSpecs {
576
-		if nat, err := iface.AllocatePort(spec); err != nil {
576
+		nat, err := iface.AllocatePort(spec)
577
+		if err != nil {
577 578
 			iface.Release()
578 579
 			return err
579
-		} else {
580
-			container.NetworkSettings.PortMapping[strconv.Itoa(nat.Backend)] = strconv.Itoa(nat.Frontend)
581 580
 		}
581
+		container.NetworkSettings.PortMapping[strconv.Itoa(nat.Backend)] = strconv.Itoa(nat.Frontend)
582 582
 	}
583 583
 	container.network = iface
584 584
 	container.NetworkSettings.Bridge = container.runtime.networkManager.bridgeIface
... ...
@@ -597,12 +597,12 @@ func (container *Container) releaseNetwork() {
597 597
 // FIXME: replace this with a control socket within docker-init
598 598
 func (container *Container) waitLxc() error {
599 599
 	for {
600
-		if output, err := exec.Command("lxc-info", "-n", container.Id).CombinedOutput(); err != nil {
600
+		output, err := exec.Command("lxc-info", "-n", container.Id).CombinedOutput()
601
+		if err != nil {
601 602
 			return err
602
-		} else {
603
-			if !strings.Contains(string(output), "RUNNING") {
604
-				return nil
605
-			}
603
+		}
604
+		if !strings.Contains(string(output), "RUNNING") {
605
+			return nil
606 606
 		}
607 607
 		time.Sleep(500 * time.Millisecond)
608 608
 	}
... ...
@@ -625,7 +625,7 @@ func (container *Container) monitor() {
625 625
 	}
626 626
 	utils.Debugf("Process finished")
627 627
 
628
-	var exitCode int = -1
628
+	exitCode := -1
629 629
 	if container.cmd != nil {
630 630
 		exitCode = container.cmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus()
631 631
 	}
... ...
@@ -11,7 +11,7 @@ import (
11 11
 	"time"
12 12
 )
13 13
 
14
-var DOCKER_PATH string = path.Join(os.Getenv("DOCKERPATH"), "docker")
14
+var DOCKER_PATH = path.Join(os.Getenv("DOCKERPATH"), "docker")
15 15
 
16 16
 // WARNING: this crashTest will 1) crash your host, 2) remove all containers
17 17
 func runDaemon() (*exec.Cmd, error) {
... ...
@@ -49,9 +49,8 @@ func LoadImage(root string) (*Image, error) {
49 49
 	if stat, err := os.Stat(layerPath(root)); err != nil {
50 50
 		if os.IsNotExist(err) {
51 51
 			return nil, fmt.Errorf("Couldn't load image %s: no filesystem layer", img.Id)
52
-		} else {
53
-			return nil, err
54 52
 		}
53
+		return nil, err
55 54
 	} else if !stat.IsDir() {
56 55
 		return nil, fmt.Errorf("Couldn't load image %s: %s is not a directory", img.Id, layerPath(root))
57 56
 	}
... ...
@@ -132,9 +132,8 @@ func CreateBridgeIface(ifaceName string) error {
132 132
 	}
133 133
 	if ifaceAddr == "" {
134 134
 		return fmt.Errorf("Could not find a free IP address range for interface '%s'. Please configure its address manually and run 'docker -b %s'", ifaceName, ifaceName)
135
-	} else {
136
-		utils.Debugf("Creating bridge %s with network %s", ifaceName, ifaceAddr)
137 135
 	}
136
+	utils.Debugf("Creating bridge %s with network %s", ifaceName, ifaceAddr)
138 137
 
139 138
 	if output, err := ip("link", "add", ifaceName, "type", "bridge"); err != nil {
140 139
 		return fmt.Errorf("Error creating bridge: %s (output: %s)", err, output)
... ...
@@ -464,11 +463,11 @@ func (iface *NetworkInterface) AllocatePort(spec string) (*Nat, error) {
464 464
 		return nil, err
465 465
 	}
466 466
 	// Allocate a random port if Frontend==0
467
-	if extPort, err := iface.manager.portAllocator.Acquire(nat.Frontend); err != nil {
467
+	extPort, err := iface.manager.portAllocator.Acquire(nat.Frontend)
468
+	if err != nil {
468 469
 		return nil, err
469
-	} else {
470
-		nat.Frontend = extPort
471 470
 	}
471
+	nat.Frontend = extPort
472 472
 	if err := iface.manager.portMapper.Map(nat.Frontend, net.TCPAddr{IP: iface.IPNet.IP, Port: nat.Backend}); err != nil {
473 473
 		iface.manager.portAllocator.Release(nat.Frontend)
474 474
 		return nil, err
... ...
@@ -15,7 +15,7 @@ import (
15 15
 	"strings"
16 16
 )
17 17
 
18
-var ErrAlreadyExists error = errors.New("Image already exists")
18
+var ErrAlreadyExists = errors.New("Image already exists")
19 19
 
20 20
 func doWithCookies(c *http.Client, req *http.Request) (*http.Response, error) {
21 21
 	for _, cookie := range c.Jar.Cookies(req.URL) {
... ...
@@ -396,11 +396,11 @@ func (r *Registry) PushImageJsonIndex(remote string, imgList []*ImgData, validat
396 396
 	}
397 397
 	if validate {
398 398
 		if res.StatusCode != 204 {
399
-			if errBody, err := ioutil.ReadAll(res.Body); err != nil {
399
+			errBody, err := ioutil.ReadAll(res.Body)
400
+			if err != nil {
400 401
 				return nil, err
401
-			} else {
402
-				return nil, fmt.Errorf("Error: Status %d trying to push checksums %s: %s", res.StatusCode, remote, errBody)
403 402
 			}
403
+			return nil, fmt.Errorf("Error: Status %d trying to push checksums %s: %s", res.StatusCode, remote, errBody)
404 404
 		}
405 405
 	}
406 406
 
... ...
@@ -133,25 +133,25 @@ func (runtime *Runtime) Register(container *Container) error {
133 133
 	//        if so, then we need to restart monitor and init a new lock
134 134
 	// If the container is supposed to be running, make sure of it
135 135
 	if container.State.Running {
136
-		if output, err := exec.Command("lxc-info", "-n", container.Id).CombinedOutput(); err != nil {
136
+		output, err := exec.Command("lxc-info", "-n", container.Id).CombinedOutput()
137
+		if err != nil {
137 138
 			return err
138
-		} else {
139
-			if !strings.Contains(string(output), "RUNNING") {
140
-				utils.Debugf("Container %s was supposed to be running be is not.", container.Id)
141
-				if runtime.autoRestart {
142
-					utils.Debugf("Restarting")
143
-					container.State.Ghost = false
144
-					container.State.setStopped(0)
145
-					if err := container.Start(); err != nil {
146
-						return err
147
-					}
148
-					nomonitor = true
149
-				} else {
150
-					utils.Debugf("Marking as stopped")
151
-					container.State.setStopped(-127)
152
-					if err := container.ToDisk(); err != nil {
153
-						return err
154
-					}
139
+		}
140
+		if !strings.Contains(string(output), "RUNNING") {
141
+			utils.Debugf("Container %s was supposed to be running be is not.", container.Id)
142
+			if runtime.autoRestart {
143
+				utils.Debugf("Restarting")
144
+				container.State.Ghost = false
145
+				container.State.setStopped(0)
146
+				if err := container.Start(); err != nil {
147
+					return err
148
+				}
149
+				nomonitor = true
150
+			} else {
151
+				utils.Debugf("Marking as stopped")
152
+				container.State.setStopped(-127)
153
+				if err := container.ToDisk(); err != nil {
154
+					return err
155 155
 				}
156 156
 			}
157 157
 		}
... ...
@@ -216,7 +216,7 @@ func (srv *Server) ImageHistory(name string) ([]ApiHistory, error) {
216 216
 		return nil, err
217 217
 	}
218 218
 
219
-	var outs []ApiHistory = []ApiHistory{} //produce [] when empty instead of 'null'
219
+	outs := []ApiHistory{} //produce [] when empty instead of 'null'
220 220
 	err = image.WalkHistory(func(img *Image) error {
221 221
 		var out ApiHistory
222 222
 		out.Id = srv.runtime.repositories.ImageName(img.ShortId())
... ...
@@ -356,11 +356,11 @@ func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, remote, a
356 356
 		}
357 357
 	} else {
358 358
 		// Otherwise, check that the tag exists and use only that one
359
-		if id, exists := tagsList[askedTag]; !exists {
359
+		id, exists := tagsList[askedTag]
360
+		if !exists {
360 361
 			return fmt.Errorf("Tag %s not found in repositoy %s", askedTag, remote)
361
-		} else {
362
-			repoData.ImgList[id].Tag = askedTag
363 362
 		}
363
+		repoData.ImgList[id].Tag = askedTag
364 364
 	}
365 365
 
366 366
 	for _, img := range repoData.ImgList {
... ...
@@ -714,10 +714,9 @@ func (srv *Server) ImageDelete(name string) error {
714 714
 	img, err := srv.runtime.repositories.LookupImage(name)
715 715
 	if err != nil {
716 716
 		return fmt.Errorf("No such image: %s", name)
717
-	} else {
718
-		if err := srv.runtime.graph.Delete(img.Id); err != nil {
719
-			return fmt.Errorf("Error deleting image %s: %s", name, err.Error())
720
-		}
717
+	}
718
+	if err := srv.runtime.graph.Delete(img.Id); err != nil {
719
+		return fmt.Errorf("Error deleting image %s: %s", name, err.Error())
721 720
 	}
722 721
 	return nil
723 722
 }
... ...
@@ -34,7 +34,7 @@ func Go(f func() error) chan error {
34 34
 // Request a given URL and return an io.Reader
35 35
 func Download(url string, stderr io.Writer) (*http.Response, error) {
36 36
 	var resp *http.Response
37
-	var err error = nil
37
+	var err error
38 38
 	if resp, err = http.Get(url); err != nil {
39 39
 		return nil, err
40 40
 	}