mirror of https://github.com/docker/docs.git
gofmt
This commit is contained in:
parent
93ba6dd82b
commit
c59fff422f
|
@ -1,8 +1,8 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/dotcloud/docker/rcli"
|
|
||||||
"github.com/dotcloud/docker/future"
|
"github.com/dotcloud/docker/future"
|
||||||
|
"github.com/dotcloud/docker/rcli"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
|
|
@ -15,7 +15,6 @@ type Termios struct {
|
||||||
Ospeed uintptr
|
Ospeed uintptr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Input flags
|
// Input flags
|
||||||
inpck = 0x010
|
inpck = 0x010
|
||||||
|
@ -136,12 +135,9 @@ func MakeRaw(fd int) (*State, error) {
|
||||||
return &oldState, nil
|
return &oldState, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Restore restores the terminal connected to the given file descriptor to a
|
// Restore restores the terminal connected to the given file descriptor to a
|
||||||
// previous state.
|
// previous state.
|
||||||
func Restore(fd int, state *State) error {
|
func Restore(fd int, state *State) error {
|
||||||
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&state.termios)), 0, 0, 0)
|
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&state.termios)), 0, 0, 0)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"./fs"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -14,7 +15,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"./fs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var sysInitPath string
|
var sysInitPath string
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"./fs"
|
||||||
"container/list"
|
"container/list"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -8,7 +9,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
"./fs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Docker struct {
|
type Docker struct {
|
||||||
|
|
|
@ -2,10 +2,10 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"github.com/dotcloud/docker/client"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"github.com/dotcloud/docker/client"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -27,4 +27,3 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"./fs"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"io"
|
|
||||||
"./fs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const testLayerPath string = "/var/lib/docker/docker-ut.tar"
|
const testLayerPath string = "/var/lib/docker/docker-ut.tar"
|
||||||
|
@ -57,7 +57,7 @@ func newTestDocker() (*Docker, error) {
|
||||||
return docker, nil
|
return docker, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTestImage(docker *Docker) (*fs.Image) {
|
func GetTestImage(docker *Docker) *fs.Image {
|
||||||
imgs, err := docker.Store.Images()
|
imgs, err := docker.Store.Images()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
".."
|
".."
|
||||||
"../server"
|
"../server"
|
||||||
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
14
fake/fake.go
14
fake/fake.go
|
@ -1,15 +1,14 @@
|
||||||
package fake
|
package fake
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"math/rand"
|
|
||||||
"io"
|
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"os/exec"
|
"bytes"
|
||||||
"github.com/kr/pty"
|
"github.com/kr/pty"
|
||||||
|
"io"
|
||||||
|
"math/rand"
|
||||||
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func FakeTar() (io.Reader, error) {
|
func FakeTar() (io.Reader, error) {
|
||||||
content := []byte("Hello world!\n")
|
content := []byte("Hello world!\n")
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
@ -27,7 +26,6 @@ func FakeTar() (io.Reader, error) {
|
||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func WriteFakeTar(dst io.Writer) error {
|
func WriteFakeTar(dst io.Writer) error {
|
||||||
if data, err := FakeTar(); err != nil {
|
if data, err := FakeTar(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -37,7 +35,6 @@ func WriteFakeTar(dst io.Writer) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func RandomBytesChanged() uint {
|
func RandomBytesChanged() uint {
|
||||||
return uint(rand.Int31n(24 * 1024 * 1024))
|
return uint(rand.Int31n(24 * 1024 * 1024))
|
||||||
}
|
}
|
||||||
|
@ -54,7 +51,6 @@ func ContainerRunning() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func StartCommand(cmd *exec.Cmd, interactive bool) (io.WriteCloser, io.ReadCloser, error) {
|
func StartCommand(cmd *exec.Cmd, interactive bool) (io.WriteCloser, io.ReadCloser, error) {
|
||||||
if interactive {
|
if interactive {
|
||||||
term, err := pty.Start(cmd)
|
term, err := pty.Start(cmd)
|
||||||
|
@ -76,5 +72,3 @@ func StartCommand(cmd *exec.Cmd, interactive bool) (io.WriteCloser, io.ReadClose
|
||||||
}
|
}
|
||||||
return stdin, stdout, nil
|
return stdin, stdout, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
10
fs/layers.go
10
fs/layers.go
|
@ -1,15 +1,15 @@
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"../future"
|
||||||
"errors"
|
"errors"
|
||||||
"path"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"fmt"
|
"path"
|
||||||
"../future"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LayerStore struct {
|
type LayerStore struct {
|
||||||
|
@ -80,7 +80,6 @@ func (store *LayerStore) Init() error {
|
||||||
return os.Mkdir(store.Root, 0700)
|
return os.Mkdir(store.Root, 0700)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (store *LayerStore) Mktemp() (string, error) {
|
func (store *LayerStore) Mktemp() (string, error) {
|
||||||
tmpName := future.RandomId()
|
tmpName := future.RandomId()
|
||||||
tmpPath := path.Join(store.Root, "tmp-"+tmpName)
|
tmpPath := path.Join(store.Root, "tmp-"+tmpName)
|
||||||
|
@ -94,7 +93,6 @@ func (store *LayerStore) layerPath(id string) string {
|
||||||
return path.Join(store.Root, id)
|
return path.Join(store.Root, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (store *LayerStore) AddLayer(id string, archive Archive, stderr io.Writer, compression Compression) (string, error) {
|
func (store *LayerStore) AddLayer(id string, archive Archive, stderr io.Writer, compression Compression) (string, error) {
|
||||||
if _, err := os.Stat(store.layerPath(id)); err == nil {
|
if _, err := os.Stat(store.layerPath(id)); err == nil {
|
||||||
return "", errors.New("Layer already exists: " + id)
|
return "", errors.New("Layer already exists: " + id)
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"testing"
|
|
||||||
"os"
|
|
||||||
"github.com/dotcloud/docker/fake"
|
"github.com/dotcloud/docker/fake"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func TestLayersInit(t *testing.T) {
|
func TestLayersInit(t *testing.T) {
|
||||||
store := tempStore(t)
|
store := tempStore(t)
|
||||||
defer os.RemoveAll(store.Root)
|
defer os.RemoveAll(store.Root)
|
||||||
|
@ -54,7 +52,6 @@ func TestAddLayerDuplicate(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* HELPER FUNCTIONS
|
* HELPER FUNCTIONS
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,7 +2,6 @@ package fs
|
||||||
|
|
||||||
import "syscall"
|
import "syscall"
|
||||||
|
|
||||||
|
|
||||||
func mount(source string, target string, fstype string, flags uintptr, data string) (err error) {
|
func mount(source string, target string, fstype string, flags uintptr, data string) (err error) {
|
||||||
return syscall.Mount(source, target, fstype, flags, data)
|
return syscall.Mount(source, target, fstype, flags, data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Store struct {
|
type Store struct {
|
||||||
|
@ -168,7 +168,6 @@ type Image struct {
|
||||||
store *Store `db:"-"`
|
store *Store `db:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (image *Image) Copy(pth string) (*Image, error) {
|
func (image *Image) Copy(pth string) (*Image, error) {
|
||||||
if err := image.store.orm.Insert(&Path{Path: pth, Image: image.Id}); err != nil {
|
if err := image.store.orm.Insert(&Path{Path: pth, Image: image.Id}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"../fake"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"../fake"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package future
|
package future
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
|
||||||
"io"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/sha256"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Seed() {
|
func Seed() {
|
||||||
|
@ -60,4 +60,3 @@ func Go(f func() error) chan error {
|
||||||
}()
|
}()
|
||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,25 @@
|
||||||
package image
|
package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"github.com/dotcloud/docker/future"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"encoding/json"
|
"os"
|
||||||
"time"
|
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"errors"
|
|
||||||
"sort"
|
"sort"
|
||||||
"os"
|
|
||||||
"github.com/dotcloud/docker/future"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Store struct {
|
type Store struct {
|
||||||
*Index
|
*Index
|
||||||
Root string
|
Root string
|
||||||
Layers *LayerStore
|
Layers *LayerStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func New(root string) (*Store, error) {
|
func New(root string) (*Store, error) {
|
||||||
abspath, err := filepath.Abs(root)
|
abspath, err := filepath.Abs(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -79,7 +77,6 @@ func (store *Store) Create(name string, source string, layers ...string) (*Image
|
||||||
return image, nil
|
return image, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Index
|
// Index
|
||||||
|
|
||||||
type Index struct {
|
type Index struct {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package docker
|
||||||
|
|
||||||
import "syscall"
|
import "syscall"
|
||||||
|
|
||||||
|
|
||||||
func mount(source string, target string, fstype string, flags uintptr, data string) (err error) {
|
func mount(source string, target string, fstype string, flags uintptr, data string) (err error) {
|
||||||
return syscall.Mount(source, target, fstype, flags, data)
|
return syscall.Mount(source, target, fstype, flags, data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package rcli
|
package rcli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// Use this key to encode an RPC call into an URL,
|
// Use this key to encode an RPC call into an URL,
|
||||||
// eg. domain.tld/path/to/method?q=get_user&q=gordon
|
// eg. domain.tld/path/to/method?q=get_user&q=gordon
|
||||||
const ARG_URL_KEY = "q"
|
const ARG_URL_KEY = "q"
|
||||||
|
@ -16,7 +15,6 @@ func URLToCall(u *url.URL) (method string, args []string) {
|
||||||
return path.Base(u.Path), u.Query()[ARG_URL_KEY]
|
return path.Base(u.Path), u.Query()[ARG_URL_KEY]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func ListenAndServeHTTP(addr string, service Service) error {
|
func ListenAndServeHTTP(addr string, service Service) error {
|
||||||
return http.ListenAndServe(addr, http.HandlerFunc(
|
return http.ListenAndServe(addr, http.HandlerFunc(
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -27,7 +25,6 @@ func ListenAndServeHTTP(addr string, service Service) error {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type AutoFlush struct {
|
type AutoFlush struct {
|
||||||
http.ResponseWriter
|
http.ResponseWriter
|
||||||
}
|
}
|
||||||
|
|
10
rcli/tcp.go
10
rcli/tcp.go
|
@ -1,13 +1,13 @@
|
||||||
package rcli
|
package rcli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
|
||||||
"log"
|
"log"
|
||||||
"fmt"
|
"net"
|
||||||
"encoding/json"
|
|
||||||
"bufio"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Connect to a remote endpoint using protocol `proto` and address `addr`,
|
// Connect to a remote endpoint using protocol `proto` and address `addr`,
|
||||||
|
@ -53,7 +53,6 @@ func ListenAndServe(proto, addr string, service Service) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Parse an rcli call on a new connection, and pass it to `service` if it
|
// Parse an rcli call on a new connection, and pass it to `service` if it
|
||||||
// is valid.
|
// is valid.
|
||||||
func Serve(conn io.ReadWriter, service Service) error {
|
func Serve(conn io.ReadWriter, service Service) error {
|
||||||
|
@ -68,4 +67,3 @@ func Serve(conn io.ReadWriter, service Service) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,13 @@ package rcli
|
||||||
// are the usual suspects.
|
// are the usual suspects.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
|
||||||
"flag"
|
|
||||||
"log"
|
"log"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service interface {
|
type Service interface {
|
||||||
|
@ -25,7 +25,6 @@ type Service interface {
|
||||||
type Cmd func(io.ReadCloser, io.Writer, ...string) error
|
type Cmd func(io.ReadCloser, io.Writer, ...string) error
|
||||||
type CmdMethod func(Service, io.ReadCloser, io.Writer, ...string) error
|
type CmdMethod func(Service, io.ReadCloser, io.Writer, ...string) error
|
||||||
|
|
||||||
|
|
||||||
func call(service Service, stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
func call(service Service, stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
args = []string{"help"}
|
args = []string{"help"}
|
||||||
|
@ -91,4 +90,3 @@ func Subcmd(output io.Writer, name, signature, description string) *flag.FlagSet
|
||||||
}
|
}
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
".."
|
||||||
|
"../fs"
|
||||||
|
"../future"
|
||||||
|
"../rcli"
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
".."
|
|
||||||
"../future"
|
|
||||||
"../fs"
|
|
||||||
"../rcli"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
Loading…
Reference in New Issue