Browse code

Fix Go formatting in beam and dockerscript

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)

Solomon Hykes authored on 2014/04/23 08:09:42
Showing 11 changed files
... ...
@@ -1,8 +1,8 @@
1 1
 package beam
2 2
 
3 3
 import (
4
-	"testing"
5 4
 	"github.com/dotcloud/docker/pkg/beam/data"
5
+	"testing"
6 6
 )
7 7
 
8 8
 func TestSendConn(t *testing.T) {
... ...
@@ -2,8 +2,8 @@ package data
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"strings"
6 5
 	"strconv"
6
+	"strings"
7 7
 )
8 8
 
9 9
 func Encode(obj map[string][]string) string {
... ...
@@ -93,10 +93,10 @@ func decodeString(msg string) (string, int, error) {
93 93
 	} else {
94 94
 		length = int(l)
95 95
 	}
96
-	if len(parts[1]) < length + 1 {
97
-		return "", 0, fmt.Errorf("message '%s' is %d bytes, expected at least %d", parts[1], len(parts[1]), length + 1)
96
+	if len(parts[1]) < length+1 {
97
+		return "", 0, fmt.Errorf("message '%s' is %d bytes, expected at least %d", parts[1], len(parts[1]), length+1)
98 98
 	}
99
-	payload := parts[1][:length + 1]
99
+	payload := parts[1][:length+1]
100 100
 	if payload[length] != ',' {
101 101
 		return "", 0, fmt.Errorf("message is not comma-terminated")
102 102
 	}
... ...
@@ -92,10 +92,10 @@ func TestEncodeBinaryValue(t *testing.T) {
92 92
 }
93 93
 
94 94
 func TestDecodeString(t *testing.T) {
95
-	validEncodedStrings := []struct{
96
-		input string
95
+	validEncodedStrings := []struct {
96
+		input  string
97 97
 		output string
98
-		skip int
98
+		skip   int
99 99
 	}{
100 100
 		{"3:foo,", "foo", 6},
101 101
 		{"5:hello,", "hello", 8},
102 102
new file mode 100755
103 103
Binary files /dev/null and b/pkg/beam/examples/beamsh/beamsh differ
... ...
@@ -2,6 +2,7 @@ package main
2 2
 
3 3
 import (
4 4
 	"bufio"
5
+	"flag"
5 6
 	"fmt"
6 7
 	"github.com/dotcloud/docker/pkg/beam"
7 8
 	"github.com/dotcloud/docker/pkg/beam/data"
... ...
@@ -14,7 +15,6 @@ import (
14 14
 	"path"
15 15
 	"strings"
16 16
 	"sync"
17
-	"flag"
18 17
 )
19 18
 
20 19
 var rootPlugins = []string{
... ...
@@ -22,8 +22,8 @@ var rootPlugins = []string{
22 22
 }
23 23
 
24 24
 var (
25
-	flX bool
26
-	flPing bool
25
+	flX        bool
26
+	flPing     bool
27 27
 	introspect beam.ReceiveSender = beam.Devnull()
28 28
 )
29 29
 
... ...
@@ -38,7 +38,7 @@ func main() {
38 38
 	fd3.Close()
39 39
 	flag.BoolVar(&flX, "x", false, "print commands as they are being executed")
40 40
 	flag.Parse()
41
-	if flag.NArg() == 0{
41
+	if flag.NArg() == 0 {
42 42
 		if term.IsTerminal(0) {
43 43
 			// No arguments, stdin is terminal --> interactive mode
44 44
 			input := bufio.NewScanner(os.Stdin)
... ...
@@ -168,7 +168,6 @@ func executeScript(out beam.Sender, script []*dockerscript.Command) error {
168 168
 	return nil
169 169
 }
170 170
 
171
-
172 171
 //	1) Find a handler for the command (if no handler, fail)
173 172
 //	2) Attach new in & out pair to the handler
174 173
 //	3) [in the background] Copy handler output to our own output
... ...
@@ -217,10 +216,8 @@ func executeCommand(out beam.Sender, cmd *dockerscript.Command) error {
217 217
 	return nil
218 218
 }
219 219
 
220
-
221 220
 type Handler func([]string, io.Writer, io.Writer, beam.Receiver, beam.Sender)
222 221
 
223
-
224 222
 func Handlers(sink beam.Sender) (*beam.UnixConn, error) {
225 223
 	var tasks sync.WaitGroup
226 224
 	pub, priv, err := beam.USocketPair()
... ...
@@ -329,11 +326,12 @@ func GetHandler(name string) Handler {
329 329
 	return nil
330 330
 }
331 331
 
332
-
333 332
 // VARIOUS HELPER FUNCTIONS:
334 333
 
335 334
 func connToFile(conn net.Conn) (f *os.File, err error) {
336
-	if connWithFile, ok := conn.(interface { File() (*os.File, error) }); !ok {
335
+	if connWithFile, ok := conn.(interface {
336
+		File() (*os.File, error)
337
+	}); !ok {
337 338
 		return nil, fmt.Errorf("no file descriptor available")
338 339
 	} else {
339 340
 		f, err = connWithFile.File()
... ...
@@ -345,12 +343,12 @@ func connToFile(conn net.Conn) (f *os.File, err error) {
345 345
 }
346 346
 
347 347
 type Msg struct {
348
-	payload		[]byte
349
-	attachment	*os.File
348
+	payload    []byte
349
+	attachment *os.File
350 350
 }
351 351
 
352 352
 func Logf(msg string, args ...interface{}) (int, error) {
353
-	if len(msg) == 0 || msg[len(msg) - 1] != '\n' {
353
+	if len(msg) == 0 || msg[len(msg)-1] != '\n' {
354 354
 		msg = msg + "\n"
355 355
 	}
356 356
 	msg = fmt.Sprintf("[%v] [%v] %s", os.Getpid(), path.Base(os.Args[0]), msg)
... ...
@@ -363,7 +361,7 @@ func Debugf(msg string, args ...interface{}) {
363 363
 	}
364 364
 }
365 365
 
366
-func Fatalf(msg string, args ...interface{})  {
366
+func Fatalf(msg string, args ...interface{}) {
367 367
 	Logf(msg, args...)
368 368
 	os.Exit(1)
369 369
 }
... ...
@@ -386,7 +384,6 @@ func scriptString(script []*dockerscript.Command) string {
386 386
 	return fmt.Sprintf("'%s'", strings.Join(lines, "; "))
387 387
 }
388 388
 
389
-
390 389
 func dialer(addr string) (chan net.Conn, error) {
391 390
 	u, err := url.Parse(addr)
392 391
 	if err != nil {
... ...
@@ -400,7 +397,7 @@ func dialer(addr string) (chan net.Conn, error) {
400 400
 			if err != nil {
401 401
 				return
402 402
 			}
403
-			connections <-conn
403
+			connections <- conn
404 404
 		}
405 405
 	}()
406 406
 	return connections, nil
... ...
@@ -424,14 +421,12 @@ func listener(addr string) (chan net.Conn, error) {
424 424
 				return
425 425
 			}
426 426
 			Logf("new connection\n")
427
-			connections<-conn
427
+			connections <- conn
428 428
 		}
429 429
 	}()
430 430
 	return connections, nil
431 431
 }
432 432
 
433
-
434
-
435 433
 func SendToConn(connections chan net.Conn, src beam.Receiver) error {
436 434
 	var tasks sync.WaitGroup
437 435
 	defer tasks.Wait()
... ...
@@ -479,14 +474,13 @@ func SendToConn(connections chan net.Conn, src beam.Receiver) error {
479 479
 	return nil
480 480
 }
481 481
 
482
-
483 482
 func msgDesc(payload []byte, attachment *os.File) string {
484 483
 	return beam.MsgDesc(payload, attachment)
485 484
 }
486 485
 
487 486
 func ReceiveFromConn(connections chan net.Conn, dst beam.Sender) error {
488 487
 	for conn := range connections {
489
-		err := func () error {
488
+		err := func() error {
490 489
 			Logf("parsing message from network...\n")
491 490
 			defer Logf("done parsing message from network\n")
492 491
 			buf := make([]byte, 4098)
... ...
@@ -534,7 +528,6 @@ func ReceiveFromConn(connections chan net.Conn, dst beam.Sender) error {
534 534
 	return nil
535 535
 }
536 536
 
537
-
538 537
 func bicopy(a, b io.ReadWriteCloser) {
539 538
 	var iotasks sync.WaitGroup
540 539
 	oneCopy := func(dst io.WriteCloser, src io.Reader) {
... ...
@@ -547,4 +540,3 @@ func bicopy(a, b io.ReadWriteCloser) {
547 547
 	go oneCopy(b, a)
548 548
 	iotasks.Wait()
549 549
 }
550
-
... ...
@@ -1,24 +1,23 @@
1 1
 package main
2 2
 
3 3
 import (
4
-	"io"
5
-	"os/exec"
4
+	"bufio"
5
+	"fmt"
6 6
 	"github.com/dotcloud/docker/pkg/beam"
7 7
 	"github.com/dotcloud/docker/pkg/beam/data"
8 8
 	"github.com/dotcloud/docker/pkg/term"
9 9
 	"github.com/dotcloud/docker/utils"
10
-	"text/template"
11
-	"fmt"
12
-	"sync"
13
-	"os"
14
-	"strings"
15
-	"path"
16
-	"bufio"
10
+	"io"
17 11
 	"net"
18 12
 	"net/url"
13
+	"os"
14
+	"os/exec"
15
+	"path"
16
+	"strings"
17
+	"sync"
18
+	"text/template"
19 19
 )
20 20
 
21
-
22 21
 func CmdLogger(args []string, stdout, stderr io.Writer, in beam.Receiver, out beam.Sender) {
23 22
 	if err := os.MkdirAll("logs", 0700); err != nil {
24 23
 		fmt.Fprintf(stderr, "%v\n", err)
... ...
@@ -28,7 +27,7 @@ func CmdLogger(args []string, stdout, stderr io.Writer, in beam.Receiver, out be
28 28
 	defer tasks.Wait()
29 29
 	var n int = 1
30 30
 	r := beam.NewRouter(out)
31
-	r.NewRoute().HasAttachment().KeyStartsWith("cmd", "log").Handler(func (payload []byte, attachment *os.File) error {
31
+	r.NewRoute().HasAttachment().KeyStartsWith("cmd", "log").Handler(func(payload []byte, attachment *os.File) error {
32 32
 		tasks.Add(1)
33 33
 		go func(n int) {
34 34
 			defer tasks.Done()
... ...
@@ -398,7 +397,7 @@ func CmdConnect(args []string, stdout, stderr io.Writer, in beam.Receiver, out b
398 398
 		Logf("connecting to %s/%s\n", u.Scheme, u.Host)
399 399
 		conn, err := net.Dial(u.Scheme, u.Host)
400 400
 		if err != nil {
401
-			out.Send(data.Empty().Set("cmd", "msg", "connect error: " + err.Error()).Bytes(), nil)
401
+			out.Send(data.Empty().Set("cmd", "msg", "connect error: "+err.Error()).Bytes(), nil)
402 402
 			return
403 403
 		}
404 404
 		out.Send(data.Empty().Set("cmd", "msg", "connection established").Bytes(), nil)
... ...
@@ -1,19 +1,19 @@
1 1
 package beam
2 2
 
3 3
 import (
4
-	"io"
5 4
 	"fmt"
6
-	"os"
7 5
 	"github.com/dotcloud/docker/pkg/beam/data"
6
+	"io"
7
+	"os"
8 8
 )
9 9
 
10 10
 type Router struct {
11 11
 	routes []*Route
12
-	sink Sender
12
+	sink   Sender
13 13
 }
14 14
 
15 15
 func NewRouter(sink Sender) *Router {
16
-	return &Router{sink:sink}
16
+	return &Router{sink: sink}
17 17
 }
18 18
 
19 19
 func (r *Router) Send(payload []byte, attachment *os.File) (err error) {
... ...
@@ -40,10 +40,8 @@ func (r *Router) NewRoute() *Route {
40 40
 	return route
41 41
 }
42 42
 
43
-
44
-
45 43
 type Route struct {
46
-	rules []func([]byte, *os.File) bool
44
+	rules   []func([]byte, *os.File) bool
47 45
 	handler func([]byte, *os.File) error
48 46
 }
49 47
 
... ...
@@ -70,7 +68,6 @@ func (r *Route) HasAttachment() *Route {
70 70
 	return r
71 71
 }
72 72
 
73
-
74 73
 func (route *Route) Tee(dst Sender) *Route {
75 74
 	inner := route.handler
76 75
 	route.handler = func(payload []byte, attachment *os.File) error {
... ...
@@ -125,8 +122,7 @@ func (r *Route) KeyStartsWith(k string, beginning ...string) *Route {
125 125
 	return r
126 126
 }
127 127
 
128
-
129
-func (r *Route) KeyEquals(k string, full...string) *Route {
128
+func (r *Route) KeyEquals(k string, full ...string) *Route {
130 129
 	r.rules = append(r.rules, func(payload []byte, attachment *os.File) bool {
131 130
 		values := data.Message(payload).Get(k)
132 131
 		if len(values) != len(full) {
... ...
@@ -3,13 +3,13 @@ package beam
3 3
 import (
4 4
 	"fmt"
5 5
 	"io/ioutil"
6
-	"testing"
7 6
 	"os"
8 7
 	"sync"
8
+	"testing"
9 9
 )
10 10
 
11 11
 type msg struct {
12
-	payload []byte
12
+	payload    []byte
13 13
 	attachment *os.File
14 14
 }
15 15
 
... ...
@@ -17,7 +17,6 @@ func (m msg) String() string {
17 17
 	return MsgDesc(m.payload, m.attachment)
18 18
 }
19 19
 
20
-
21 20
 type mockReceiver []msg
22 21
 
23 22
 func (r *mockReceiver) Send(p []byte, a *os.File) error {
... ...
@@ -1,11 +1,11 @@
1 1
 package beam
2 2
 
3 3
 import (
4
+	"bufio"
4 5
 	"fmt"
5 6
 	"net"
6 7
 	"os"
7 8
 	"syscall"
8
-	"bufio"
9 9
 )
10 10
 
11 11
 func debugCheckpoint(msg string, args ...interface{}) {
... ...
@@ -13,7 +13,7 @@ func debugCheckpoint(msg string, args ...interface{}) {
13 13
 		return
14 14
 	}
15 15
 	os.Stdout.Sync()
16
-	tty,_ := os.OpenFile("/dev/tty", os.O_RDWR, 0700)
16
+	tty, _ := os.OpenFile("/dev/tty", os.O_RDWR, 0700)
17 17
 	fmt.Fprintf(tty, msg, args...)
18 18
 	bufio.NewScanner(tty).Scan()
19 19
 	tty.Close()
... ...
@@ -170,7 +170,7 @@ func SocketPair() (a *os.File, b *os.File, err error) {
170 170
 
171 171
 func USocketPair() (*UnixConn, *UnixConn, error) {
172 172
 	debugCheckpoint("===DEBUG=== USocketPair(). Hit enter to confirm: ")
173
-	defer debugCheckpoint ("===DEBUG=== USocketPair() returned. Hit enter to confirm ")
173
+	defer debugCheckpoint("===DEBUG=== USocketPair() returned. Hit enter to confirm ")
174 174
 	a, b, err := SocketPair()
175 175
 	if err != nil {
176 176
 		return nil, nil, err
... ...
@@ -193,7 +193,7 @@ func USocketPair() (*UnixConn, *UnixConn, error) {
193 193
 // returns an error if the file descriptor does not point to a unix socket.
194 194
 // This creates a duplicate file descriptor. It's the caller's responsibility
195 195
 // to close both.
196
-func FdConn(fd int) (n*net.UnixConn, err error) {
196
+func FdConn(fd int) (n *net.UnixConn, err error) {
197 197
 	{
198 198
 		debugCheckpoint("===DEBUG=== FdConn([%d]) = (unknown fd). Hit enter to confirm: ", fd)
199 199
 	}
... ...
@@ -1,15 +1,15 @@
1 1
 package dockerscript
2 2
 
3 3
 import (
4
-	"github.com/dotcloud/docker/pkg/dockerscript/scanner"
5 4
 	"fmt"
5
+	"github.com/dotcloud/docker/pkg/dockerscript/scanner"
6 6
 	"io"
7 7
 	"strings"
8 8
 )
9 9
 
10 10
 type Command struct {
11
-	Args []string
12
-	Children []*Command
11
+	Args       []string
12
+	Children   []*Command
13 13
 	Background bool
14 14
 }
15 15
 
... ...
@@ -32,7 +32,7 @@ func Parse(src io.Reader) ([]*Command, error) {
32 32
 
33 33
 func (cmd *Command) subString(depth int) string {
34 34
 	var prefix string
35
-	for i:=0; i<depth; i++ {
35
+	for i := 0; i < depth; i++ {
36 36
 		prefix += "  "
37 37
 	}
38 38
 	s := prefix + strings.Join(cmd.Args, ", ")
... ...
@@ -85,12 +85,12 @@ func parseArgs(s *Scanner) ([]string, rune, error) {
85 85
 
86 86
 func parse(s *Scanner, opener string) (expr []*Command, err error) {
87 87
 	/*
88
-	defer func() {
89
-		fmt.Printf("parse() returned %d commands:\n", len(expr))
90
-		for _, c := range expr {
91
-			fmt.Printf("\t----> %s\n", c)
92
-		}
93
-	}()
88
+		defer func() {
89
+			fmt.Printf("parse() returned %d commands:\n", len(expr))
90
+			for _, c := range expr {
91
+				fmt.Printf("\t----> %s\n", c)
92
+			}
93
+		}()
94 94
 	*/
95 95
 	for {
96 96
 		args, tok, err := parseArgs(s)
... ...
@@ -1,8 +1,8 @@
1 1
 package scanner
2 2
 
3 3
 import (
4
-	"unicode"
5 4
 	"strings"
5
+	"unicode"
6 6
 )
7 7
 
8 8
 // extra functions used to hijack the upstream text/scanner
... ...
@@ -19,4 +19,3 @@ func detectIdent(ch rune) bool {
19 19
 	}
20 20
 	return false
21 21
 }
22
-