id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
14,300
docker/libcompose
docker/container/container.go
Run
func (c *Container) Run(ctx context.Context, configOverride *config.ServiceConfig) (int, error) { var ( errCh chan error out, stderr io.Writer in io.ReadCloser inFd uintptr ) if configOverride.StdinOpen { in = os.Stdin } if configOverride.Tty { out = os.Stdout stderr = os.Stderr } options := types.ContainerAttachOptions{ Stream: true, Stdin: configOverride.StdinOpen, Stdout: configOverride.Tty, Stderr: configOverride.Tty, } resp, err := c.client.ContainerAttach(ctx, c.container.ID, options) if err != nil { return -1, err } if configOverride.StdinOpen { // set raw terminal inFd, _ = term.GetFdInfo(in) state, err := term.SetRawTerminal(inFd) if err != nil { return -1, err } // restore raw terminal defer term.RestoreTerminal(inFd, state) } // holdHijackedConnection (in goroutine) errCh = make(chan error, 1) go func() { errCh <- holdHijackedConnection(configOverride.Tty, in, out, stderr, resp) }() if err := c.client.ContainerStart(ctx, c.container.ID, types.ContainerStartOptions{}); err != nil { return -1, err } if configOverride.Tty { ws, err := term.GetWinsize(inFd) if err != nil { return -1, err } resizeOpts := types.ResizeOptions{ Height: uint(ws.Height), Width: uint(ws.Width), } if err := c.client.ContainerResize(ctx, c.container.ID, resizeOpts); err != nil { return -1, err } } if err := <-errCh; err != nil { logrus.Debugf("Error hijack: %s", err) return -1, err } exitedContainer, err := c.client.ContainerInspect(ctx, c.container.ID) if err != nil { return -1, err } return exitedContainer.State.ExitCode, nil }
go
func (c *Container) Run(ctx context.Context, configOverride *config.ServiceConfig) (int, error) { var ( errCh chan error out, stderr io.Writer in io.ReadCloser inFd uintptr ) if configOverride.StdinOpen { in = os.Stdin } if configOverride.Tty { out = os.Stdout stderr = os.Stderr } options := types.ContainerAttachOptions{ Stream: true, Stdin: configOverride.StdinOpen, Stdout: configOverride.Tty, Stderr: configOverride.Tty, } resp, err := c.client.ContainerAttach(ctx, c.container.ID, options) if err != nil { return -1, err } if configOverride.StdinOpen { // set raw terminal inFd, _ = term.GetFdInfo(in) state, err := term.SetRawTerminal(inFd) if err != nil { return -1, err } // restore raw terminal defer term.RestoreTerminal(inFd, state) } // holdHijackedConnection (in goroutine) errCh = make(chan error, 1) go func() { errCh <- holdHijackedConnection(configOverride.Tty, in, out, stderr, resp) }() if err := c.client.ContainerStart(ctx, c.container.ID, types.ContainerStartOptions{}); err != nil { return -1, err } if configOverride.Tty { ws, err := term.GetWinsize(inFd) if err != nil { return -1, err } resizeOpts := types.ResizeOptions{ Height: uint(ws.Height), Width: uint(ws.Width), } if err := c.client.ContainerResize(ctx, c.container.ID, resizeOpts); err != nil { return -1, err } } if err := <-errCh; err != nil { logrus.Debugf("Error hijack: %s", err) return -1, err } exitedContainer, err := c.client.ContainerInspect(ctx, c.container.ID) if err != nil { return -1, err } return exitedContainer.State.ExitCode, nil }
[ "func", "(", "c", "*", "Container", ")", "Run", "(", "ctx", "context", ".", "Context", ",", "configOverride", "*", "config", ".", "ServiceConfig", ")", "(", "int", ",", "error", ")", "{", "var", "(", "errCh", "chan", "error", "\n", "out", ",", "stderr", "io", ".", "Writer", "\n", "in", "io", ".", "ReadCloser", "\n", "inFd", "uintptr", "\n", ")", "\n\n", "if", "configOverride", ".", "StdinOpen", "{", "in", "=", "os", ".", "Stdin", "\n", "}", "\n", "if", "configOverride", ".", "Tty", "{", "out", "=", "os", ".", "Stdout", "\n", "stderr", "=", "os", ".", "Stderr", "\n", "}", "\n\n", "options", ":=", "types", ".", "ContainerAttachOptions", "{", "Stream", ":", "true", ",", "Stdin", ":", "configOverride", ".", "StdinOpen", ",", "Stdout", ":", "configOverride", ".", "Tty", ",", "Stderr", ":", "configOverride", ".", "Tty", ",", "}", "\n\n", "resp", ",", "err", ":=", "c", ".", "client", ".", "ContainerAttach", "(", "ctx", ",", "c", ".", "container", ".", "ID", ",", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "if", "configOverride", ".", "StdinOpen", "{", "// set raw terminal", "inFd", ",", "_", "=", "term", ".", "GetFdInfo", "(", "in", ")", "\n", "state", ",", "err", ":=", "term", ".", "SetRawTerminal", "(", "inFd", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n", "// restore raw terminal", "defer", "term", ".", "RestoreTerminal", "(", "inFd", ",", "state", ")", "\n", "}", "\n\n", "// holdHijackedConnection (in goroutine)", "errCh", "=", "make", "(", "chan", "error", ",", "1", ")", "\n", "go", "func", "(", ")", "{", "errCh", "<-", "holdHijackedConnection", "(", "configOverride", ".", "Tty", ",", "in", ",", "out", ",", "stderr", ",", "resp", ")", "\n", "}", "(", ")", "\n\n", "if", "err", ":=", "c", ".", "client", ".", "ContainerStart", "(", "ctx", ",", "c", ".", "container", ".", "ID", ",", "types", ".", "ContainerStartOptions", "{", "}", ")", ";", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "if", "configOverride", ".", "Tty", "{", "ws", ",", "err", ":=", "term", ".", "GetWinsize", "(", "inFd", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "resizeOpts", ":=", "types", ".", "ResizeOptions", "{", "Height", ":", "uint", "(", "ws", ".", "Height", ")", ",", "Width", ":", "uint", "(", "ws", ".", "Width", ")", ",", "}", "\n\n", "if", "err", ":=", "c", ".", "client", ".", "ContainerResize", "(", "ctx", ",", "c", ".", "container", ".", "ID", ",", "resizeOpts", ")", ";", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n", "}", "\n\n", "if", "err", ":=", "<-", "errCh", ";", "err", "!=", "nil", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "exitedContainer", ",", "err", ":=", "c", ".", "client", ".", "ContainerInspect", "(", "ctx", ",", "c", ".", "container", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "return", "exitedContainer", ".", "State", ".", "ExitCode", ",", "nil", "\n", "}" ]
// Run creates, start and attach to the container based on the image name, // the specified configuration. // It will always create a new container.
[ "Run", "creates", "start", "and", "attach", "to", "the", "container", "based", "on", "the", "image", "name", "the", "specified", "configuration", ".", "It", "will", "always", "create", "a", "new", "container", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/container/container.go#L177-L253
14,301
docker/libcompose
docker/container/container.go
Start
func (c *Container) Start(ctx context.Context) error { logrus.WithFields(logrus.Fields{"container.ID": c.container.ID, "container.Name": c.container.Name}).Debug("Starting container") if err := c.client.ContainerStart(ctx, c.container.ID, types.ContainerStartOptions{}); err != nil { logrus.WithFields(logrus.Fields{"container.ID": c.container.ID, "container.Name": c.container.Name}).Debug("Failed to start container") return err } return nil }
go
func (c *Container) Start(ctx context.Context) error { logrus.WithFields(logrus.Fields{"container.ID": c.container.ID, "container.Name": c.container.Name}).Debug("Starting container") if err := c.client.ContainerStart(ctx, c.container.ID, types.ContainerStartOptions{}); err != nil { logrus.WithFields(logrus.Fields{"container.ID": c.container.ID, "container.Name": c.container.Name}).Debug("Failed to start container") return err } return nil }
[ "func", "(", "c", "*", "Container", ")", "Start", "(", "ctx", "context", ".", "Context", ")", "error", "{", "logrus", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "\"", "\"", ":", "c", ".", "container", ".", "ID", ",", "\"", "\"", ":", "c", ".", "container", ".", "Name", "}", ")", ".", "Debug", "(", "\"", "\"", ")", "\n", "if", "err", ":=", "c", ".", "client", ".", "ContainerStart", "(", "ctx", ",", "c", ".", "container", ".", "ID", ",", "types", ".", "ContainerStartOptions", "{", "}", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "\"", "\"", ":", "c", ".", "container", ".", "ID", ",", "\"", "\"", ":", "c", ".", "container", ".", "Name", "}", ")", ".", "Debug", "(", "\"", "\"", ")", "\n", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Start the specified container with the specified host config
[ "Start", "the", "specified", "container", "with", "the", "specified", "host", "config" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/container/container.go#L303-L310
14,302
docker/libcompose
docker/container/container.go
Restart
func (c *Container) Restart(ctx context.Context, timeout int) error { timeoutDuration := time.Duration(timeout) * time.Second return c.client.ContainerRestart(ctx, c.container.ID, &timeoutDuration) }
go
func (c *Container) Restart(ctx context.Context, timeout int) error { timeoutDuration := time.Duration(timeout) * time.Second return c.client.ContainerRestart(ctx, c.container.ID, &timeoutDuration) }
[ "func", "(", "c", "*", "Container", ")", "Restart", "(", "ctx", "context", ".", "Context", ",", "timeout", "int", ")", "error", "{", "timeoutDuration", ":=", "time", ".", "Duration", "(", "timeout", ")", "*", "time", ".", "Second", "\n", "return", "c", ".", "client", ".", "ContainerRestart", "(", "ctx", ",", "c", ".", "container", ".", "ID", ",", "&", "timeoutDuration", ")", "\n", "}" ]
// Restart restarts the container if existing, does nothing otherwise.
[ "Restart", "restarts", "the", "container", "if", "existing", "does", "nothing", "otherwise", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/container/container.go#L313-L316
14,303
docker/libcompose
docker/container/container.go
Log
func (c *Container) Log(ctx context.Context, l logger.Logger, follow bool) error { info, err := c.client.ContainerInspect(ctx, c.container.ID) if err != nil { return err } options := types.ContainerLogsOptions{ ShowStdout: true, ShowStderr: true, Follow: follow, Tail: "all", } responseBody, err := c.client.ContainerLogs(ctx, c.container.ID, options) if err != nil { return err } defer responseBody.Close() if info.Config.Tty { _, err = io.Copy(&logger.Wrapper{Logger: l}, responseBody) } else { _, err = stdcopy.StdCopy(&logger.Wrapper{Logger: l}, &logger.Wrapper{Logger: l, Err: true}, responseBody) } logrus.WithFields(logrus.Fields{"Logger": l, "err": err}).Debug("c.client.Logs() returned error") return err }
go
func (c *Container) Log(ctx context.Context, l logger.Logger, follow bool) error { info, err := c.client.ContainerInspect(ctx, c.container.ID) if err != nil { return err } options := types.ContainerLogsOptions{ ShowStdout: true, ShowStderr: true, Follow: follow, Tail: "all", } responseBody, err := c.client.ContainerLogs(ctx, c.container.ID, options) if err != nil { return err } defer responseBody.Close() if info.Config.Tty { _, err = io.Copy(&logger.Wrapper{Logger: l}, responseBody) } else { _, err = stdcopy.StdCopy(&logger.Wrapper{Logger: l}, &logger.Wrapper{Logger: l, Err: true}, responseBody) } logrus.WithFields(logrus.Fields{"Logger": l, "err": err}).Debug("c.client.Logs() returned error") return err }
[ "func", "(", "c", "*", "Container", ")", "Log", "(", "ctx", "context", ".", "Context", ",", "l", "logger", ".", "Logger", ",", "follow", "bool", ")", "error", "{", "info", ",", "err", ":=", "c", ".", "client", ".", "ContainerInspect", "(", "ctx", ",", "c", ".", "container", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "options", ":=", "types", ".", "ContainerLogsOptions", "{", "ShowStdout", ":", "true", ",", "ShowStderr", ":", "true", ",", "Follow", ":", "follow", ",", "Tail", ":", "\"", "\"", ",", "}", "\n", "responseBody", ",", "err", ":=", "c", ".", "client", ".", "ContainerLogs", "(", "ctx", ",", "c", ".", "container", ".", "ID", ",", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "responseBody", ".", "Close", "(", ")", "\n\n", "if", "info", ".", "Config", ".", "Tty", "{", "_", ",", "err", "=", "io", ".", "Copy", "(", "&", "logger", ".", "Wrapper", "{", "Logger", ":", "l", "}", ",", "responseBody", ")", "\n", "}", "else", "{", "_", ",", "err", "=", "stdcopy", ".", "StdCopy", "(", "&", "logger", ".", "Wrapper", "{", "Logger", ":", "l", "}", ",", "&", "logger", ".", "Wrapper", "{", "Logger", ":", "l", ",", "Err", ":", "true", "}", ",", "responseBody", ")", "\n", "}", "\n", "logrus", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "\"", "\"", ":", "l", ",", "\"", "\"", ":", "err", "}", ")", ".", "Debug", "(", "\"", "\"", ")", "\n\n", "return", "err", "\n", "}" ]
// Log forwards container logs to the project configured logger.
[ "Log", "forwards", "container", "logs", "to", "the", "project", "configured", "logger", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/container/container.go#L319-L345
14,304
docker/libcompose
docker/container/container.go
Port
func (c *Container) Port(ctx context.Context, port string) (string, error) { if bindings, ok := c.container.NetworkSettings.Ports[nat.Port(port)]; ok { result := []string{} for _, binding := range bindings { result = append(result, binding.HostIP+":"+binding.HostPort) } return strings.Join(result, "\n"), nil } return "", nil }
go
func (c *Container) Port(ctx context.Context, port string) (string, error) { if bindings, ok := c.container.NetworkSettings.Ports[nat.Port(port)]; ok { result := []string{} for _, binding := range bindings { result = append(result, binding.HostIP+":"+binding.HostPort) } return strings.Join(result, "\n"), nil } return "", nil }
[ "func", "(", "c", "*", "Container", ")", "Port", "(", "ctx", "context", ".", "Context", ",", "port", "string", ")", "(", "string", ",", "error", ")", "{", "if", "bindings", ",", "ok", ":=", "c", ".", "container", ".", "NetworkSettings", ".", "Ports", "[", "nat", ".", "Port", "(", "port", ")", "]", ";", "ok", "{", "result", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "binding", ":=", "range", "bindings", "{", "result", "=", "append", "(", "result", ",", "binding", ".", "HostIP", "+", "\"", "\"", "+", "binding", ".", "HostPort", ")", "\n", "}", "\n\n", "return", "strings", ".", "Join", "(", "result", ",", "\"", "\\n", "\"", ")", ",", "nil", "\n", "}", "\n", "return", "\"", "\"", ",", "nil", "\n", "}" ]
// Port returns the host port the specified port is mapped on.
[ "Port", "returns", "the", "host", "port", "the", "specified", "port", "is", "mapped", "on", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/container/container.go#L348-L358
14,305
docker/libcompose
docker/container/container.go
Networks
func (c *Container) Networks() (map[string]*network.EndpointSettings, error) { return c.container.NetworkSettings.Networks, nil }
go
func (c *Container) Networks() (map[string]*network.EndpointSettings, error) { return c.container.NetworkSettings.Networks, nil }
[ "func", "(", "c", "*", "Container", ")", "Networks", "(", ")", "(", "map", "[", "string", "]", "*", "network", ".", "EndpointSettings", ",", "error", ")", "{", "return", "c", ".", "container", ".", "NetworkSettings", ".", "Networks", ",", "nil", "\n", "}" ]
// Networks returns the containers network
[ "Networks", "returns", "the", "containers", "network" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/container/container.go#L361-L363
14,306
docker/libcompose
docker/container/container.go
Hash
func (c *Container) Hash() string { return c.container.Config.Labels[labels.HASH.Str()] }
go
func (c *Container) Hash() string { return c.container.Config.Labels[labels.HASH.Str()] }
[ "func", "(", "c", "*", "Container", ")", "Hash", "(", ")", "string", "{", "return", "c", ".", "container", ".", "Config", ".", "Labels", "[", "labels", ".", "HASH", ".", "Str", "(", ")", "]", "\n", "}" ]
// Hash returns the container hash stored as label.
[ "Hash", "returns", "the", "container", "hash", "stored", "as", "label", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/container/container.go#L393-L395
14,307
docker/libcompose
docker/container/container.go
Number
func (c *Container) Number() (int, error) { numberStr := c.container.Config.Labels[labels.NUMBER.Str()] return strconv.Atoi(numberStr) }
go
func (c *Container) Number() (int, error) { numberStr := c.container.Config.Labels[labels.NUMBER.Str()] return strconv.Atoi(numberStr) }
[ "func", "(", "c", "*", "Container", ")", "Number", "(", ")", "(", "int", ",", "error", ")", "{", "numberStr", ":=", "c", ".", "container", ".", "Config", ".", "Labels", "[", "labels", ".", "NUMBER", ".", "Str", "(", ")", "]", "\n", "return", "strconv", ".", "Atoi", "(", "numberStr", ")", "\n", "}" ]
// Number returns the container number stored as label.
[ "Number", "returns", "the", "container", "number", "stored", "as", "label", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/container/container.go#L398-L401
14,308
docker/libcompose
docker/client/client.go
Create
func Create(c Options) (client.APIClient, error) { if c.Host == "" { if os.Getenv("DOCKER_API_VERSION") == "" { os.Setenv("DOCKER_API_VERSION", DefaultAPIVersion) } client, err := client.NewEnvClient() if err != nil { return nil, err } return client, nil } apiVersion := c.APIVersion if apiVersion == "" { apiVersion = DefaultAPIVersion } if c.TLSOptions.CAFile == "" { c.TLSOptions.CAFile = filepath.Join(dockerCertPath, defaultCaFile) } if c.TLSOptions.CertFile == "" { c.TLSOptions.CertFile = filepath.Join(dockerCertPath, defaultCertFile) } if c.TLSOptions.KeyFile == "" { c.TLSOptions.KeyFile = filepath.Join(dockerCertPath, defaultKeyFile) } if c.TrustKey == "" { c.TrustKey = filepath.Join(homedir.Get(), ".docker", defaultTrustKeyFile) } if c.TLSVerify { c.TLS = true } if c.TLS { c.TLSOptions.InsecureSkipVerify = !c.TLSVerify } var httpClient *http.Client if c.TLS { config, err := tlsconfig.Client(c.TLSOptions) if err != nil { return nil, err } httpClient = &http.Client{ Transport: &http.Transport{ TLSClientConfig: config, }, } } customHeaders := map[string]string{} customHeaders["User-Agent"] = fmt.Sprintf("Libcompose-Client/%s (%s)", version.VERSION, runtime.GOOS) client, err := client.NewClientWithOpts( client.WithHTTPClient(httpClient), client.WithHost(c.Host), client.WithVersion(apiVersion), client.WithHTTPHeaders(customHeaders), ) if err != nil { return nil, err } return client, nil }
go
func Create(c Options) (client.APIClient, error) { if c.Host == "" { if os.Getenv("DOCKER_API_VERSION") == "" { os.Setenv("DOCKER_API_VERSION", DefaultAPIVersion) } client, err := client.NewEnvClient() if err != nil { return nil, err } return client, nil } apiVersion := c.APIVersion if apiVersion == "" { apiVersion = DefaultAPIVersion } if c.TLSOptions.CAFile == "" { c.TLSOptions.CAFile = filepath.Join(dockerCertPath, defaultCaFile) } if c.TLSOptions.CertFile == "" { c.TLSOptions.CertFile = filepath.Join(dockerCertPath, defaultCertFile) } if c.TLSOptions.KeyFile == "" { c.TLSOptions.KeyFile = filepath.Join(dockerCertPath, defaultKeyFile) } if c.TrustKey == "" { c.TrustKey = filepath.Join(homedir.Get(), ".docker", defaultTrustKeyFile) } if c.TLSVerify { c.TLS = true } if c.TLS { c.TLSOptions.InsecureSkipVerify = !c.TLSVerify } var httpClient *http.Client if c.TLS { config, err := tlsconfig.Client(c.TLSOptions) if err != nil { return nil, err } httpClient = &http.Client{ Transport: &http.Transport{ TLSClientConfig: config, }, } } customHeaders := map[string]string{} customHeaders["User-Agent"] = fmt.Sprintf("Libcompose-Client/%s (%s)", version.VERSION, runtime.GOOS) client, err := client.NewClientWithOpts( client.WithHTTPClient(httpClient), client.WithHost(c.Host), client.WithVersion(apiVersion), client.WithHTTPHeaders(customHeaders), ) if err != nil { return nil, err } return client, nil }
[ "func", "Create", "(", "c", "Options", ")", "(", "client", ".", "APIClient", ",", "error", ")", "{", "if", "c", ".", "Host", "==", "\"", "\"", "{", "if", "os", ".", "Getenv", "(", "\"", "\"", ")", "==", "\"", "\"", "{", "os", ".", "Setenv", "(", "\"", "\"", ",", "DefaultAPIVersion", ")", "\n", "}", "\n", "client", ",", "err", ":=", "client", ".", "NewEnvClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "client", ",", "nil", "\n", "}", "\n\n", "apiVersion", ":=", "c", ".", "APIVersion", "\n", "if", "apiVersion", "==", "\"", "\"", "{", "apiVersion", "=", "DefaultAPIVersion", "\n", "}", "\n\n", "if", "c", ".", "TLSOptions", ".", "CAFile", "==", "\"", "\"", "{", "c", ".", "TLSOptions", ".", "CAFile", "=", "filepath", ".", "Join", "(", "dockerCertPath", ",", "defaultCaFile", ")", "\n", "}", "\n", "if", "c", ".", "TLSOptions", ".", "CertFile", "==", "\"", "\"", "{", "c", ".", "TLSOptions", ".", "CertFile", "=", "filepath", ".", "Join", "(", "dockerCertPath", ",", "defaultCertFile", ")", "\n", "}", "\n", "if", "c", ".", "TLSOptions", ".", "KeyFile", "==", "\"", "\"", "{", "c", ".", "TLSOptions", ".", "KeyFile", "=", "filepath", ".", "Join", "(", "dockerCertPath", ",", "defaultKeyFile", ")", "\n", "}", "\n", "if", "c", ".", "TrustKey", "==", "\"", "\"", "{", "c", ".", "TrustKey", "=", "filepath", ".", "Join", "(", "homedir", ".", "Get", "(", ")", ",", "\"", "\"", ",", "defaultTrustKeyFile", ")", "\n", "}", "\n", "if", "c", ".", "TLSVerify", "{", "c", ".", "TLS", "=", "true", "\n", "}", "\n", "if", "c", ".", "TLS", "{", "c", ".", "TLSOptions", ".", "InsecureSkipVerify", "=", "!", "c", ".", "TLSVerify", "\n", "}", "\n\n", "var", "httpClient", "*", "http", ".", "Client", "\n", "if", "c", ".", "TLS", "{", "config", ",", "err", ":=", "tlsconfig", ".", "Client", "(", "c", ".", "TLSOptions", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "httpClient", "=", "&", "http", ".", "Client", "{", "Transport", ":", "&", "http", ".", "Transport", "{", "TLSClientConfig", ":", "config", ",", "}", ",", "}", "\n", "}", "\n\n", "customHeaders", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "customHeaders", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "version", ".", "VERSION", ",", "runtime", ".", "GOOS", ")", "\n\n", "client", ",", "err", ":=", "client", ".", "NewClientWithOpts", "(", "client", ".", "WithHTTPClient", "(", "httpClient", ")", ",", "client", ".", "WithHost", "(", "c", ".", "Host", ")", ",", "client", ".", "WithVersion", "(", "apiVersion", ")", ",", "client", ".", "WithHTTPHeaders", "(", "customHeaders", ")", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "client", ",", "nil", "\n", "}" ]
// Create creates a docker client based on the specified options.
[ "Create", "creates", "a", "docker", "client", "based", "on", "the", "specified", "options", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/client/client.go#L47-L110
14,309
docker/libcompose
docker/service/service_factory.go
Create
func (s *Factory) Create(project *project.Project, name string, serviceConfig *config.ServiceConfig) (project.Service, error) { return NewService(name, serviceConfig, s.context), nil }
go
func (s *Factory) Create(project *project.Project, name string, serviceConfig *config.ServiceConfig) (project.Service, error) { return NewService(name, serviceConfig, s.context), nil }
[ "func", "(", "s", "*", "Factory", ")", "Create", "(", "project", "*", "project", ".", "Project", ",", "name", "string", ",", "serviceConfig", "*", "config", ".", "ServiceConfig", ")", "(", "project", ".", "Service", ",", "error", ")", "{", "return", "NewService", "(", "name", ",", "serviceConfig", ",", "s", ".", "context", ")", ",", "nil", "\n", "}" ]
// Create creates a Service based on the specified project, name and service configuration.
[ "Create", "creates", "a", "Service", "based", "on", "the", "specified", "project", "name", "and", "service", "configuration", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service_factory.go#L22-L24
14,310
docker/libcompose
docker/service/service.go
NewService
func NewService(name string, serviceConfig *config.ServiceConfig, context *ctx.Context) *Service { return &Service{ name: name, project: context.Project, serviceConfig: serviceConfig, clientFactory: context.ClientFactory, authLookup: context.AuthLookup, context: context, } }
go
func NewService(name string, serviceConfig *config.ServiceConfig, context *ctx.Context) *Service { return &Service{ name: name, project: context.Project, serviceConfig: serviceConfig, clientFactory: context.ClientFactory, authLookup: context.AuthLookup, context: context, } }
[ "func", "NewService", "(", "name", "string", ",", "serviceConfig", "*", "config", ".", "ServiceConfig", ",", "context", "*", "ctx", ".", "Context", ")", "*", "Service", "{", "return", "&", "Service", "{", "name", ":", "name", ",", "project", ":", "context", ".", "Project", ",", "serviceConfig", ":", "serviceConfig", ",", "clientFactory", ":", "context", ".", "ClientFactory", ",", "authLookup", ":", "context", ".", "AuthLookup", ",", "context", ":", "context", ",", "}", "\n", "}" ]
// NewService creates a service
[ "NewService", "creates", "a", "service" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L44-L53
14,311
docker/libcompose
docker/service/service.go
Create
func (s *Service) Create(ctx context.Context, options options.Create) error { containers, err := s.collectContainers(ctx) if err != nil { return err } if err := s.ensureImageExists(ctx, options.NoBuild, options.ForceBuild); err != nil { return err } if len(containers) != 0 { return s.eachContainer(ctx, containers, func(c *container.Container) error { _, err := s.recreateIfNeeded(ctx, c, options.NoRecreate, options.ForceRecreate) return err }) } namer, err := s.namer(ctx, 1) if err != nil { return err } _, err = s.createContainer(ctx, namer, "", nil, false) return err }
go
func (s *Service) Create(ctx context.Context, options options.Create) error { containers, err := s.collectContainers(ctx) if err != nil { return err } if err := s.ensureImageExists(ctx, options.NoBuild, options.ForceBuild); err != nil { return err } if len(containers) != 0 { return s.eachContainer(ctx, containers, func(c *container.Container) error { _, err := s.recreateIfNeeded(ctx, c, options.NoRecreate, options.ForceRecreate) return err }) } namer, err := s.namer(ctx, 1) if err != nil { return err } _, err = s.createContainer(ctx, namer, "", nil, false) return err }
[ "func", "(", "s", "*", "Service", ")", "Create", "(", "ctx", "context", ".", "Context", ",", "options", "options", ".", "Create", ")", "error", "{", "containers", ",", "err", ":=", "s", ".", "collectContainers", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "ensureImageExists", "(", "ctx", ",", "options", ".", "NoBuild", ",", "options", ".", "ForceBuild", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "len", "(", "containers", ")", "!=", "0", "{", "return", "s", ".", "eachContainer", "(", "ctx", ",", "containers", ",", "func", "(", "c", "*", "container", ".", "Container", ")", "error", "{", "_", ",", "err", ":=", "s", ".", "recreateIfNeeded", "(", "ctx", ",", "c", ",", "options", ".", "NoRecreate", ",", "options", ".", "ForceRecreate", ")", "\n", "return", "err", "\n", "}", ")", "\n", "}", "\n\n", "namer", ",", "err", ":=", "s", ".", "namer", "(", "ctx", ",", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "_", ",", "err", "=", "s", ".", "createContainer", "(", "ctx", ",", "namer", ",", "\"", "\"", ",", "nil", ",", "false", ")", "\n", "return", "err", "\n", "}" ]
// Create implements Service.Create. It ensures the image exists or build it // if it can and then create a container.
[ "Create", "implements", "Service", ".", "Create", ".", "It", "ensures", "the", "image", "exists", "or", "build", "it", "if", "it", "can", "and", "then", "create", "a", "container", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L72-L96
14,312
docker/libcompose
docker/service/service.go
Build
func (s *Service) Build(ctx context.Context, buildOptions options.Build) error { return s.build(ctx, buildOptions) }
go
func (s *Service) Build(ctx context.Context, buildOptions options.Build) error { return s.build(ctx, buildOptions) }
[ "func", "(", "s", "*", "Service", ")", "Build", "(", "ctx", "context", ".", "Context", ",", "buildOptions", "options", ".", "Build", ")", "error", "{", "return", "s", ".", "build", "(", "ctx", ",", "buildOptions", ")", "\n", "}" ]
// Build implements Service.Build. It will try to build the image and returns an error if any.
[ "Build", "implements", "Service", ".", "Build", ".", "It", "will", "try", "to", "build", "the", "image", "and", "returns", "an", "error", "if", "any", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L168-L170
14,313
docker/libcompose
docker/service/service.go
Up
func (s *Service) Up(ctx context.Context, options options.Up) error { containers, err := s.collectContainers(ctx) if err != nil { return err } var imageName = s.imageName() if len(containers) == 0 || !options.NoRecreate { if err = s.ensureImageExists(ctx, options.NoBuild, options.ForceBuild); err != nil { return err } } return s.up(ctx, imageName, true, options) }
go
func (s *Service) Up(ctx context.Context, options options.Up) error { containers, err := s.collectContainers(ctx) if err != nil { return err } var imageName = s.imageName() if len(containers) == 0 || !options.NoRecreate { if err = s.ensureImageExists(ctx, options.NoBuild, options.ForceBuild); err != nil { return err } } return s.up(ctx, imageName, true, options) }
[ "func", "(", "s", "*", "Service", ")", "Up", "(", "ctx", "context", ".", "Context", ",", "options", "options", ".", "Up", ")", "error", "{", "containers", ",", "err", ":=", "s", ".", "collectContainers", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "var", "imageName", "=", "s", ".", "imageName", "(", ")", "\n", "if", "len", "(", "containers", ")", "==", "0", "||", "!", "options", ".", "NoRecreate", "{", "if", "err", "=", "s", ".", "ensureImageExists", "(", "ctx", ",", "options", ".", "NoBuild", ",", "options", ".", "ForceBuild", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "s", ".", "up", "(", "ctx", ",", "imageName", ",", "true", ",", "options", ")", "\n", "}" ]
// Up implements Service.Up. It builds the image if needed, creates a container // and start it.
[ "Up", "implements", "Service", ".", "Up", ".", "It", "builds", "the", "image", "if", "needed", "creates", "a", "container", "and", "start", "it", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L229-L243
14,314
docker/libcompose
docker/service/service.go
Run
func (s *Service) Run(ctx context.Context, commandParts []string, options options.Run) (int, error) { err := s.ensureImageExists(ctx, false, false) if err != nil { return -1, err } client := s.clientFactory.Create(s) namer, err := NewNamer(ctx, client, s.project.Name, s.name, true) if err != nil { return -1, err } configOverride := &config.ServiceConfig{Command: commandParts, Tty: !options.DisableTty, StdinOpen: !options.DisableTty} c, err := s.createContainer(ctx, namer, "", configOverride, true) if err != nil { return -1, err } if err := s.connectContainerToNetworks(ctx, c, true); err != nil { return -1, err } if options.Detached { logrus.Infof("%s", c.Name()) return 0, c.Start(ctx) } return c.Run(ctx, configOverride) }
go
func (s *Service) Run(ctx context.Context, commandParts []string, options options.Run) (int, error) { err := s.ensureImageExists(ctx, false, false) if err != nil { return -1, err } client := s.clientFactory.Create(s) namer, err := NewNamer(ctx, client, s.project.Name, s.name, true) if err != nil { return -1, err } configOverride := &config.ServiceConfig{Command: commandParts, Tty: !options.DisableTty, StdinOpen: !options.DisableTty} c, err := s.createContainer(ctx, namer, "", configOverride, true) if err != nil { return -1, err } if err := s.connectContainerToNetworks(ctx, c, true); err != nil { return -1, err } if options.Detached { logrus.Infof("%s", c.Name()) return 0, c.Start(ctx) } return c.Run(ctx, configOverride) }
[ "func", "(", "s", "*", "Service", ")", "Run", "(", "ctx", "context", ".", "Context", ",", "commandParts", "[", "]", "string", ",", "options", "options", ".", "Run", ")", "(", "int", ",", "error", ")", "{", "err", ":=", "s", ".", "ensureImageExists", "(", "ctx", ",", "false", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "client", ":=", "s", ".", "clientFactory", ".", "Create", "(", "s", ")", "\n\n", "namer", ",", "err", ":=", "NewNamer", "(", "ctx", ",", "client", ",", "s", ".", "project", ".", "Name", ",", "s", ".", "name", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "configOverride", ":=", "&", "config", ".", "ServiceConfig", "{", "Command", ":", "commandParts", ",", "Tty", ":", "!", "options", ".", "DisableTty", ",", "StdinOpen", ":", "!", "options", ".", "DisableTty", "}", "\n\n", "c", ",", "err", ":=", "s", ".", "createContainer", "(", "ctx", ",", "namer", ",", "\"", "\"", ",", "configOverride", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "connectContainerToNetworks", "(", "ctx", ",", "c", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "if", "options", ".", "Detached", "{", "logrus", ".", "Infof", "(", "\"", "\"", ",", "c", ".", "Name", "(", ")", ")", "\n", "return", "0", ",", "c", ".", "Start", "(", "ctx", ")", "\n", "}", "\n", "return", "c", ".", "Run", "(", "ctx", ",", "configOverride", ")", "\n", "}" ]
// Run implements Service.Run. It runs a one of command within the service container. // It always create a new container.
[ "Run", "implements", "Service", ".", "Run", ".", "It", "runs", "a", "one", "of", "command", "within", "the", "service", "container", ".", "It", "always", "create", "a", "new", "container", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L247-L276
14,315
docker/libcompose
docker/service/service.go
Start
func (s *Service) Start(ctx context.Context) error { return s.collectContainersAndDo(ctx, func(c *container.Container) error { if err := s.connectContainerToNetworks(ctx, c, false); err != nil { return err } return c.Start(ctx) }) }
go
func (s *Service) Start(ctx context.Context) error { return s.collectContainersAndDo(ctx, func(c *container.Container) error { if err := s.connectContainerToNetworks(ctx, c, false); err != nil { return err } return c.Start(ctx) }) }
[ "func", "(", "s", "*", "Service", ")", "Start", "(", "ctx", "context", ".", "Context", ")", "error", "{", "return", "s", ".", "collectContainersAndDo", "(", "ctx", ",", "func", "(", "c", "*", "container", ".", "Container", ")", "error", "{", "if", "err", ":=", "s", ".", "connectContainerToNetworks", "(", "ctx", ",", "c", ",", "false", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "c", ".", "Start", "(", "ctx", ")", "\n", "}", ")", "\n", "}" ]
// Start implements Service.Start. It tries to start a container without creating it.
[ "Start", "implements", "Service", ".", "Start", ".", "It", "tries", "to", "start", "a", "container", "without", "creating", "it", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L299-L306
14,316
docker/libcompose
docker/service/service.go
NetworkDisconnect
func (s *Service) NetworkDisconnect(ctx context.Context, c *container.Container, net *yaml.Network, oneOff bool) error { containerID := c.ID() client := s.clientFactory.Create(s) return client.NetworkDisconnect(ctx, net.RealName, containerID, true) }
go
func (s *Service) NetworkDisconnect(ctx context.Context, c *container.Container, net *yaml.Network, oneOff bool) error { containerID := c.ID() client := s.clientFactory.Create(s) return client.NetworkDisconnect(ctx, net.RealName, containerID, true) }
[ "func", "(", "s", "*", "Service", ")", "NetworkDisconnect", "(", "ctx", "context", ".", "Context", ",", "c", "*", "container", ".", "Container", ",", "net", "*", "yaml", ".", "Network", ",", "oneOff", "bool", ")", "error", "{", "containerID", ":=", "c", ".", "ID", "(", ")", "\n", "client", ":=", "s", ".", "clientFactory", ".", "Create", "(", "s", ")", "\n", "return", "client", ".", "NetworkDisconnect", "(", "ctx", ",", "net", ".", "RealName", ",", "containerID", ",", "true", ")", "\n", "}" ]
// NetworkDisconnect disconnects the container from the specified network
[ "NetworkDisconnect", "disconnects", "the", "container", "from", "the", "specified", "network" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L386-L390
14,317
docker/libcompose
docker/service/service.go
OutOfSync
func (s *Service) OutOfSync(ctx context.Context, c *container.Container) (bool, error) { if c.ImageConfig() != s.serviceConfig.Image { logrus.Debugf("Images for %s do not match %s!=%s", c.Name(), c.ImageConfig(), s.serviceConfig.Image) return true, nil } expectedHash := config.GetServiceHash(s.name, s.Config()) if c.Hash() != expectedHash { logrus.Debugf("Hashes for %s do not match %s!=%s", c.Name(), c.Hash(), expectedHash) return true, nil } image, err := image.InspectImage(ctx, s.clientFactory.Create(s), c.ImageConfig()) if err != nil { if client.IsErrNotFound(err) { logrus.Debugf("Image %s do not exist, do not know if it's out of sync", c.Image()) return false, nil } return false, err } logrus.Debugf("Checking existing image name vs id: %s == %s", image.ID, c.Image()) return image.ID != c.Image(), err }
go
func (s *Service) OutOfSync(ctx context.Context, c *container.Container) (bool, error) { if c.ImageConfig() != s.serviceConfig.Image { logrus.Debugf("Images for %s do not match %s!=%s", c.Name(), c.ImageConfig(), s.serviceConfig.Image) return true, nil } expectedHash := config.GetServiceHash(s.name, s.Config()) if c.Hash() != expectedHash { logrus.Debugf("Hashes for %s do not match %s!=%s", c.Name(), c.Hash(), expectedHash) return true, nil } image, err := image.InspectImage(ctx, s.clientFactory.Create(s), c.ImageConfig()) if err != nil { if client.IsErrNotFound(err) { logrus.Debugf("Image %s do not exist, do not know if it's out of sync", c.Image()) return false, nil } return false, err } logrus.Debugf("Checking existing image name vs id: %s == %s", image.ID, c.Image()) return image.ID != c.Image(), err }
[ "func", "(", "s", "*", "Service", ")", "OutOfSync", "(", "ctx", "context", ".", "Context", ",", "c", "*", "container", ".", "Container", ")", "(", "bool", ",", "error", ")", "{", "if", "c", ".", "ImageConfig", "(", ")", "!=", "s", ".", "serviceConfig", ".", "Image", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "c", ".", "Name", "(", ")", ",", "c", ".", "ImageConfig", "(", ")", ",", "s", ".", "serviceConfig", ".", "Image", ")", "\n", "return", "true", ",", "nil", "\n", "}", "\n\n", "expectedHash", ":=", "config", ".", "GetServiceHash", "(", "s", ".", "name", ",", "s", ".", "Config", "(", ")", ")", "\n", "if", "c", ".", "Hash", "(", ")", "!=", "expectedHash", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "c", ".", "Name", "(", ")", ",", "c", ".", "Hash", "(", ")", ",", "expectedHash", ")", "\n", "return", "true", ",", "nil", "\n", "}", "\n\n", "image", ",", "err", ":=", "image", ".", "InspectImage", "(", "ctx", ",", "s", ".", "clientFactory", ".", "Create", "(", "s", ")", ",", "c", ".", "ImageConfig", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "if", "client", ".", "IsErrNotFound", "(", "err", ")", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "c", ".", "Image", "(", ")", ")", "\n", "return", "false", ",", "nil", "\n", "}", "\n", "return", "false", ",", "err", "\n", "}", "\n\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "image", ".", "ID", ",", "c", ".", "Image", "(", ")", ")", "\n", "return", "image", ".", "ID", "!=", "c", ".", "Image", "(", ")", ",", "err", "\n", "}" ]
// OutOfSync checks if the container is out of sync with the service definition. // It looks if the the service hash container label is the same as the computed one.
[ "OutOfSync", "checks", "if", "the", "container", "is", "out", "of", "sync", "with", "the", "service", "definition", ".", "It", "looks", "if", "the", "the", "service", "hash", "container", "label", "is", "the", "same", "as", "the", "computed", "one", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L491-L514
14,318
docker/libcompose
docker/service/service.go
Stop
func (s *Service) Stop(ctx context.Context, timeout int) error { timeout = s.stopTimeout(timeout) return s.collectContainersAndDo(ctx, func(c *container.Container) error { return c.Stop(ctx, timeout) }) }
go
func (s *Service) Stop(ctx context.Context, timeout int) error { timeout = s.stopTimeout(timeout) return s.collectContainersAndDo(ctx, func(c *container.Container) error { return c.Stop(ctx, timeout) }) }
[ "func", "(", "s", "*", "Service", ")", "Stop", "(", "ctx", "context", ".", "Context", ",", "timeout", "int", ")", "error", "{", "timeout", "=", "s", ".", "stopTimeout", "(", "timeout", ")", "\n", "return", "s", ".", "collectContainersAndDo", "(", "ctx", ",", "func", "(", "c", "*", "container", ".", "Container", ")", "error", "{", "return", "c", ".", "Stop", "(", "ctx", ",", "timeout", ")", "\n", "}", ")", "\n", "}" ]
// Stop implements Service.Stop. It stops any containers related to the service.
[ "Stop", "implements", "Service", ".", "Stop", ".", "It", "stops", "any", "containers", "related", "to", "the", "service", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L541-L546
14,319
docker/libcompose
docker/service/service.go
Kill
func (s *Service) Kill(ctx context.Context, signal string) error { return s.collectContainersAndDo(ctx, func(c *container.Container) error { return c.Kill(ctx, signal) }) }
go
func (s *Service) Kill(ctx context.Context, signal string) error { return s.collectContainersAndDo(ctx, func(c *container.Container) error { return c.Kill(ctx, signal) }) }
[ "func", "(", "s", "*", "Service", ")", "Kill", "(", "ctx", "context", ".", "Context", ",", "signal", "string", ")", "error", "{", "return", "s", ".", "collectContainersAndDo", "(", "ctx", ",", "func", "(", "c", "*", "container", ".", "Container", ")", "error", "{", "return", "c", ".", "Kill", "(", "ctx", ",", "signal", ")", "\n", "}", ")", "\n", "}" ]
// Kill implements Service.Kill. It kills any containers related to the service.
[ "Kill", "implements", "Service", ".", "Kill", ".", "It", "kills", "any", "containers", "related", "to", "the", "service", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L557-L561
14,320
docker/libcompose
docker/service/service.go
Delete
func (s *Service) Delete(ctx context.Context, options options.Delete) error { return s.collectContainersAndDo(ctx, func(c *container.Container) error { running := c.IsRunning(ctx) if !running || options.RemoveRunning { return c.Remove(ctx, options.RemoveVolume) } return nil }) }
go
func (s *Service) Delete(ctx context.Context, options options.Delete) error { return s.collectContainersAndDo(ctx, func(c *container.Container) error { running := c.IsRunning(ctx) if !running || options.RemoveRunning { return c.Remove(ctx, options.RemoveVolume) } return nil }) }
[ "func", "(", "s", "*", "Service", ")", "Delete", "(", "ctx", "context", ".", "Context", ",", "options", "options", ".", "Delete", ")", "error", "{", "return", "s", ".", "collectContainersAndDo", "(", "ctx", ",", "func", "(", "c", "*", "container", ".", "Container", ")", "error", "{", "running", ":=", "c", ".", "IsRunning", "(", "ctx", ")", "\n", "if", "!", "running", "||", "options", ".", "RemoveRunning", "{", "return", "c", ".", "Remove", "(", "ctx", ",", "options", ".", "RemoveVolume", ")", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// Delete implements Service.Delete. It removes any containers related to the service.
[ "Delete", "implements", "Service", ".", "Delete", ".", "It", "removes", "any", "containers", "related", "to", "the", "service", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L564-L572
14,321
docker/libcompose
docker/service/service.go
Log
func (s *Service) Log(ctx context.Context, follow bool) error { return s.collectContainersAndDo(ctx, func(c *container.Container) error { containerNumber, err := c.Number() if err != nil { return err } name := fmt.Sprintf("%s_%d", s.name, containerNumber) if s.Config().ContainerName != "" { name = s.Config().ContainerName } l := s.context.LoggerFactory.CreateContainerLogger(name) return c.Log(ctx, l, follow) }) }
go
func (s *Service) Log(ctx context.Context, follow bool) error { return s.collectContainersAndDo(ctx, func(c *container.Container) error { containerNumber, err := c.Number() if err != nil { return err } name := fmt.Sprintf("%s_%d", s.name, containerNumber) if s.Config().ContainerName != "" { name = s.Config().ContainerName } l := s.context.LoggerFactory.CreateContainerLogger(name) return c.Log(ctx, l, follow) }) }
[ "func", "(", "s", "*", "Service", ")", "Log", "(", "ctx", "context", ".", "Context", ",", "follow", "bool", ")", "error", "{", "return", "s", ".", "collectContainersAndDo", "(", "ctx", ",", "func", "(", "c", "*", "container", ".", "Container", ")", "error", "{", "containerNumber", ",", "err", ":=", "c", ".", "Number", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "name", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "name", ",", "containerNumber", ")", "\n", "if", "s", ".", "Config", "(", ")", ".", "ContainerName", "!=", "\"", "\"", "{", "name", "=", "s", ".", "Config", "(", ")", ".", "ContainerName", "\n", "}", "\n", "l", ":=", "s", ".", "context", ".", "LoggerFactory", ".", "CreateContainerLogger", "(", "name", ")", "\n", "return", "c", ".", "Log", "(", "ctx", ",", "l", ",", "follow", ")", "\n", "}", ")", "\n", "}" ]
// Log implements Service.Log. It returns the docker logs for each container related to the service.
[ "Log", "implements", "Service", ".", "Log", ".", "It", "returns", "the", "docker", "logs", "for", "each", "container", "related", "to", "the", "service", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L575-L588
14,322
docker/libcompose
docker/service/service.go
Scale
func (s *Service) Scale(ctx context.Context, scale int, timeout int) error { if s.specificiesHostPort() { logrus.Warnf("The \"%s\" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.", s.Name()) } containers, err := s.collectContainers(ctx) if err != nil { return err } if len(containers) > scale { foundCount := 0 for _, c := range containers { foundCount++ if foundCount > scale { timeout = s.stopTimeout(timeout) if err := c.Stop(ctx, timeout); err != nil { return err } // FIXME(vdemeester) remove volume in scale by default ? if err := c.Remove(ctx, false); err != nil { return err } } } } if err != nil { return err } if len(containers) < scale { err := s.ensureImageExists(ctx, false, false) if err != nil { return err } if _, err = s.constructContainers(ctx, scale); err != nil { return err } } return s.up(ctx, "", false, options.Up{}) }
go
func (s *Service) Scale(ctx context.Context, scale int, timeout int) error { if s.specificiesHostPort() { logrus.Warnf("The \"%s\" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.", s.Name()) } containers, err := s.collectContainers(ctx) if err != nil { return err } if len(containers) > scale { foundCount := 0 for _, c := range containers { foundCount++ if foundCount > scale { timeout = s.stopTimeout(timeout) if err := c.Stop(ctx, timeout); err != nil { return err } // FIXME(vdemeester) remove volume in scale by default ? if err := c.Remove(ctx, false); err != nil { return err } } } } if err != nil { return err } if len(containers) < scale { err := s.ensureImageExists(ctx, false, false) if err != nil { return err } if _, err = s.constructContainers(ctx, scale); err != nil { return err } } return s.up(ctx, "", false, options.Up{}) }
[ "func", "(", "s", "*", "Service", ")", "Scale", "(", "ctx", "context", ".", "Context", ",", "scale", "int", ",", "timeout", "int", ")", "error", "{", "if", "s", ".", "specificiesHostPort", "(", ")", "{", "logrus", ".", "Warnf", "(", "\"", "\\\"", "\\\"", "\"", ",", "s", ".", "Name", "(", ")", ")", "\n", "}", "\n\n", "containers", ",", "err", ":=", "s", ".", "collectContainers", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "len", "(", "containers", ")", ">", "scale", "{", "foundCount", ":=", "0", "\n", "for", "_", ",", "c", ":=", "range", "containers", "{", "foundCount", "++", "\n", "if", "foundCount", ">", "scale", "{", "timeout", "=", "s", ".", "stopTimeout", "(", "timeout", ")", "\n", "if", "err", ":=", "c", ".", "Stop", "(", "ctx", ",", "timeout", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// FIXME(vdemeester) remove volume in scale by default ?", "if", "err", ":=", "c", ".", "Remove", "(", "ctx", ",", "false", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "len", "(", "containers", ")", "<", "scale", "{", "err", ":=", "s", ".", "ensureImageExists", "(", "ctx", ",", "false", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "_", ",", "err", "=", "s", ".", "constructContainers", "(", "ctx", ",", "scale", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "s", ".", "up", "(", "ctx", ",", "\"", "\"", ",", "false", ",", "options", ".", "Up", "{", "}", ")", "\n", "}" ]
// Scale implements Service.Scale. It creates or removes containers to have the specified number // of related container to the service to run.
[ "Scale", "implements", "Service", ".", "Scale", ".", "It", "creates", "or", "removes", "containers", "to", "have", "the", "specified", "number", "of", "related", "container", "to", "the", "service", "to", "run", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L592-L634
14,323
docker/libcompose
docker/service/service.go
Pull
func (s *Service) Pull(ctx context.Context) error { if s.Config().Image == "" { return nil } return image.PullImage(ctx, s.clientFactory.Create(s), s.name, s.authLookup, s.Config().Image) }
go
func (s *Service) Pull(ctx context.Context) error { if s.Config().Image == "" { return nil } return image.PullImage(ctx, s.clientFactory.Create(s), s.name, s.authLookup, s.Config().Image) }
[ "func", "(", "s", "*", "Service", ")", "Pull", "(", "ctx", "context", ".", "Context", ")", "error", "{", "if", "s", ".", "Config", "(", ")", ".", "Image", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n\n", "return", "image", ".", "PullImage", "(", "ctx", ",", "s", ".", "clientFactory", ".", "Create", "(", "s", ")", ",", "s", ".", "name", ",", "s", ".", "authLookup", ",", "s", ".", "Config", "(", ")", ".", "Image", ")", "\n", "}" ]
// Pull implements Service.Pull. It pulls the image of the service and skip the service that // would need to be built.
[ "Pull", "implements", "Service", ".", "Pull", ".", "It", "pulls", "the", "image", "of", "the", "service", "and", "skip", "the", "service", "that", "would", "need", "to", "be", "built", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L638-L644
14,324
docker/libcompose
docker/service/service.go
RemoveImage
func (s *Service) RemoveImage(ctx context.Context, imageType options.ImageType) error { switch imageType { case "local": if s.Config().Image != "" { return nil } return image.RemoveImage(ctx, s.clientFactory.Create(s), s.imageName()) case "all": return image.RemoveImage(ctx, s.clientFactory.Create(s), s.imageName()) default: // Don't do a thing, should be validated up-front return nil } }
go
func (s *Service) RemoveImage(ctx context.Context, imageType options.ImageType) error { switch imageType { case "local": if s.Config().Image != "" { return nil } return image.RemoveImage(ctx, s.clientFactory.Create(s), s.imageName()) case "all": return image.RemoveImage(ctx, s.clientFactory.Create(s), s.imageName()) default: // Don't do a thing, should be validated up-front return nil } }
[ "func", "(", "s", "*", "Service", ")", "RemoveImage", "(", "ctx", "context", ".", "Context", ",", "imageType", "options", ".", "ImageType", ")", "error", "{", "switch", "imageType", "{", "case", "\"", "\"", ":", "if", "s", ".", "Config", "(", ")", ".", "Image", "!=", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "return", "image", ".", "RemoveImage", "(", "ctx", ",", "s", ".", "clientFactory", ".", "Create", "(", "s", ")", ",", "s", ".", "imageName", "(", ")", ")", "\n", "case", "\"", "\"", ":", "return", "image", ".", "RemoveImage", "(", "ctx", ",", "s", ".", "clientFactory", ".", "Create", "(", "s", ")", ",", "s", ".", "imageName", "(", ")", ")", "\n", "default", ":", "// Don't do a thing, should be validated up-front", "return", "nil", "\n", "}", "\n", "}" ]
// RemoveImage implements Service.RemoveImage. It removes images used for the service // depending on the specified type.
[ "RemoveImage", "implements", "Service", ".", "RemoveImage", ".", "It", "removes", "images", "used", "for", "the", "service", "depending", "on", "the", "specified", "type", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L664-L677
14,325
docker/libcompose
docker/service/service.go
Events
func (s *Service) Events(ctx context.Context, evts chan events.ContainerEvent) error { filter := filters.NewArgs() filter.Add("label", fmt.Sprintf("%s=%s", labels.PROJECT, s.project.Name)) filter.Add("label", fmt.Sprintf("%s=%s", labels.SERVICE, s.name)) client := s.clientFactory.Create(s) eventq, errq := client.Events(ctx, types.EventsOptions{ Filters: filter, }) go func() { for { select { case event := <-eventq: service := event.Actor.Attributes[labels.SERVICE.Str()] attributes := map[string]string{} for _, attr := range eventAttributes { attributes[attr] = event.Actor.Attributes[attr] } e := events.ContainerEvent{ Service: service, Event: event.Action, Type: event.Type, ID: event.Actor.ID, Time: time.Unix(event.Time, 0), Attributes: attributes, } evts <- e } } }() return <-errq }
go
func (s *Service) Events(ctx context.Context, evts chan events.ContainerEvent) error { filter := filters.NewArgs() filter.Add("label", fmt.Sprintf("%s=%s", labels.PROJECT, s.project.Name)) filter.Add("label", fmt.Sprintf("%s=%s", labels.SERVICE, s.name)) client := s.clientFactory.Create(s) eventq, errq := client.Events(ctx, types.EventsOptions{ Filters: filter, }) go func() { for { select { case event := <-eventq: service := event.Actor.Attributes[labels.SERVICE.Str()] attributes := map[string]string{} for _, attr := range eventAttributes { attributes[attr] = event.Actor.Attributes[attr] } e := events.ContainerEvent{ Service: service, Event: event.Action, Type: event.Type, ID: event.Actor.ID, Time: time.Unix(event.Time, 0), Attributes: attributes, } evts <- e } } }() return <-errq }
[ "func", "(", "s", "*", "Service", ")", "Events", "(", "ctx", "context", ".", "Context", ",", "evts", "chan", "events", ".", "ContainerEvent", ")", "error", "{", "filter", ":=", "filters", ".", "NewArgs", "(", ")", "\n", "filter", ".", "Add", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "labels", ".", "PROJECT", ",", "s", ".", "project", ".", "Name", ")", ")", "\n", "filter", ".", "Add", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "labels", ".", "SERVICE", ",", "s", ".", "name", ")", ")", "\n", "client", ":=", "s", ".", "clientFactory", ".", "Create", "(", "s", ")", "\n", "eventq", ",", "errq", ":=", "client", ".", "Events", "(", "ctx", ",", "types", ".", "EventsOptions", "{", "Filters", ":", "filter", ",", "}", ")", "\n", "go", "func", "(", ")", "{", "for", "{", "select", "{", "case", "event", ":=", "<-", "eventq", ":", "service", ":=", "event", ".", "Actor", ".", "Attributes", "[", "labels", ".", "SERVICE", ".", "Str", "(", ")", "]", "\n", "attributes", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "for", "_", ",", "attr", ":=", "range", "eventAttributes", "{", "attributes", "[", "attr", "]", "=", "event", ".", "Actor", ".", "Attributes", "[", "attr", "]", "\n", "}", "\n", "e", ":=", "events", ".", "ContainerEvent", "{", "Service", ":", "service", ",", "Event", ":", "event", ".", "Action", ",", "Type", ":", "event", ".", "Type", ",", "ID", ":", "event", ".", "Actor", ".", "ID", ",", "Time", ":", "time", ".", "Unix", "(", "event", ".", "Time", ",", "0", ")", ",", "Attributes", ":", "attributes", ",", "}", "\n", "evts", "<-", "e", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n", "return", "<-", "errq", "\n", "}" ]
// Events implements Service.Events. It listen to all real-time events happening // for the service, and put them into the specified chan.
[ "Events", "implements", "Service", ".", "Events", ".", "It", "listen", "to", "all", "real", "-", "time", "events", "happening", "for", "the", "service", "and", "put", "them", "into", "the", "specified", "chan", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L683-L713
14,326
docker/libcompose
docker/service/service.go
Containers
func (s *Service) Containers(ctx context.Context) ([]project.Container, error) { result := []project.Container{} containers, err := s.collectContainers(ctx) if err != nil { return nil, err } for _, c := range containers { result = append(result, c) } return result, nil }
go
func (s *Service) Containers(ctx context.Context) ([]project.Container, error) { result := []project.Container{} containers, err := s.collectContainers(ctx) if err != nil { return nil, err } for _, c := range containers { result = append(result, c) } return result, nil }
[ "func", "(", "s", "*", "Service", ")", "Containers", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "project", ".", "Container", ",", "error", ")", "{", "result", ":=", "[", "]", "project", ".", "Container", "{", "}", "\n", "containers", ",", "err", ":=", "s", ".", "collectContainers", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "_", ",", "c", ":=", "range", "containers", "{", "result", "=", "append", "(", "result", ",", "c", ")", "\n", "}", "\n\n", "return", "result", ",", "nil", "\n", "}" ]
// Containers implements Service.Containers. It returns the list of containers // that are related to the service.
[ "Containers", "implements", "Service", ".", "Containers", ".", "It", "returns", "the", "list", "of", "containers", "that", "are", "related", "to", "the", "service", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L717-L729
14,327
docker/libcompose
docker/service/service.go
stopTimeout
func (s *Service) stopTimeout(timeout int) int { DEFAULTTIMEOUT := 10 if timeout != 0 { return timeout } configTimeout := utils.DurationStrToSecondsInt(s.Config().StopGracePeriod) if configTimeout != nil { return *configTimeout } return DEFAULTTIMEOUT }
go
func (s *Service) stopTimeout(timeout int) int { DEFAULTTIMEOUT := 10 if timeout != 0 { return timeout } configTimeout := utils.DurationStrToSecondsInt(s.Config().StopGracePeriod) if configTimeout != nil { return *configTimeout } return DEFAULTTIMEOUT }
[ "func", "(", "s", "*", "Service", ")", "stopTimeout", "(", "timeout", "int", ")", "int", "{", "DEFAULTTIMEOUT", ":=", "10", "\n", "if", "timeout", "!=", "0", "{", "return", "timeout", "\n", "}", "\n", "configTimeout", ":=", "utils", ".", "DurationStrToSecondsInt", "(", "s", ".", "Config", "(", ")", ".", "StopGracePeriod", ")", "\n", "if", "configTimeout", "!=", "nil", "{", "return", "*", "configTimeout", "\n", "}", "\n", "return", "DEFAULTTIMEOUT", "\n", "}" ]
//take in timeout flag from cli as parameter //return timeout if it is set, //else return stop_grace_period if it is set, //else return default 10s
[ "take", "in", "timeout", "flag", "from", "cli", "as", "parameter", "return", "timeout", "if", "it", "is", "set", "else", "return", "stop_grace_period", "if", "it", "is", "set", "else", "return", "default", "10s" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/service.go#L753-L763
14,328
docker/libcompose
config/schema_helpers.go
parseValidTypesFromSchema
func parseValidTypesFromSchema(schema map[string]interface{}, context string) []string { contextSplit := strings.Split(context, ".") key := contextSplit[len(contextSplit)-1] definitions := schema["definitions"].(map[string]interface{}) service := definitions["service"].(map[string]interface{}) properties := service["properties"].(map[string]interface{}) property := properties[key].(map[string]interface{}) var validTypes []string if val, ok := property["oneOf"]; ok { validConditions := val.([]interface{}) for _, validCondition := range validConditions { condition := validCondition.(map[string]interface{}) validTypes = append(validTypes, condition["type"].(string)) } } else if val, ok := property["$ref"]; ok { reference := val.(string) if reference == "#/definitions/string_or_list" { return []string{"string", "array"} } else if reference == "#/definitions/list_of_strings" { return []string{"array"} } else if reference == "#/definitions/list_or_dict" { return []string{"array", "object"} } } return validTypes }
go
func parseValidTypesFromSchema(schema map[string]interface{}, context string) []string { contextSplit := strings.Split(context, ".") key := contextSplit[len(contextSplit)-1] definitions := schema["definitions"].(map[string]interface{}) service := definitions["service"].(map[string]interface{}) properties := service["properties"].(map[string]interface{}) property := properties[key].(map[string]interface{}) var validTypes []string if val, ok := property["oneOf"]; ok { validConditions := val.([]interface{}) for _, validCondition := range validConditions { condition := validCondition.(map[string]interface{}) validTypes = append(validTypes, condition["type"].(string)) } } else if val, ok := property["$ref"]; ok { reference := val.(string) if reference == "#/definitions/string_or_list" { return []string{"string", "array"} } else if reference == "#/definitions/list_of_strings" { return []string{"array"} } else if reference == "#/definitions/list_or_dict" { return []string{"array", "object"} } } return validTypes }
[ "func", "parseValidTypesFromSchema", "(", "schema", "map", "[", "string", "]", "interface", "{", "}", ",", "context", "string", ")", "[", "]", "string", "{", "contextSplit", ":=", "strings", ".", "Split", "(", "context", ",", "\"", "\"", ")", "\n", "key", ":=", "contextSplit", "[", "len", "(", "contextSplit", ")", "-", "1", "]", "\n\n", "definitions", ":=", "schema", "[", "\"", "\"", "]", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "service", ":=", "definitions", "[", "\"", "\"", "]", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "properties", ":=", "service", "[", "\"", "\"", "]", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "property", ":=", "properties", "[", "key", "]", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n\n", "var", "validTypes", "[", "]", "string", "\n\n", "if", "val", ",", "ok", ":=", "property", "[", "\"", "\"", "]", ";", "ok", "{", "validConditions", ":=", "val", ".", "(", "[", "]", "interface", "{", "}", ")", "\n\n", "for", "_", ",", "validCondition", ":=", "range", "validConditions", "{", "condition", ":=", "validCondition", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "validTypes", "=", "append", "(", "validTypes", ",", "condition", "[", "\"", "\"", "]", ".", "(", "string", ")", ")", "\n", "}", "\n", "}", "else", "if", "val", ",", "ok", ":=", "property", "[", "\"", "\"", "]", ";", "ok", "{", "reference", ":=", "val", ".", "(", "string", ")", "\n", "if", "reference", "==", "\"", "\"", "{", "return", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "\n", "}", "else", "if", "reference", "==", "\"", "\"", "{", "return", "[", "]", "string", "{", "\"", "\"", "}", "\n", "}", "else", "if", "reference", "==", "\"", "\"", "{", "return", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "\n", "}", "\n", "}", "\n\n", "return", "validTypes", "\n", "}" ]
// gojsonschema doesn't provide a list of valid types for a property // This parses the schema manually to find all valid types
[ "gojsonschema", "doesn", "t", "provide", "a", "list", "of", "valid", "types", "for", "a", "property", "This", "parses", "the", "schema", "manually", "to", "find", "all", "valid", "types" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/config/schema_helpers.go#L75-L105
14,329
docker/libcompose
labels/labels.go
EqString
func (f Label) EqString(value string) string { return LabelFilterString(string(f), value) }
go
func (f Label) EqString(value string) string { return LabelFilterString(string(f), value) }
[ "func", "(", "f", "Label", ")", "EqString", "(", "value", "string", ")", "string", "{", "return", "LabelFilterString", "(", "string", "(", "f", ")", ",", "value", ")", "\n", "}" ]
// EqString returns a label json string representation with the specified value.
[ "EqString", "returns", "a", "label", "json", "string", "representation", "with", "the", "specified", "value", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/labels/labels.go#L24-L26
14,330
docker/libcompose
labels/labels.go
Eq
func (f Label) Eq(value string) map[string][]string { return LabelFilter(string(f), value) }
go
func (f Label) Eq(value string) map[string][]string { return LabelFilter(string(f), value) }
[ "func", "(", "f", "Label", ")", "Eq", "(", "value", "string", ")", "map", "[", "string", "]", "[", "]", "string", "{", "return", "LabelFilter", "(", "string", "(", "f", ")", ",", "value", ")", "\n", "}" ]
// Eq returns a label map representation with the specified value.
[ "Eq", "returns", "a", "label", "map", "representation", "with", "the", "specified", "value", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/labels/labels.go#L29-L31
14,331
docker/libcompose
yaml/ulimit.go
NewUlimit
func NewUlimit(name string, soft int64, hard int64) Ulimit { return Ulimit{ Name: name, ulimitValues: ulimitValues{ Soft: soft, Hard: hard, }, } }
go
func NewUlimit(name string, soft int64, hard int64) Ulimit { return Ulimit{ Name: name, ulimitValues: ulimitValues{ Soft: soft, Hard: hard, }, } }
[ "func", "NewUlimit", "(", "name", "string", ",", "soft", "int64", ",", "hard", "int64", ")", "Ulimit", "{", "return", "Ulimit", "{", "Name", ":", "name", ",", "ulimitValues", ":", "ulimitValues", "{", "Soft", ":", "soft", ",", "Hard", ":", "hard", ",", "}", ",", "}", "\n", "}" ]
// NewUlimit creates a Ulimit based on the specified parts.
[ "NewUlimit", "creates", "a", "Ulimit", "based", "on", "the", "specified", "parts", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/yaml/ulimit.go#L100-L108
14,332
docker/libcompose
yaml/build.go
handleBuildOptionMap
func handleBuildOptionMap(m map[interface{}]interface{}) (map[string]*string, error) { args := map[string]*string{} for mapKey, mapValue := range m { var argValue string name, ok := mapKey.(string) if !ok { return args, fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", name, name) } switch a := mapValue.(type) { case string: argValue = a case int: argValue = strconv.Itoa(a) case int64: argValue = strconv.Itoa(int(a)) default: return args, fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", mapValue, mapValue) } args[name] = &argValue } return args, nil }
go
func handleBuildOptionMap(m map[interface{}]interface{}) (map[string]*string, error) { args := map[string]*string{} for mapKey, mapValue := range m { var argValue string name, ok := mapKey.(string) if !ok { return args, fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", name, name) } switch a := mapValue.(type) { case string: argValue = a case int: argValue = strconv.Itoa(a) case int64: argValue = strconv.Itoa(int(a)) default: return args, fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", mapValue, mapValue) } args[name] = &argValue } return args, nil }
[ "func", "handleBuildOptionMap", "(", "m", "map", "[", "interface", "{", "}", "]", "interface", "{", "}", ")", "(", "map", "[", "string", "]", "*", "string", ",", "error", ")", "{", "args", ":=", "map", "[", "string", "]", "*", "string", "{", "}", "\n", "for", "mapKey", ",", "mapValue", ":=", "range", "m", "{", "var", "argValue", "string", "\n", "name", ",", "ok", ":=", "mapKey", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "return", "args", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ",", "name", ")", "\n", "}", "\n", "switch", "a", ":=", "mapValue", ".", "(", "type", ")", "{", "case", "string", ":", "argValue", "=", "a", "\n", "case", "int", ":", "argValue", "=", "strconv", ".", "Itoa", "(", "a", ")", "\n", "case", "int64", ":", "argValue", "=", "strconv", ".", "Itoa", "(", "int", "(", "a", ")", ")", "\n", "default", ":", "return", "args", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "mapValue", ",", "mapValue", ")", "\n", "}", "\n", "args", "[", "name", "]", "=", "&", "argValue", "\n", "}", "\n", "return", "args", ",", "nil", "\n", "}" ]
// Used for args and labels
[ "Used", "for", "args", "and", "labels" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/yaml/build.go#L160-L181
14,333
docker/libcompose
config/convert.go
ConvertServices
func ConvertServices(v1Services map[string]*ServiceConfigV1) (map[string]*ServiceConfig, error) { v2Services := make(map[string]*ServiceConfig) replacementFields := make(map[string]*ServiceConfig) for name, service := range v1Services { replacementFields[name] = &ServiceConfig{ Build: yaml.Build{ Context: service.Build, Dockerfile: service.Dockerfile, }, Logging: Log{ Driver: service.LogDriver, Options: service.LogOpt, }, NetworkMode: service.Net, } v1Services[name].Build = "" v1Services[name].Dockerfile = "" v1Services[name].LogDriver = "" v1Services[name].LogOpt = nil v1Services[name].Net = "" } if err := utils.Convert(v1Services, &v2Services); err != nil { return nil, err } for name := range v2Services { v2Services[name].Build = replacementFields[name].Build v2Services[name].Logging = replacementFields[name].Logging v2Services[name].NetworkMode = replacementFields[name].NetworkMode } return v2Services, nil }
go
func ConvertServices(v1Services map[string]*ServiceConfigV1) (map[string]*ServiceConfig, error) { v2Services := make(map[string]*ServiceConfig) replacementFields := make(map[string]*ServiceConfig) for name, service := range v1Services { replacementFields[name] = &ServiceConfig{ Build: yaml.Build{ Context: service.Build, Dockerfile: service.Dockerfile, }, Logging: Log{ Driver: service.LogDriver, Options: service.LogOpt, }, NetworkMode: service.Net, } v1Services[name].Build = "" v1Services[name].Dockerfile = "" v1Services[name].LogDriver = "" v1Services[name].LogOpt = nil v1Services[name].Net = "" } if err := utils.Convert(v1Services, &v2Services); err != nil { return nil, err } for name := range v2Services { v2Services[name].Build = replacementFields[name].Build v2Services[name].Logging = replacementFields[name].Logging v2Services[name].NetworkMode = replacementFields[name].NetworkMode } return v2Services, nil }
[ "func", "ConvertServices", "(", "v1Services", "map", "[", "string", "]", "*", "ServiceConfigV1", ")", "(", "map", "[", "string", "]", "*", "ServiceConfig", ",", "error", ")", "{", "v2Services", ":=", "make", "(", "map", "[", "string", "]", "*", "ServiceConfig", ")", "\n", "replacementFields", ":=", "make", "(", "map", "[", "string", "]", "*", "ServiceConfig", ")", "\n\n", "for", "name", ",", "service", ":=", "range", "v1Services", "{", "replacementFields", "[", "name", "]", "=", "&", "ServiceConfig", "{", "Build", ":", "yaml", ".", "Build", "{", "Context", ":", "service", ".", "Build", ",", "Dockerfile", ":", "service", ".", "Dockerfile", ",", "}", ",", "Logging", ":", "Log", "{", "Driver", ":", "service", ".", "LogDriver", ",", "Options", ":", "service", ".", "LogOpt", ",", "}", ",", "NetworkMode", ":", "service", ".", "Net", ",", "}", "\n\n", "v1Services", "[", "name", "]", ".", "Build", "=", "\"", "\"", "\n", "v1Services", "[", "name", "]", ".", "Dockerfile", "=", "\"", "\"", "\n", "v1Services", "[", "name", "]", ".", "LogDriver", "=", "\"", "\"", "\n", "v1Services", "[", "name", "]", ".", "LogOpt", "=", "nil", "\n", "v1Services", "[", "name", "]", ".", "Net", "=", "\"", "\"", "\n", "}", "\n\n", "if", "err", ":=", "utils", ".", "Convert", "(", "v1Services", ",", "&", "v2Services", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "name", ":=", "range", "v2Services", "{", "v2Services", "[", "name", "]", ".", "Build", "=", "replacementFields", "[", "name", "]", ".", "Build", "\n", "v2Services", "[", "name", "]", ".", "Logging", "=", "replacementFields", "[", "name", "]", ".", "Logging", "\n", "v2Services", "[", "name", "]", ".", "NetworkMode", "=", "replacementFields", "[", "name", "]", ".", "NetworkMode", "\n", "}", "\n\n", "return", "v2Services", ",", "nil", "\n", "}" ]
// ConvertServices converts a set of v1 service configs to v2 service configs
[ "ConvertServices", "converts", "a", "set", "of", "v1", "service", "configs", "to", "v2", "service", "configs" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/config/convert.go#L9-L44
14,334
docker/libcompose
docker/builder/builder.go
Build
func (d *DaemonBuilder) Build(ctx context.Context, imageName string) error { buildCtx, err := CreateTar(d.ContextDirectory, d.Dockerfile) if err != nil { return err } defer buildCtx.Close() if d.LoggerFactory == nil { d.LoggerFactory = &logger.NullLogger{} } l := d.LoggerFactory.CreateBuildLogger(imageName) progBuff := &logger.Wrapper{ Err: false, Logger: l, } buildBuff := &logger.Wrapper{ Err: false, Logger: l, } errBuff := &logger.Wrapper{ Err: true, Logger: l, } // Setup an upload progress bar progressOutput := streamformatter.NewProgressOutput(progBuff) var body io.Reader = progress.NewProgressReader(buildCtx, progressOutput, 0, "", "Sending build context to Docker daemon") logrus.Infof("Building %s...", imageName) outFd, isTerminalOut := term.GetFdInfo(os.Stdout) w := l.OutWriter() if w != nil { outFd, isTerminalOut = term.GetFdInfo(w) } // Convert map[string]*string to map[string]string labels := make(map[string]string) for lk, lv := range d.Labels { labels[lk] = *lv } response, err := d.Client.ImageBuild(ctx, body, types.ImageBuildOptions{ Tags: []string{imageName}, NoCache: d.NoCache, Remove: true, ForceRemove: d.ForceRemove, PullParent: d.Pull, Dockerfile: d.Dockerfile, AuthConfigs: d.AuthConfigs, BuildArgs: d.BuildArgs, CacheFrom: d.CacheFrom, Labels: labels, NetworkMode: d.Network, Target: d.Target, }) if err != nil { return err } err = jsonmessage.DisplayJSONMessagesStream(response.Body, buildBuff, outFd, isTerminalOut, nil) if err != nil { if jerr, ok := err.(*jsonmessage.JSONError); ok { // If no error code is set, default to 1 if jerr.Code == 0 { jerr.Code = 1 } errBuff.Write([]byte(jerr.Error())) return fmt.Errorf("Status: %s, Code: %d", jerr.Message, jerr.Code) } } return err }
go
func (d *DaemonBuilder) Build(ctx context.Context, imageName string) error { buildCtx, err := CreateTar(d.ContextDirectory, d.Dockerfile) if err != nil { return err } defer buildCtx.Close() if d.LoggerFactory == nil { d.LoggerFactory = &logger.NullLogger{} } l := d.LoggerFactory.CreateBuildLogger(imageName) progBuff := &logger.Wrapper{ Err: false, Logger: l, } buildBuff := &logger.Wrapper{ Err: false, Logger: l, } errBuff := &logger.Wrapper{ Err: true, Logger: l, } // Setup an upload progress bar progressOutput := streamformatter.NewProgressOutput(progBuff) var body io.Reader = progress.NewProgressReader(buildCtx, progressOutput, 0, "", "Sending build context to Docker daemon") logrus.Infof("Building %s...", imageName) outFd, isTerminalOut := term.GetFdInfo(os.Stdout) w := l.OutWriter() if w != nil { outFd, isTerminalOut = term.GetFdInfo(w) } // Convert map[string]*string to map[string]string labels := make(map[string]string) for lk, lv := range d.Labels { labels[lk] = *lv } response, err := d.Client.ImageBuild(ctx, body, types.ImageBuildOptions{ Tags: []string{imageName}, NoCache: d.NoCache, Remove: true, ForceRemove: d.ForceRemove, PullParent: d.Pull, Dockerfile: d.Dockerfile, AuthConfigs: d.AuthConfigs, BuildArgs: d.BuildArgs, CacheFrom: d.CacheFrom, Labels: labels, NetworkMode: d.Network, Target: d.Target, }) if err != nil { return err } err = jsonmessage.DisplayJSONMessagesStream(response.Body, buildBuff, outFd, isTerminalOut, nil) if err != nil { if jerr, ok := err.(*jsonmessage.JSONError); ok { // If no error code is set, default to 1 if jerr.Code == 0 { jerr.Code = 1 } errBuff.Write([]byte(jerr.Error())) return fmt.Errorf("Status: %s, Code: %d", jerr.Message, jerr.Code) } } return err }
[ "func", "(", "d", "*", "DaemonBuilder", ")", "Build", "(", "ctx", "context", ".", "Context", ",", "imageName", "string", ")", "error", "{", "buildCtx", ",", "err", ":=", "CreateTar", "(", "d", ".", "ContextDirectory", ",", "d", ".", "Dockerfile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "buildCtx", ".", "Close", "(", ")", "\n", "if", "d", ".", "LoggerFactory", "==", "nil", "{", "d", ".", "LoggerFactory", "=", "&", "logger", ".", "NullLogger", "{", "}", "\n", "}", "\n\n", "l", ":=", "d", ".", "LoggerFactory", ".", "CreateBuildLogger", "(", "imageName", ")", "\n\n", "progBuff", ":=", "&", "logger", ".", "Wrapper", "{", "Err", ":", "false", ",", "Logger", ":", "l", ",", "}", "\n\n", "buildBuff", ":=", "&", "logger", ".", "Wrapper", "{", "Err", ":", "false", ",", "Logger", ":", "l", ",", "}", "\n\n", "errBuff", ":=", "&", "logger", ".", "Wrapper", "{", "Err", ":", "true", ",", "Logger", ":", "l", ",", "}", "\n\n", "// Setup an upload progress bar", "progressOutput", ":=", "streamformatter", ".", "NewProgressOutput", "(", "progBuff", ")", "\n\n", "var", "body", "io", ".", "Reader", "=", "progress", ".", "NewProgressReader", "(", "buildCtx", ",", "progressOutput", ",", "0", ",", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "imageName", ")", "\n\n", "outFd", ",", "isTerminalOut", ":=", "term", ".", "GetFdInfo", "(", "os", ".", "Stdout", ")", "\n", "w", ":=", "l", ".", "OutWriter", "(", ")", "\n", "if", "w", "!=", "nil", "{", "outFd", ",", "isTerminalOut", "=", "term", ".", "GetFdInfo", "(", "w", ")", "\n", "}", "\n\n", "// Convert map[string]*string to map[string]string", "labels", ":=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "for", "lk", ",", "lv", ":=", "range", "d", ".", "Labels", "{", "labels", "[", "lk", "]", "=", "*", "lv", "\n", "}", "\n\n", "response", ",", "err", ":=", "d", ".", "Client", ".", "ImageBuild", "(", "ctx", ",", "body", ",", "types", ".", "ImageBuildOptions", "{", "Tags", ":", "[", "]", "string", "{", "imageName", "}", ",", "NoCache", ":", "d", ".", "NoCache", ",", "Remove", ":", "true", ",", "ForceRemove", ":", "d", ".", "ForceRemove", ",", "PullParent", ":", "d", ".", "Pull", ",", "Dockerfile", ":", "d", ".", "Dockerfile", ",", "AuthConfigs", ":", "d", ".", "AuthConfigs", ",", "BuildArgs", ":", "d", ".", "BuildArgs", ",", "CacheFrom", ":", "d", ".", "CacheFrom", ",", "Labels", ":", "labels", ",", "NetworkMode", ":", "d", ".", "Network", ",", "Target", ":", "d", ".", "Target", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "err", "=", "jsonmessage", ".", "DisplayJSONMessagesStream", "(", "response", ".", "Body", ",", "buildBuff", ",", "outFd", ",", "isTerminalOut", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "if", "jerr", ",", "ok", ":=", "err", ".", "(", "*", "jsonmessage", ".", "JSONError", ")", ";", "ok", "{", "// If no error code is set, default to 1", "if", "jerr", ".", "Code", "==", "0", "{", "jerr", ".", "Code", "=", "1", "\n", "}", "\n", "errBuff", ".", "Write", "(", "[", "]", "byte", "(", "jerr", ".", "Error", "(", ")", ")", ")", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "jerr", ".", "Message", ",", "jerr", ".", "Code", ")", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// Build implements Builder. It consumes the docker build API endpoint and sends // a tar of the specified service build context.
[ "Build", "implements", "Builder", ".", "It", "consumes", "the", "docker", "build", "API", "endpoint", "and", "sends", "a", "tar", "of", "the", "specified", "service", "build", "context", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/builder/builder.go#L54-L130
14,335
docker/libcompose
docker/builder/builder.go
CreateTar
func CreateTar(contextDirectory, dockerfile string) (io.ReadCloser, error) { // This code was ripped off from docker/api/client/build.go dockerfileName := filepath.Join(contextDirectory, dockerfile) absContextDirectory, err := filepath.Abs(contextDirectory) if err != nil { return nil, err } filename := dockerfileName if dockerfile == "" { // No -f/--file was specified so use the default dockerfileName = DefaultDockerfileName filename = filepath.Join(absContextDirectory, dockerfileName) // Just to be nice ;-) look for 'dockerfile' too but only // use it if we found it, otherwise ignore this check if _, err = os.Lstat(filename); os.IsNotExist(err) { tmpFN := path.Join(absContextDirectory, strings.ToLower(dockerfileName)) if _, err = os.Lstat(tmpFN); err == nil { dockerfileName = strings.ToLower(dockerfileName) filename = tmpFN } } } origDockerfile := dockerfileName // used for error msg if filename, err = filepath.Abs(filename); err != nil { return nil, err } // Now reset the dockerfileName to be relative to the build context dockerfileName, err = filepath.Rel(absContextDirectory, filename) if err != nil { return nil, err } // And canonicalize dockerfile name to a platform-independent one dockerfileName, err = archive.CanonicalTarNameForPath(dockerfileName) if err != nil { return nil, fmt.Errorf("Cannot canonicalize dockerfile path %s: %v", dockerfileName, err) } if _, err = os.Lstat(filename); os.IsNotExist(err) { return nil, fmt.Errorf("Cannot locate Dockerfile: %s", origDockerfile) } var includes = []string{"."} var excludes []string dockerIgnorePath := path.Join(contextDirectory, ".dockerignore") dockerIgnore, err := os.Open(dockerIgnorePath) if err != nil { if !os.IsNotExist(err) { return nil, err } logrus.Warnf("Error while reading .dockerignore (%s) : %s", dockerIgnorePath, err.Error()) excludes = make([]string, 0) } else { excludes, err = dockerignore.ReadAll(dockerIgnore) if err != nil { return nil, err } } // If .dockerignore mentions .dockerignore or the Dockerfile // then make sure we send both files over to the daemon // because Dockerfile is, obviously, needed no matter what, and // .dockerignore is needed to know if either one needs to be // removed. The deamon will remove them for us, if needed, after it // parses the Dockerfile. keepThem1, _ := fileutils.Matches(".dockerignore", excludes) keepThem2, _ := fileutils.Matches(dockerfileName, excludes) if keepThem1 || keepThem2 { includes = append(includes, ".dockerignore", dockerfileName) } if err := build.ValidateContextDirectory(contextDirectory, excludes); err != nil { return nil, fmt.Errorf("error checking context is accessible: '%s', please check permissions and try again", err) } options := &archive.TarOptions{ Compression: archive.Uncompressed, ExcludePatterns: excludes, IncludeFiles: includes, } return archive.TarWithOptions(contextDirectory, options) }
go
func CreateTar(contextDirectory, dockerfile string) (io.ReadCloser, error) { // This code was ripped off from docker/api/client/build.go dockerfileName := filepath.Join(contextDirectory, dockerfile) absContextDirectory, err := filepath.Abs(contextDirectory) if err != nil { return nil, err } filename := dockerfileName if dockerfile == "" { // No -f/--file was specified so use the default dockerfileName = DefaultDockerfileName filename = filepath.Join(absContextDirectory, dockerfileName) // Just to be nice ;-) look for 'dockerfile' too but only // use it if we found it, otherwise ignore this check if _, err = os.Lstat(filename); os.IsNotExist(err) { tmpFN := path.Join(absContextDirectory, strings.ToLower(dockerfileName)) if _, err = os.Lstat(tmpFN); err == nil { dockerfileName = strings.ToLower(dockerfileName) filename = tmpFN } } } origDockerfile := dockerfileName // used for error msg if filename, err = filepath.Abs(filename); err != nil { return nil, err } // Now reset the dockerfileName to be relative to the build context dockerfileName, err = filepath.Rel(absContextDirectory, filename) if err != nil { return nil, err } // And canonicalize dockerfile name to a platform-independent one dockerfileName, err = archive.CanonicalTarNameForPath(dockerfileName) if err != nil { return nil, fmt.Errorf("Cannot canonicalize dockerfile path %s: %v", dockerfileName, err) } if _, err = os.Lstat(filename); os.IsNotExist(err) { return nil, fmt.Errorf("Cannot locate Dockerfile: %s", origDockerfile) } var includes = []string{"."} var excludes []string dockerIgnorePath := path.Join(contextDirectory, ".dockerignore") dockerIgnore, err := os.Open(dockerIgnorePath) if err != nil { if !os.IsNotExist(err) { return nil, err } logrus.Warnf("Error while reading .dockerignore (%s) : %s", dockerIgnorePath, err.Error()) excludes = make([]string, 0) } else { excludes, err = dockerignore.ReadAll(dockerIgnore) if err != nil { return nil, err } } // If .dockerignore mentions .dockerignore or the Dockerfile // then make sure we send both files over to the daemon // because Dockerfile is, obviously, needed no matter what, and // .dockerignore is needed to know if either one needs to be // removed. The deamon will remove them for us, if needed, after it // parses the Dockerfile. keepThem1, _ := fileutils.Matches(".dockerignore", excludes) keepThem2, _ := fileutils.Matches(dockerfileName, excludes) if keepThem1 || keepThem2 { includes = append(includes, ".dockerignore", dockerfileName) } if err := build.ValidateContextDirectory(contextDirectory, excludes); err != nil { return nil, fmt.Errorf("error checking context is accessible: '%s', please check permissions and try again", err) } options := &archive.TarOptions{ Compression: archive.Uncompressed, ExcludePatterns: excludes, IncludeFiles: includes, } return archive.TarWithOptions(contextDirectory, options) }
[ "func", "CreateTar", "(", "contextDirectory", ",", "dockerfile", "string", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "// This code was ripped off from docker/api/client/build.go", "dockerfileName", ":=", "filepath", ".", "Join", "(", "contextDirectory", ",", "dockerfile", ")", "\n\n", "absContextDirectory", ",", "err", ":=", "filepath", ".", "Abs", "(", "contextDirectory", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "filename", ":=", "dockerfileName", "\n\n", "if", "dockerfile", "==", "\"", "\"", "{", "// No -f/--file was specified so use the default", "dockerfileName", "=", "DefaultDockerfileName", "\n", "filename", "=", "filepath", ".", "Join", "(", "absContextDirectory", ",", "dockerfileName", ")", "\n\n", "// Just to be nice ;-) look for 'dockerfile' too but only", "// use it if we found it, otherwise ignore this check", "if", "_", ",", "err", "=", "os", ".", "Lstat", "(", "filename", ")", ";", "os", ".", "IsNotExist", "(", "err", ")", "{", "tmpFN", ":=", "path", ".", "Join", "(", "absContextDirectory", ",", "strings", ".", "ToLower", "(", "dockerfileName", ")", ")", "\n", "if", "_", ",", "err", "=", "os", ".", "Lstat", "(", "tmpFN", ")", ";", "err", "==", "nil", "{", "dockerfileName", "=", "strings", ".", "ToLower", "(", "dockerfileName", ")", "\n", "filename", "=", "tmpFN", "\n", "}", "\n", "}", "\n", "}", "\n\n", "origDockerfile", ":=", "dockerfileName", "// used for error msg", "\n", "if", "filename", ",", "err", "=", "filepath", ".", "Abs", "(", "filename", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Now reset the dockerfileName to be relative to the build context", "dockerfileName", ",", "err", "=", "filepath", ".", "Rel", "(", "absContextDirectory", ",", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// And canonicalize dockerfile name to a platform-independent one", "dockerfileName", ",", "err", "=", "archive", ".", "CanonicalTarNameForPath", "(", "dockerfileName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dockerfileName", ",", "err", ")", "\n", "}", "\n\n", "if", "_", ",", "err", "=", "os", ".", "Lstat", "(", "filename", ")", ";", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "origDockerfile", ")", "\n", "}", "\n", "var", "includes", "=", "[", "]", "string", "{", "\"", "\"", "}", "\n", "var", "excludes", "[", "]", "string", "\n\n", "dockerIgnorePath", ":=", "path", ".", "Join", "(", "contextDirectory", ",", "\"", "\"", ")", "\n", "dockerIgnore", ",", "err", ":=", "os", ".", "Open", "(", "dockerIgnorePath", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", ",", "err", "\n", "}", "\n", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "dockerIgnorePath", ",", "err", ".", "Error", "(", ")", ")", "\n", "excludes", "=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "}", "else", "{", "excludes", ",", "err", "=", "dockerignore", ".", "ReadAll", "(", "dockerIgnore", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "// If .dockerignore mentions .dockerignore or the Dockerfile", "// then make sure we send both files over to the daemon", "// because Dockerfile is, obviously, needed no matter what, and", "// .dockerignore is needed to know if either one needs to be", "// removed. The deamon will remove them for us, if needed, after it", "// parses the Dockerfile.", "keepThem1", ",", "_", ":=", "fileutils", ".", "Matches", "(", "\"", "\"", ",", "excludes", ")", "\n", "keepThem2", ",", "_", ":=", "fileutils", ".", "Matches", "(", "dockerfileName", ",", "excludes", ")", "\n", "if", "keepThem1", "||", "keepThem2", "{", "includes", "=", "append", "(", "includes", ",", "\"", "\"", ",", "dockerfileName", ")", "\n", "}", "\n\n", "if", "err", ":=", "build", ".", "ValidateContextDirectory", "(", "contextDirectory", ",", "excludes", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "options", ":=", "&", "archive", ".", "TarOptions", "{", "Compression", ":", "archive", ".", "Uncompressed", ",", "ExcludePatterns", ":", "excludes", ",", "IncludeFiles", ":", "includes", ",", "}", "\n\n", "return", "archive", ".", "TarWithOptions", "(", "contextDirectory", ",", "options", ")", "\n", "}" ]
// CreateTar create a build context tar for the specified project and service name.
[ "CreateTar", "create", "a", "build", "context", "tar", "for", "the", "specified", "project", "and", "service", "name", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/builder/builder.go#L133-L221
14,336
docker/libcompose
lookup/composable.go
Lookup
func (l *ComposableEnvLookup) Lookup(key string, config *config.ServiceConfig) []string { result := []string{} for _, lookup := range l.Lookups { env := lookup.Lookup(key, config) if len(env) == 1 { result = env } } return result }
go
func (l *ComposableEnvLookup) Lookup(key string, config *config.ServiceConfig) []string { result := []string{} for _, lookup := range l.Lookups { env := lookup.Lookup(key, config) if len(env) == 1 { result = env } } return result }
[ "func", "(", "l", "*", "ComposableEnvLookup", ")", "Lookup", "(", "key", "string", ",", "config", "*", "config", ".", "ServiceConfig", ")", "[", "]", "string", "{", "result", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "lookup", ":=", "range", "l", ".", "Lookups", "{", "env", ":=", "lookup", ".", "Lookup", "(", "key", ",", "config", ")", "\n", "if", "len", "(", "env", ")", "==", "1", "{", "result", "=", "env", "\n", "}", "\n", "}", "\n", "return", "result", "\n", "}" ]
// Lookup creates a string slice of string containing a "docker-friendly" environment string // in the form of 'key=value'. It loop through the lookups and returns the latest value if // more than one lookup return a result.
[ "Lookup", "creates", "a", "string", "slice", "of", "string", "containing", "a", "docker", "-", "friendly", "environment", "string", "in", "the", "form", "of", "key", "=", "value", ".", "It", "loop", "through", "the", "lookups", "and", "returns", "the", "latest", "value", "if", "more", "than", "one", "lookup", "return", "a", "result", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/lookup/composable.go#L16-L25
14,337
docker/libcompose
logger/raw_logger.go
Err
func (r *RawLogger) Err(message []byte) { fmt.Fprint(os.Stderr, string(message)) }
go
func (r *RawLogger) Err(message []byte) { fmt.Fprint(os.Stderr, string(message)) }
[ "func", "(", "r", "*", "RawLogger", ")", "Err", "(", "message", "[", "]", "byte", ")", "{", "fmt", ".", "Fprint", "(", "os", ".", "Stderr", ",", "string", "(", "message", ")", ")", "\n\n", "}" ]
// Err is a no-op function.
[ "Err", "is", "a", "no", "-", "op", "function", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/logger/raw_logger.go#L20-L23
14,338
docker/libcompose
cli/command/command.go
Populate
func Populate(context *project.Context, c *cli.Context) { // urfave/cli does not distinguish whether the first string in the slice comes from the envvar // or is from a flag. Worse off, it appends the flag values to the envvar value instead of // overriding it. To ensure the multifile envvar case is always handled, the first string // must always be split. It gives a more consistent behavior, then, to split each string in // the slice. for _, v := range c.GlobalStringSlice("file") { context.ComposeFiles = append(context.ComposeFiles, strings.Split(v, string(os.PathListSeparator))...) } if len(context.ComposeFiles) == 0 { context.ComposeFiles = []string{"docker-compose.yml"} if _, err := os.Stat("docker-compose.override.yml"); err == nil { context.ComposeFiles = append(context.ComposeFiles, "docker-compose.override.yml") } } context.ProjectName = c.GlobalString("project-name") }
go
func Populate(context *project.Context, c *cli.Context) { // urfave/cli does not distinguish whether the first string in the slice comes from the envvar // or is from a flag. Worse off, it appends the flag values to the envvar value instead of // overriding it. To ensure the multifile envvar case is always handled, the first string // must always be split. It gives a more consistent behavior, then, to split each string in // the slice. for _, v := range c.GlobalStringSlice("file") { context.ComposeFiles = append(context.ComposeFiles, strings.Split(v, string(os.PathListSeparator))...) } if len(context.ComposeFiles) == 0 { context.ComposeFiles = []string{"docker-compose.yml"} if _, err := os.Stat("docker-compose.override.yml"); err == nil { context.ComposeFiles = append(context.ComposeFiles, "docker-compose.override.yml") } } context.ProjectName = c.GlobalString("project-name") }
[ "func", "Populate", "(", "context", "*", "project", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "{", "// urfave/cli does not distinguish whether the first string in the slice comes from the envvar", "// or is from a flag. Worse off, it appends the flag values to the envvar value instead of", "// overriding it. To ensure the multifile envvar case is always handled, the first string", "// must always be split. It gives a more consistent behavior, then, to split each string in", "// the slice.", "for", "_", ",", "v", ":=", "range", "c", ".", "GlobalStringSlice", "(", "\"", "\"", ")", "{", "context", ".", "ComposeFiles", "=", "append", "(", "context", ".", "ComposeFiles", ",", "strings", ".", "Split", "(", "v", ",", "string", "(", "os", ".", "PathListSeparator", ")", ")", "...", ")", "\n", "}", "\n\n", "if", "len", "(", "context", ".", "ComposeFiles", ")", "==", "0", "{", "context", ".", "ComposeFiles", "=", "[", "]", "string", "{", "\"", "\"", "}", "\n", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "\"", "\"", ")", ";", "err", "==", "nil", "{", "context", ".", "ComposeFiles", "=", "append", "(", "context", ".", "ComposeFiles", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "context", ".", "ProjectName", "=", "c", ".", "GlobalString", "(", "\"", "\"", ")", "\n", "}" ]
// Populate updates the specified project context based on command line arguments and subcommands.
[ "Populate", "updates", "the", "specified", "project", "context", "based", "on", "command", "line", "arguments", "and", "subcommands", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L13-L31
14,339
docker/libcompose
cli/command/command.go
CreateCommand
func CreateCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "create", Usage: "Create all services but do not start", Action: app.WithProject(factory, app.ProjectCreate), Flags: []cli.Flag{ cli.BoolFlag{ Name: "no-recreate", Usage: "If containers already exist, don't recreate them. Incompatible with --force-recreate.", }, cli.BoolFlag{ Name: "force-recreate", Usage: "Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.", }, cli.BoolFlag{ Name: "no-build", Usage: "Don't build an image, even if it's missing.", }, }, } }
go
func CreateCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "create", Usage: "Create all services but do not start", Action: app.WithProject(factory, app.ProjectCreate), Flags: []cli.Flag{ cli.BoolFlag{ Name: "no-recreate", Usage: "If containers already exist, don't recreate them. Incompatible with --force-recreate.", }, cli.BoolFlag{ Name: "force-recreate", Usage: "Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.", }, cli.BoolFlag{ Name: "no-build", Usage: "Don't build an image, even if it's missing.", }, }, } }
[ "func", "CreateCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectCreate", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// CreateCommand defines the libcompose create subcommand.
[ "CreateCommand", "defines", "the", "libcompose", "create", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L34-L54
14,340
docker/libcompose
cli/command/command.go
ConfigCommand
func ConfigCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "config", Usage: "Validate and view the compose file.", Action: app.WithProject(factory, app.ProjectConfig), Flags: []cli.Flag{ cli.BoolFlag{ Name: "quiet,q", Usage: "Only validate the configuration, don't print anything.", }, }, } }
go
func ConfigCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "config", Usage: "Validate and view the compose file.", Action: app.WithProject(factory, app.ProjectConfig), Flags: []cli.Flag{ cli.BoolFlag{ Name: "quiet,q", Usage: "Only validate the configuration, don't print anything.", }, }, } }
[ "func", "ConfigCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectConfig", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// ConfigCommand defines the libcompose config subcommand
[ "ConfigCommand", "defines", "the", "libcompose", "config", "subcommand" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L57-L69
14,341
docker/libcompose
cli/command/command.go
BuildCommand
func BuildCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "build", Usage: "Build or rebuild services.", Action: app.WithProject(factory, app.ProjectBuild), Flags: []cli.Flag{ cli.BoolFlag{ Name: "no-cache", Usage: "Do not use cache when building the image", }, cli.BoolFlag{ Name: "force-rm", Usage: "Always remove intermediate containers", }, cli.BoolFlag{ Name: "pull", Usage: "Always attempt to pull a newer version of the image", }, }, } }
go
func BuildCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "build", Usage: "Build or rebuild services.", Action: app.WithProject(factory, app.ProjectBuild), Flags: []cli.Flag{ cli.BoolFlag{ Name: "no-cache", Usage: "Do not use cache when building the image", }, cli.BoolFlag{ Name: "force-rm", Usage: "Always remove intermediate containers", }, cli.BoolFlag{ Name: "pull", Usage: "Always attempt to pull a newer version of the image", }, }, } }
[ "func", "BuildCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectBuild", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// BuildCommand defines the libcompose build subcommand.
[ "BuildCommand", "defines", "the", "libcompose", "build", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L72-L92
14,342
docker/libcompose
cli/command/command.go
PsCommand
func PsCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "ps", Usage: "List containers", Action: app.WithProject(factory, app.ProjectPs), Flags: []cli.Flag{ cli.BoolFlag{ Name: "q", Usage: "Only display IDs", }, }, } }
go
func PsCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "ps", Usage: "List containers", Action: app.WithProject(factory, app.ProjectPs), Flags: []cli.Flag{ cli.BoolFlag{ Name: "q", Usage: "Only display IDs", }, }, } }
[ "func", "PsCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectPs", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// PsCommand defines the libcompose ps subcommand.
[ "PsCommand", "defines", "the", "libcompose", "ps", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L95-L107
14,343
docker/libcompose
cli/command/command.go
PortCommand
func PortCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "port", Usage: "Print the public port for a port binding", Action: app.WithProject(factory, app.ProjectPort), Flags: []cli.Flag{ cli.StringFlag{ Name: "protocol", Usage: "tcp or udp ", Value: "tcp", }, cli.IntFlag{ Name: "index", Usage: "index of the container if there are multiple instances of a service", Value: 1, }, }, } }
go
func PortCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "port", Usage: "Print the public port for a port binding", Action: app.WithProject(factory, app.ProjectPort), Flags: []cli.Flag{ cli.StringFlag{ Name: "protocol", Usage: "tcp or udp ", Value: "tcp", }, cli.IntFlag{ Name: "index", Usage: "index of the container if there are multiple instances of a service", Value: 1, }, }, } }
[ "func", "PortCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectPort", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Value", ":", "\"", "\"", ",", "}", ",", "cli", ".", "IntFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Value", ":", "1", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// PortCommand defines the libcompose port subcommand.
[ "PortCommand", "defines", "the", "libcompose", "port", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L110-L128
14,344
docker/libcompose
cli/command/command.go
StartCommand
func StartCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "start", Usage: "Start services", Action: app.WithProject(factory, app.ProjectStart), Flags: []cli.Flag{ cli.BoolTFlag{ Name: "d", Usage: "Do not block and log", }, }, } }
go
func StartCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "start", Usage: "Start services", Action: app.WithProject(factory, app.ProjectStart), Flags: []cli.Flag{ cli.BoolTFlag{ Name: "d", Usage: "Do not block and log", }, }, } }
[ "func", "StartCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectStart", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolTFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// StartCommand defines the libcompose start subcommand.
[ "StartCommand", "defines", "the", "libcompose", "start", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L162-L174
14,345
docker/libcompose
cli/command/command.go
RunCommand
func RunCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "run", Usage: "Run a one-off command", Action: app.WithProject(factory, app.ProjectRun), Flags: []cli.Flag{ cli.BoolFlag{ Name: "d", Usage: "Detached mode: Run container in the background, print new container name.", }, }, } }
go
func RunCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "run", Usage: "Run a one-off command", Action: app.WithProject(factory, app.ProjectRun), Flags: []cli.Flag{ cli.BoolFlag{ Name: "d", Usage: "Detached mode: Run container in the background, print new container name.", }, }, } }
[ "func", "RunCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectRun", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// RunCommand defines the libcompose run subcommand.
[ "RunCommand", "defines", "the", "libcompose", "run", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L177-L189
14,346
docker/libcompose
cli/command/command.go
LogsCommand
func LogsCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "logs", Usage: "Get service logs", Action: app.WithProject(factory, app.ProjectLog), Flags: []cli.Flag{ cli.BoolFlag{ Name: "follow", Usage: "Follow log output.", }, }, } }
go
func LogsCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "logs", Usage: "Get service logs", Action: app.WithProject(factory, app.ProjectLog), Flags: []cli.Flag{ cli.BoolFlag{ Name: "follow", Usage: "Follow log output.", }, }, } }
[ "func", "LogsCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectLog", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// LogsCommand defines the libcompose logs subcommand.
[ "LogsCommand", "defines", "the", "libcompose", "logs", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L207-L219
14,347
docker/libcompose
cli/command/command.go
RestartCommand
func RestartCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "restart", Usage: "Restart services", Action: app.WithProject(factory, app.ProjectRestart), Flags: []cli.Flag{ cli.IntFlag{ Name: "timeout,t", Usage: "Specify a shutdown timeout in seconds.", }, }, } }
go
func RestartCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "restart", Usage: "Restart services", Action: app.WithProject(factory, app.ProjectRestart), Flags: []cli.Flag{ cli.IntFlag{ Name: "timeout,t", Usage: "Specify a shutdown timeout in seconds.", }, }, } }
[ "func", "RestartCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectRestart", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "IntFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// RestartCommand defines the libcompose restart subcommand.
[ "RestartCommand", "defines", "the", "libcompose", "restart", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L222-L234
14,348
docker/libcompose
cli/command/command.go
DownCommand
func DownCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "down", Usage: "Stop and remove containers, networks, images, and volumes", Action: app.WithProject(factory, app.ProjectDown), Flags: []cli.Flag{ cli.BoolFlag{ Name: "volumes,v", Usage: "Remove data volumes", }, cli.StringFlag{ Name: "rmi", Usage: "Remove images, type may be one of: 'all' to remove all images, or 'local' to remove only images that don't have an custom name set by the `image` field", }, cli.BoolFlag{ Name: "remove-orphans", Usage: "Remove containers for services not defined in the Compose file", }, }, } }
go
func DownCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "down", Usage: "Stop and remove containers, networks, images, and volumes", Action: app.WithProject(factory, app.ProjectDown), Flags: []cli.Flag{ cli.BoolFlag{ Name: "volumes,v", Usage: "Remove data volumes", }, cli.StringFlag{ Name: "rmi", Usage: "Remove images, type may be one of: 'all' to remove all images, or 'local' to remove only images that don't have an custom name set by the `image` field", }, cli.BoolFlag{ Name: "remove-orphans", Usage: "Remove containers for services not defined in the Compose file", }, }, } }
[ "func", "DownCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectDown", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// DownCommand defines the libcompose stop subcommand.
[ "DownCommand", "defines", "the", "libcompose", "stop", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L252-L272
14,349
docker/libcompose
cli/command/command.go
ScaleCommand
func ScaleCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "scale", Usage: "Scale services", Action: app.WithProject(factory, app.ProjectScale), Flags: []cli.Flag{ cli.IntFlag{ Name: "timeout,t", Usage: "Specify a shutdown timeout in seconds.", }, }, } }
go
func ScaleCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "scale", Usage: "Scale services", Action: app.WithProject(factory, app.ProjectScale), Flags: []cli.Flag{ cli.IntFlag{ Name: "timeout,t", Usage: "Specify a shutdown timeout in seconds.", }, }, } }
[ "func", "ScaleCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectScale", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "IntFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// ScaleCommand defines the libcompose scale subcommand.
[ "ScaleCommand", "defines", "the", "libcompose", "scale", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L275-L287
14,350
docker/libcompose
cli/command/command.go
RmCommand
func RmCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "rm", Usage: "Delete services", Action: app.WithProject(factory, app.ProjectDelete), Flags: []cli.Flag{ cli.BoolFlag{ Name: "force,f", Usage: "Allow deletion of all services", }, cli.BoolFlag{ Name: "v", Usage: "Remove volumes associated with containers", }, }, } }
go
func RmCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "rm", Usage: "Delete services", Action: app.WithProject(factory, app.ProjectDelete), Flags: []cli.Flag{ cli.BoolFlag{ Name: "force,f", Usage: "Allow deletion of all services", }, cli.BoolFlag{ Name: "v", Usage: "Remove volumes associated with containers", }, }, } }
[ "func", "RmCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectDelete", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// RmCommand defines the libcompose rm subcommand.
[ "RmCommand", "defines", "the", "libcompose", "rm", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L290-L306
14,351
docker/libcompose
cli/command/command.go
KillCommand
func KillCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "kill", Usage: "Force stop service containers", Action: app.WithProject(factory, app.ProjectKill), Flags: []cli.Flag{ cli.StringFlag{ Name: "signal,s", Usage: "SIGNAL to send to the container", Value: "SIGKILL", }, }, } }
go
func KillCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "kill", Usage: "Force stop service containers", Action: app.WithProject(factory, app.ProjectKill), Flags: []cli.Flag{ cli.StringFlag{ Name: "signal,s", Usage: "SIGNAL to send to the container", Value: "SIGKILL", }, }, } }
[ "func", "KillCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectKill", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Value", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// KillCommand defines the libcompose kill subcommand.
[ "KillCommand", "defines", "the", "libcompose", "kill", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L309-L322
14,352
docker/libcompose
cli/command/command.go
PauseCommand
func PauseCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "pause", Usage: "Pause services.", // ArgsUsage: "[SERVICE...]", Action: app.WithProject(factory, app.ProjectPause), } }
go
func PauseCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "pause", Usage: "Pause services.", // ArgsUsage: "[SERVICE...]", Action: app.WithProject(factory, app.ProjectPause), } }
[ "func", "PauseCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "// ArgsUsage: \"[SERVICE...]\",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectPause", ")", ",", "}", "\n", "}" ]
// PauseCommand defines the libcompose pause subcommand.
[ "PauseCommand", "defines", "the", "libcompose", "pause", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L325-L332
14,353
docker/libcompose
cli/command/command.go
UnpauseCommand
func UnpauseCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "unpause", Usage: "Unpause services.", // ArgsUsage: "[SERVICE...]", Action: app.WithProject(factory, app.ProjectUnpause), } }
go
func UnpauseCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "unpause", Usage: "Unpause services.", // ArgsUsage: "[SERVICE...]", Action: app.WithProject(factory, app.ProjectUnpause), } }
[ "func", "UnpauseCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "// ArgsUsage: \"[SERVICE...]\",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectUnpause", ")", ",", "}", "\n", "}" ]
// UnpauseCommand defines the libcompose unpause subcommand.
[ "UnpauseCommand", "defines", "the", "libcompose", "unpause", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L335-L342
14,354
docker/libcompose
cli/command/command.go
EventsCommand
func EventsCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "events", Usage: "Receive real time events from containers.", Action: app.WithProject(factory, app.ProjectEvents), Flags: []cli.Flag{ cli.BoolFlag{ Name: "json", Usage: "Output events as a stream of json objects", }, }, } }
go
func EventsCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "events", Usage: "Receive real time events from containers.", Action: app.WithProject(factory, app.ProjectEvents), Flags: []cli.Flag{ cli.BoolFlag{ Name: "json", Usage: "Output events as a stream of json objects", }, }, } }
[ "func", "EventsCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "WithProject", "(", "factory", ",", "app", ".", "ProjectEvents", ")", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// EventsCommand defines the libcompose events subcommand
[ "EventsCommand", "defines", "the", "libcompose", "events", "subcommand" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L345-L357
14,355
docker/libcompose
cli/command/command.go
VersionCommand
func VersionCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "version", Usage: "Show version informations", Action: app.Version, Flags: []cli.Flag{ cli.BoolFlag{ Name: "short", Usage: "Shows only Compose's version number.", }, }, } }
go
func VersionCommand(factory app.ProjectFactory) cli.Command { return cli.Command{ Name: "version", Usage: "Show version informations", Action: app.Version, Flags: []cli.Flag{ cli.BoolFlag{ Name: "short", Usage: "Shows only Compose's version number.", }, }, } }
[ "func", "VersionCommand", "(", "factory", "app", ".", "ProjectFactory", ")", "cli", ".", "Command", "{", "return", "cli", ".", "Command", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "app", ".", "Version", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// VersionCommand defines the libcompose version subcommand.
[ "VersionCommand", "defines", "the", "libcompose", "version", "subcommand", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L360-L372
14,356
docker/libcompose
cli/command/command.go
CommonFlags
func CommonFlags() []cli.Flag { return []cli.Flag{ cli.BoolFlag{ Name: "verbose,debug", }, cli.StringSliceFlag{ Name: "file,f", Usage: "Specify one or more alternate compose files (default: docker-compose.yml)", Value: &cli.StringSlice{}, EnvVar: "COMPOSE_FILE", }, cli.StringFlag{ Name: "project-name,p", Usage: "Specify an alternate project name (default: directory name)", EnvVar: "COMPOSE_PROJECT_NAME", }, } }
go
func CommonFlags() []cli.Flag { return []cli.Flag{ cli.BoolFlag{ Name: "verbose,debug", }, cli.StringSliceFlag{ Name: "file,f", Usage: "Specify one or more alternate compose files (default: docker-compose.yml)", Value: &cli.StringSlice{}, EnvVar: "COMPOSE_FILE", }, cli.StringFlag{ Name: "project-name,p", Usage: "Specify an alternate project name (default: directory name)", EnvVar: "COMPOSE_PROJECT_NAME", }, } }
[ "func", "CommonFlags", "(", ")", "[", "]", "cli", ".", "Flag", "{", "return", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "}", ",", "cli", ".", "StringSliceFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Value", ":", "&", "cli", ".", "StringSlice", "{", "}", ",", "EnvVar", ":", "\"", "\"", ",", "}", ",", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "EnvVar", ":", "\"", "\"", ",", "}", ",", "}", "\n", "}" ]
// CommonFlags defines the flags that are in common for all subcommands.
[ "CommonFlags", "defines", "the", "flags", "that", "are", "in", "common", "for", "all", "subcommands", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/command/command.go#L375-L392
14,357
docker/libcompose
cli/docker/app/commands.go
DockerClientFlags
func DockerClientFlags() []cli.Flag { return []cli.Flag{ cli.BoolFlag{ Name: "tls", Usage: "Use TLS; implied by --tlsverify", }, cli.BoolFlag{ Name: "tlsverify", Usage: "Use TLS and verify the remote", EnvVar: "DOCKER_TLS_VERIFY", }, cli.StringFlag{ Name: "tlscacert", Usage: "Trust certs signed only by this CA", }, cli.StringFlag{ Name: "tlscert", Usage: "Path to TLS certificate file", }, cli.StringFlag{ Name: "tlskey", Usage: "Path to TLS key file", }, cli.StringFlag{ Name: "configdir", Usage: "Path to docker config dir, default ${HOME}/.docker", }, } }
go
func DockerClientFlags() []cli.Flag { return []cli.Flag{ cli.BoolFlag{ Name: "tls", Usage: "Use TLS; implied by --tlsverify", }, cli.BoolFlag{ Name: "tlsverify", Usage: "Use TLS and verify the remote", EnvVar: "DOCKER_TLS_VERIFY", }, cli.StringFlag{ Name: "tlscacert", Usage: "Trust certs signed only by this CA", }, cli.StringFlag{ Name: "tlscert", Usage: "Path to TLS certificate file", }, cli.StringFlag{ Name: "tlskey", Usage: "Path to TLS key file", }, cli.StringFlag{ Name: "configdir", Usage: "Path to docker config dir, default ${HOME}/.docker", }, } }
[ "func", "DockerClientFlags", "(", ")", "[", "]", "cli", ".", "Flag", "{", "return", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "BoolFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "EnvVar", ":", "\"", "\"", ",", "}", ",", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", "\n", "}" ]
// DockerClientFlags defines the flags that are specific to the docker client, // like configdir or tls related flags.
[ "DockerClientFlags", "defines", "the", "flags", "that", "are", "specific", "to", "the", "docker", "client", "like", "configdir", "or", "tls", "related", "flags", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/docker/app/commands.go#L13-L41
14,358
docker/libcompose
cli/docker/app/commands.go
Populate
func Populate(context *ctx.Context, c *cli.Context) { command.Populate(&context.Context, c) context.ConfigDir = c.String("configdir") opts := client.Options{} opts.TLS = c.GlobalBool("tls") opts.TLSVerify = c.GlobalBool("tlsverify") opts.TLSOptions.CAFile = c.GlobalString("tlscacert") opts.TLSOptions.CertFile = c.GlobalString("tlscert") opts.TLSOptions.KeyFile = c.GlobalString("tlskey") clientFactory, err := client.NewDefaultFactory(opts) if err != nil { logrus.Fatalf("Failed to construct Docker client: %v", err) } context.ClientFactory = clientFactory }
go
func Populate(context *ctx.Context, c *cli.Context) { command.Populate(&context.Context, c) context.ConfigDir = c.String("configdir") opts := client.Options{} opts.TLS = c.GlobalBool("tls") opts.TLSVerify = c.GlobalBool("tlsverify") opts.TLSOptions.CAFile = c.GlobalString("tlscacert") opts.TLSOptions.CertFile = c.GlobalString("tlscert") opts.TLSOptions.KeyFile = c.GlobalString("tlskey") clientFactory, err := client.NewDefaultFactory(opts) if err != nil { logrus.Fatalf("Failed to construct Docker client: %v", err) } context.ClientFactory = clientFactory }
[ "func", "Populate", "(", "context", "*", "ctx", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "{", "command", ".", "Populate", "(", "&", "context", ".", "Context", ",", "c", ")", "\n\n", "context", ".", "ConfigDir", "=", "c", ".", "String", "(", "\"", "\"", ")", "\n\n", "opts", ":=", "client", ".", "Options", "{", "}", "\n", "opts", ".", "TLS", "=", "c", ".", "GlobalBool", "(", "\"", "\"", ")", "\n", "opts", ".", "TLSVerify", "=", "c", ".", "GlobalBool", "(", "\"", "\"", ")", "\n", "opts", ".", "TLSOptions", ".", "CAFile", "=", "c", ".", "GlobalString", "(", "\"", "\"", ")", "\n", "opts", ".", "TLSOptions", ".", "CertFile", "=", "c", ".", "GlobalString", "(", "\"", "\"", ")", "\n", "opts", ".", "TLSOptions", ".", "KeyFile", "=", "c", ".", "GlobalString", "(", "\"", "\"", ")", "\n\n", "clientFactory", ",", "err", ":=", "client", ".", "NewDefaultFactory", "(", "opts", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "context", ".", "ClientFactory", "=", "clientFactory", "\n", "}" ]
// Populate updates the specified docker context based on command line arguments and subcommands.
[ "Populate", "updates", "the", "specified", "docker", "context", "based", "on", "command", "line", "arguments", "and", "subcommands", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/cli/docker/app/commands.go#L44-L62
14,359
docker/libcompose
project/project_log.go
Log
func (p *Project) Log(ctx context.Context, follow bool, services ...string) error { return p.forEach(services, wrapperAction(func(wrapper *serviceWrapper, wrappers map[string]*serviceWrapper) { wrapper.Do(nil, events.NoEvent, events.NoEvent, func(service Service) error { return service.Log(ctx, follow) }) }), nil) }
go
func (p *Project) Log(ctx context.Context, follow bool, services ...string) error { return p.forEach(services, wrapperAction(func(wrapper *serviceWrapper, wrappers map[string]*serviceWrapper) { wrapper.Do(nil, events.NoEvent, events.NoEvent, func(service Service) error { return service.Log(ctx, follow) }) }), nil) }
[ "func", "(", "p", "*", "Project", ")", "Log", "(", "ctx", "context", ".", "Context", ",", "follow", "bool", ",", "services", "...", "string", ")", "error", "{", "return", "p", ".", "forEach", "(", "services", ",", "wrapperAction", "(", "func", "(", "wrapper", "*", "serviceWrapper", ",", "wrappers", "map", "[", "string", "]", "*", "serviceWrapper", ")", "{", "wrapper", ".", "Do", "(", "nil", ",", "events", ".", "NoEvent", ",", "events", ".", "NoEvent", ",", "func", "(", "service", "Service", ")", "error", "{", "return", "service", ".", "Log", "(", "ctx", ",", "follow", ")", "\n", "}", ")", "\n", "}", ")", ",", "nil", ")", "\n", "}" ]
// Log aggregates and prints out the logs for the specified services.
[ "Log", "aggregates", "and", "prints", "out", "the", "logs", "for", "the", "specified", "services", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/project/project_log.go#L10-L16
14,360
docker/libcompose
project/project_ps.go
Ps
func (p *Project) Ps(ctx context.Context, services ...string) (InfoSet, error) { allInfo := InfoSet{} if len(services) == 0 { services = p.ServiceConfigs.Keys() } for _, name := range services { service, err := p.CreateService(name) if err != nil { return nil, err } info, err := service.Info(ctx) if err != nil { return nil, err } allInfo = append(allInfo, info...) } return allInfo, nil }
go
func (p *Project) Ps(ctx context.Context, services ...string) (InfoSet, error) { allInfo := InfoSet{} if len(services) == 0 { services = p.ServiceConfigs.Keys() } for _, name := range services { service, err := p.CreateService(name) if err != nil { return nil, err } info, err := service.Info(ctx) if err != nil { return nil, err } allInfo = append(allInfo, info...) } return allInfo, nil }
[ "func", "(", "p", "*", "Project", ")", "Ps", "(", "ctx", "context", ".", "Context", ",", "services", "...", "string", ")", "(", "InfoSet", ",", "error", ")", "{", "allInfo", ":=", "InfoSet", "{", "}", "\n\n", "if", "len", "(", "services", ")", "==", "0", "{", "services", "=", "p", ".", "ServiceConfigs", ".", "Keys", "(", ")", "\n", "}", "\n\n", "for", "_", ",", "name", ":=", "range", "services", "{", "service", ",", "err", ":=", "p", ".", "CreateService", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "info", ",", "err", ":=", "service", ".", "Info", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "allInfo", "=", "append", "(", "allInfo", ",", "info", "...", ")", "\n", "}", "\n", "return", "allInfo", ",", "nil", "\n", "}" ]
// Ps list containers for the specified services.
[ "Ps", "list", "containers", "for", "the", "specified", "services", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/project/project_ps.go#L6-L28
14,361
docker/libcompose
config/types.go
Has
func (c *ServiceConfigs) Has(name string) bool { c.mu.RLock() defer c.mu.RUnlock() _, ok := c.m[name] return ok }
go
func (c *ServiceConfigs) Has(name string) bool { c.mu.RLock() defer c.mu.RUnlock() _, ok := c.m[name] return ok }
[ "func", "(", "c", "*", "ServiceConfigs", ")", "Has", "(", "name", "string", ")", "bool", "{", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n", "_", ",", "ok", ":=", "c", ".", "m", "[", "name", "]", "\n", "return", "ok", "\n", "}" ]
// Has checks if the config map has the specified name
[ "Has", "checks", "if", "the", "config", "map", "has", "the", "specified", "name" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/config/types.go#L199-L204
14,362
docker/libcompose
config/types.go
Get
func (c *ServiceConfigs) Get(name string) (*ServiceConfig, bool) { c.mu.RLock() defer c.mu.RUnlock() service, ok := c.m[name] return service, ok }
go
func (c *ServiceConfigs) Get(name string) (*ServiceConfig, bool) { c.mu.RLock() defer c.mu.RUnlock() service, ok := c.m[name] return service, ok }
[ "func", "(", "c", "*", "ServiceConfigs", ")", "Get", "(", "name", "string", ")", "(", "*", "ServiceConfig", ",", "bool", ")", "{", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n", "service", ",", "ok", ":=", "c", ".", "m", "[", "name", "]", "\n", "return", "service", ",", "ok", "\n", "}" ]
// Get returns the config and the presence of the specified name
[ "Get", "returns", "the", "config", "and", "the", "presence", "of", "the", "specified", "name" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/config/types.go#L207-L212
14,363
docker/libcompose
config/types.go
Add
func (c *ServiceConfigs) Add(name string, service *ServiceConfig) { c.mu.Lock() c.m[name] = service c.mu.Unlock() }
go
func (c *ServiceConfigs) Add(name string, service *ServiceConfig) { c.mu.Lock() c.m[name] = service c.mu.Unlock() }
[ "func", "(", "c", "*", "ServiceConfigs", ")", "Add", "(", "name", "string", ",", "service", "*", "ServiceConfig", ")", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "c", ".", "m", "[", "name", "]", "=", "service", "\n", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// Add add the specifed config with the specified name
[ "Add", "add", "the", "specifed", "config", "with", "the", "specified", "name" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/config/types.go#L215-L219
14,364
docker/libcompose
config/types.go
Remove
func (c *ServiceConfigs) Remove(name string) { c.mu.Lock() delete(c.m, name) c.mu.Unlock() }
go
func (c *ServiceConfigs) Remove(name string) { c.mu.Lock() delete(c.m, name) c.mu.Unlock() }
[ "func", "(", "c", "*", "ServiceConfigs", ")", "Remove", "(", "name", "string", ")", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "delete", "(", "c", ".", "m", ",", "name", ")", "\n", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// Remove removes the config with the specified name
[ "Remove", "removes", "the", "config", "with", "the", "specified", "name" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/config/types.go#L222-L226
14,365
docker/libcompose
config/types.go
Len
func (c *ServiceConfigs) Len() int { c.mu.RLock() defer c.mu.RUnlock() return len(c.m) }
go
func (c *ServiceConfigs) Len() int { c.mu.RLock() defer c.mu.RUnlock() return len(c.m) }
[ "func", "(", "c", "*", "ServiceConfigs", ")", "Len", "(", ")", "int", "{", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n", "return", "len", "(", "c", ".", "m", ")", "\n", "}" ]
// Len returns the len of the configs
[ "Len", "returns", "the", "len", "of", "the", "configs" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/config/types.go#L229-L233
14,366
docker/libcompose
config/types.go
Keys
func (c *ServiceConfigs) Keys() []string { keys := []string{} c.mu.RLock() defer c.mu.RUnlock() for name := range c.m { keys = append(keys, name) } return keys }
go
func (c *ServiceConfigs) Keys() []string { keys := []string{} c.mu.RLock() defer c.mu.RUnlock() for name := range c.m { keys = append(keys, name) } return keys }
[ "func", "(", "c", "*", "ServiceConfigs", ")", "Keys", "(", ")", "[", "]", "string", "{", "keys", ":=", "[", "]", "string", "{", "}", "\n", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n", "for", "name", ":=", "range", "c", ".", "m", "{", "keys", "=", "append", "(", "keys", ",", "name", ")", "\n", "}", "\n", "return", "keys", "\n", "}" ]
// Keys returns the names of the config
[ "Keys", "returns", "the", "names", "of", "the", "config" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/config/types.go#L236-L244
14,367
docker/libcompose
config/types.go
All
func (c *ServiceConfigs) All() map[string]*ServiceConfig { c.mu.RLock() defer c.mu.RUnlock() return c.m }
go
func (c *ServiceConfigs) All() map[string]*ServiceConfig { c.mu.RLock() defer c.mu.RUnlock() return c.m }
[ "func", "(", "c", "*", "ServiceConfigs", ")", "All", "(", ")", "map", "[", "string", "]", "*", "ServiceConfig", "{", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n", "return", "c", ".", "m", "\n", "}" ]
// All returns all the config at once
[ "All", "returns", "all", "the", "config", "at", "once" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/config/types.go#L247-L251
14,368
docker/libcompose
utils/util.go
Add
func (i *InParallel) Add(task func() error) { i.wg.Add(1) go func() { defer i.wg.Done() err := task() if err != nil { i.pool.Put(err) } }() }
go
func (i *InParallel) Add(task func() error) { i.wg.Add(1) go func() { defer i.wg.Done() err := task() if err != nil { i.pool.Put(err) } }() }
[ "func", "(", "i", "*", "InParallel", ")", "Add", "(", "task", "func", "(", ")", "error", ")", "{", "i", ".", "wg", ".", "Add", "(", "1", ")", "\n\n", "go", "func", "(", ")", "{", "defer", "i", ".", "wg", ".", "Done", "(", ")", "\n", "err", ":=", "task", "(", ")", "\n", "if", "err", "!=", "nil", "{", "i", ".", "pool", ".", "Put", "(", "err", ")", "\n", "}", "\n", "}", "(", ")", "\n", "}" ]
// Add runs the specified task in parallel and adds it to the waitGroup.
[ "Add", "runs", "the", "specified", "task", "in", "parallel", "and", "adds", "it", "to", "the", "waitGroup", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/utils/util.go#L21-L31
14,369
docker/libcompose
utils/util.go
Wait
func (i *InParallel) Wait() error { i.wg.Wait() obj := i.pool.Get() if err, ok := obj.(error); ok { return err } return nil }
go
func (i *InParallel) Wait() error { i.wg.Wait() obj := i.pool.Get() if err, ok := obj.(error); ok { return err } return nil }
[ "func", "(", "i", "*", "InParallel", ")", "Wait", "(", ")", "error", "{", "i", ".", "wg", ".", "Wait", "(", ")", "\n", "obj", ":=", "i", ".", "pool", ".", "Get", "(", ")", "\n", "if", "err", ",", "ok", ":=", "obj", ".", "(", "error", ")", ";", "ok", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Wait waits for all tasks to complete and returns the latest error encountered if any.
[ "Wait", "waits", "for", "all", "tasks", "to", "complete", "and", "returns", "the", "latest", "error", "encountered", "if", "any", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/utils/util.go#L34-L41
14,370
docker/libcompose
utils/util.go
CopySlice
func CopySlice(s []string) []string { if s == nil { return nil } r := make([]string, len(s)) copy(r, s) return r }
go
func CopySlice(s []string) []string { if s == nil { return nil } r := make([]string, len(s)) copy(r, s) return r }
[ "func", "CopySlice", "(", "s", "[", "]", "string", ")", "[", "]", "string", "{", "if", "s", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "r", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "s", ")", ")", "\n", "copy", "(", "r", ",", "s", ")", "\n", "return", "r", "\n", "}" ]
// CopySlice creates an exact copy of the provided string slice
[ "CopySlice", "creates", "an", "exact", "copy", "of", "the", "provided", "string", "slice" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/utils/util.go#L74-L81
14,371
docker/libcompose
utils/util.go
CopyMap
func CopyMap(m map[string]string) map[string]string { if m == nil { return nil } r := map[string]string{} for k, v := range m { r[k] = v } return r }
go
func CopyMap(m map[string]string) map[string]string { if m == nil { return nil } r := map[string]string{} for k, v := range m { r[k] = v } return r }
[ "func", "CopyMap", "(", "m", "map", "[", "string", "]", "string", ")", "map", "[", "string", "]", "string", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "r", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "for", "k", ",", "v", ":=", "range", "m", "{", "r", "[", "k", "]", "=", "v", "\n", "}", "\n", "return", "r", "\n", "}" ]
// CopyMap creates an exact copy of the provided string-to-string map
[ "CopyMap", "creates", "an", "exact", "copy", "of", "the", "provided", "string", "-", "to", "-", "string", "map" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/utils/util.go#L84-L93
14,372
docker/libcompose
utils/util.go
FilterString
func FilterString(data map[string][]string) string { // I can't imagine this would ever fail bytes, _ := json.Marshal(data) return string(bytes) }
go
func FilterString(data map[string][]string) string { // I can't imagine this would ever fail bytes, _ := json.Marshal(data) return string(bytes) }
[ "func", "FilterString", "(", "data", "map", "[", "string", "]", "[", "]", "string", ")", "string", "{", "// I can't imagine this would ever fail", "bytes", ",", "_", ":=", "json", ".", "Marshal", "(", "data", ")", "\n", "return", "string", "(", "bytes", ")", "\n", "}" ]
// FilterString returns a json representation of the specified map // that is used as filter for docker.
[ "FilterString", "returns", "a", "json", "representation", "of", "the", "specified", "map", "that", "is", "used", "as", "filter", "for", "docker", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/utils/util.go#L109-L113
14,373
docker/libcompose
docker/service/utils.go
GetContainerFromIpcLikeConfig
func GetContainerFromIpcLikeConfig(p *project.Project, conf string) string { ipc := container.IpcMode(conf) if !ipc.IsContainer() { return "" } name := ipc.Container() if name == "" { return "" } if p.ServiceConfigs.Has(name) { return name } return "" }
go
func GetContainerFromIpcLikeConfig(p *project.Project, conf string) string { ipc := container.IpcMode(conf) if !ipc.IsContainer() { return "" } name := ipc.Container() if name == "" { return "" } if p.ServiceConfigs.Has(name) { return name } return "" }
[ "func", "GetContainerFromIpcLikeConfig", "(", "p", "*", "project", ".", "Project", ",", "conf", "string", ")", "string", "{", "ipc", ":=", "container", ".", "IpcMode", "(", "conf", ")", "\n", "if", "!", "ipc", ".", "IsContainer", "(", ")", "{", "return", "\"", "\"", "\n", "}", "\n\n", "name", ":=", "ipc", ".", "Container", "(", ")", "\n", "if", "name", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n\n", "if", "p", ".", "ServiceConfigs", ".", "Has", "(", "name", ")", "{", "return", "name", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// GetContainerFromIpcLikeConfig returns name of the service that shares the IPC // namespace with the specified service.
[ "GetContainerFromIpcLikeConfig", "returns", "name", "of", "the", "service", "that", "shares", "the", "IPC", "namespace", "with", "the", "specified", "service", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/utils.go#L30-L45
14,374
docker/libcompose
project/listener.go
NewDefaultListener
func NewDefaultListener(p *Project) chan<- events.Event { l := defaultListener{ listenChan: make(chan events.Event), project: p, } go l.start() return l.listenChan }
go
func NewDefaultListener(p *Project) chan<- events.Event { l := defaultListener{ listenChan: make(chan events.Event), project: p, } go l.start() return l.listenChan }
[ "func", "NewDefaultListener", "(", "p", "*", "Project", ")", "chan", "<-", "events", ".", "Event", "{", "l", ":=", "defaultListener", "{", "listenChan", ":", "make", "(", "chan", "events", ".", "Event", ")", ",", "project", ":", "p", ",", "}", "\n", "go", "l", ".", "start", "(", ")", "\n", "return", "l", ".", "listenChan", "\n", "}" ]
// NewDefaultListener create a default listener for the specified project.
[ "NewDefaultListener", "create", "a", "default", "listener", "for", "the", "specified", "project", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/project/listener.go#L42-L49
14,375
docker/libcompose
config/merge.go
InterpolateRawServiceMap
func InterpolateRawServiceMap(baseRawServices *RawServiceMap, environmentLookup EnvironmentLookup) error { for k, v := range *baseRawServices { for k2, v2 := range v { if err := Interpolate(k2, &v2, environmentLookup); err != nil { return err } (*baseRawServices)[k][k2] = v2 } } return nil }
go
func InterpolateRawServiceMap(baseRawServices *RawServiceMap, environmentLookup EnvironmentLookup) error { for k, v := range *baseRawServices { for k2, v2 := range v { if err := Interpolate(k2, &v2, environmentLookup); err != nil { return err } (*baseRawServices)[k][k2] = v2 } } return nil }
[ "func", "InterpolateRawServiceMap", "(", "baseRawServices", "*", "RawServiceMap", ",", "environmentLookup", "EnvironmentLookup", ")", "error", "{", "for", "k", ",", "v", ":=", "range", "*", "baseRawServices", "{", "for", "k2", ",", "v2", ":=", "range", "v", "{", "if", "err", ":=", "Interpolate", "(", "k2", ",", "&", "v2", ",", "environmentLookup", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "(", "*", "baseRawServices", ")", "[", "k", "]", "[", "k2", "]", "=", "v2", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// InterpolateRawServiceMap replaces varialbse in raw service map struct based on environment lookup
[ "InterpolateRawServiceMap", "replaces", "varialbse", "in", "raw", "service", "map", "struct", "based", "on", "environment", "lookup" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/config/merge.go#L179-L189
14,376
docker/libcompose
yaml/volume.go
HashString
func (v *Volumes) HashString() string { if v == nil { return "" } result := []string{} for _, vol := range v.Volumes { result = append(result, vol.String()) } sort.Strings(result) return strings.Join(result, ",") }
go
func (v *Volumes) HashString() string { if v == nil { return "" } result := []string{} for _, vol := range v.Volumes { result = append(result, vol.String()) } sort.Strings(result) return strings.Join(result, ",") }
[ "func", "(", "v", "*", "Volumes", ")", "HashString", "(", ")", "string", "{", "if", "v", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "result", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "vol", ":=", "range", "v", ".", "Volumes", "{", "result", "=", "append", "(", "result", ",", "vol", ".", "String", "(", ")", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "result", ")", "\n", "return", "strings", ".", "Join", "(", "result", ",", "\"", "\"", ")", "\n", "}" ]
// Generate a hash string to detect service volume config changes
[ "Generate", "a", "hash", "string", "to", "detect", "service", "volume", "config", "changes" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/yaml/volume.go#L24-L34
14,377
docker/libcompose
config/validation.go
getValue
func getValue(val interface{}, context string) string { keys := strings.Split(context, ".") if keys[0] == "(root)" { keys = keys[1:] } for i, k := range keys { switch typedVal := (val).(type) { case string: return typedVal case []interface{}: if index, err := strconv.Atoi(k); err == nil { val = typedVal[index] } case RawServiceMap: val = typedVal[k] case RawService: val = typedVal[k] case map[interface{}]interface{}: val = typedVal[k] } if i == len(keys)-1 { return fmt.Sprint(val) } } return "" }
go
func getValue(val interface{}, context string) string { keys := strings.Split(context, ".") if keys[0] == "(root)" { keys = keys[1:] } for i, k := range keys { switch typedVal := (val).(type) { case string: return typedVal case []interface{}: if index, err := strconv.Atoi(k); err == nil { val = typedVal[index] } case RawServiceMap: val = typedVal[k] case RawService: val = typedVal[k] case map[interface{}]interface{}: val = typedVal[k] } if i == len(keys)-1 { return fmt.Sprint(val) } } return "" }
[ "func", "getValue", "(", "val", "interface", "{", "}", ",", "context", "string", ")", "string", "{", "keys", ":=", "strings", ".", "Split", "(", "context", ",", "\"", "\"", ")", "\n\n", "if", "keys", "[", "0", "]", "==", "\"", "\"", "{", "keys", "=", "keys", "[", "1", ":", "]", "\n", "}", "\n\n", "for", "i", ",", "k", ":=", "range", "keys", "{", "switch", "typedVal", ":=", "(", "val", ")", ".", "(", "type", ")", "{", "case", "string", ":", "return", "typedVal", "\n", "case", "[", "]", "interface", "{", "}", ":", "if", "index", ",", "err", ":=", "strconv", ".", "Atoi", "(", "k", ")", ";", "err", "==", "nil", "{", "val", "=", "typedVal", "[", "index", "]", "\n", "}", "\n", "case", "RawServiceMap", ":", "val", "=", "typedVal", "[", "k", "]", "\n", "case", "RawService", ":", "val", "=", "typedVal", "[", "k", "]", "\n", "case", "map", "[", "interface", "{", "}", "]", "interface", "{", "}", ":", "val", "=", "typedVal", "[", "k", "]", "\n", "}", "\n\n", "if", "i", "==", "len", "(", "keys", ")", "-", "1", "{", "return", "fmt", ".", "Sprint", "(", "val", ")", "\n", "}", "\n", "}", "\n\n", "return", "\"", "\"", "\n", "}" ]
// Gets the value in a service map at a given error context
[ "Gets", "the", "value", "in", "a", "service", "map", "at", "a", "given", "error", "context" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/config/validation.go#L43-L72
14,378
docker/libcompose
config/merge_v1.go
MergeServicesV1
func MergeServicesV1(existingServices *ServiceConfigs, environmentLookup EnvironmentLookup, resourceLookup ResourceLookup, file string, datas RawServiceMap, options *ParseOptions) (map[string]*ServiceConfigV1, error) { if options.Validate { if err := validate(datas); err != nil { return nil, err } } for name, data := range datas { data, err := parseV1(resourceLookup, environmentLookup, file, data, datas, options) if err != nil { logrus.Errorf("Failed to parse service %s: %v", name, err) return nil, err } if serviceConfig, ok := existingServices.Get(name); ok { var rawExistingService RawService if err := utils.Convert(serviceConfig, &rawExistingService); err != nil { return nil, err } data = mergeConfigV1(rawExistingService, data) } datas[name] = data } if options.Validate { for name, data := range datas { err := validateServiceConstraints(data, name) if err != nil { return nil, err } } } serviceConfigs := make(map[string]*ServiceConfigV1) if err := utils.Convert(datas, &serviceConfigs); err != nil { return nil, err } return serviceConfigs, nil }
go
func MergeServicesV1(existingServices *ServiceConfigs, environmentLookup EnvironmentLookup, resourceLookup ResourceLookup, file string, datas RawServiceMap, options *ParseOptions) (map[string]*ServiceConfigV1, error) { if options.Validate { if err := validate(datas); err != nil { return nil, err } } for name, data := range datas { data, err := parseV1(resourceLookup, environmentLookup, file, data, datas, options) if err != nil { logrus.Errorf("Failed to parse service %s: %v", name, err) return nil, err } if serviceConfig, ok := existingServices.Get(name); ok { var rawExistingService RawService if err := utils.Convert(serviceConfig, &rawExistingService); err != nil { return nil, err } data = mergeConfigV1(rawExistingService, data) } datas[name] = data } if options.Validate { for name, data := range datas { err := validateServiceConstraints(data, name) if err != nil { return nil, err } } } serviceConfigs := make(map[string]*ServiceConfigV1) if err := utils.Convert(datas, &serviceConfigs); err != nil { return nil, err } return serviceConfigs, nil }
[ "func", "MergeServicesV1", "(", "existingServices", "*", "ServiceConfigs", ",", "environmentLookup", "EnvironmentLookup", ",", "resourceLookup", "ResourceLookup", ",", "file", "string", ",", "datas", "RawServiceMap", ",", "options", "*", "ParseOptions", ")", "(", "map", "[", "string", "]", "*", "ServiceConfigV1", ",", "error", ")", "{", "if", "options", ".", "Validate", "{", "if", "err", ":=", "validate", "(", "datas", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "for", "name", ",", "data", ":=", "range", "datas", "{", "data", ",", "err", ":=", "parseV1", "(", "resourceLookup", ",", "environmentLookup", ",", "file", ",", "data", ",", "datas", ",", "options", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "name", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "serviceConfig", ",", "ok", ":=", "existingServices", ".", "Get", "(", "name", ")", ";", "ok", "{", "var", "rawExistingService", "RawService", "\n", "if", "err", ":=", "utils", ".", "Convert", "(", "serviceConfig", ",", "&", "rawExistingService", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "data", "=", "mergeConfigV1", "(", "rawExistingService", ",", "data", ")", "\n", "}", "\n\n", "datas", "[", "name", "]", "=", "data", "\n", "}", "\n\n", "if", "options", ".", "Validate", "{", "for", "name", ",", "data", ":=", "range", "datas", "{", "err", ":=", "validateServiceConstraints", "(", "data", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "}", "\n\n", "serviceConfigs", ":=", "make", "(", "map", "[", "string", "]", "*", "ServiceConfigV1", ")", "\n", "if", "err", ":=", "utils", ".", "Convert", "(", "datas", ",", "&", "serviceConfigs", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "serviceConfigs", ",", "nil", "\n", "}" ]
// MergeServicesV1 merges a v1 compose file into an existing set of service configs
[ "MergeServicesV1", "merges", "a", "v1", "compose", "file", "into", "an", "existing", "set", "of", "service", "configs" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/config/merge_v1.go#L12-L53
14,379
docker/libcompose
project/project_scale.go
Scale
func (p *Project) Scale(ctx context.Context, timeout int, servicesScale map[string]int) error { // This code is a bit verbose but I wanted to parse everything up front order := make([]string, 0, 0) services := make(map[string]Service) for name := range servicesScale { if !p.ServiceConfigs.Has(name) { return fmt.Errorf("%s is not defined in the template", name) } service, err := p.CreateService(name) if err != nil { return fmt.Errorf("Failed to lookup service: %s: %v", service, err) } order = append(order, name) services[name] = service } for _, name := range order { scale := servicesScale[name] log.Infof("Setting scale %s=%d...", name, scale) err := services[name].Scale(ctx, scale, timeout) if err != nil { return fmt.Errorf("Failed to set the scale %s=%d: %v", name, scale, err) } } return nil }
go
func (p *Project) Scale(ctx context.Context, timeout int, servicesScale map[string]int) error { // This code is a bit verbose but I wanted to parse everything up front order := make([]string, 0, 0) services := make(map[string]Service) for name := range servicesScale { if !p.ServiceConfigs.Has(name) { return fmt.Errorf("%s is not defined in the template", name) } service, err := p.CreateService(name) if err != nil { return fmt.Errorf("Failed to lookup service: %s: %v", service, err) } order = append(order, name) services[name] = service } for _, name := range order { scale := servicesScale[name] log.Infof("Setting scale %s=%d...", name, scale) err := services[name].Scale(ctx, scale, timeout) if err != nil { return fmt.Errorf("Failed to set the scale %s=%d: %v", name, scale, err) } } return nil }
[ "func", "(", "p", "*", "Project", ")", "Scale", "(", "ctx", "context", ".", "Context", ",", "timeout", "int", ",", "servicesScale", "map", "[", "string", "]", "int", ")", "error", "{", "// This code is a bit verbose but I wanted to parse everything up front", "order", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "0", ")", "\n", "services", ":=", "make", "(", "map", "[", "string", "]", "Service", ")", "\n\n", "for", "name", ":=", "range", "servicesScale", "{", "if", "!", "p", ".", "ServiceConfigs", ".", "Has", "(", "name", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n\n", "service", ",", "err", ":=", "p", ".", "CreateService", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "service", ",", "err", ")", "\n", "}", "\n\n", "order", "=", "append", "(", "order", ",", "name", ")", "\n", "services", "[", "name", "]", "=", "service", "\n", "}", "\n\n", "for", "_", ",", "name", ":=", "range", "order", "{", "scale", ":=", "servicesScale", "[", "name", "]", "\n", "log", ".", "Infof", "(", "\"", "\"", ",", "name", ",", "scale", ")", "\n", "err", ":=", "services", "[", "name", "]", ".", "Scale", "(", "ctx", ",", "scale", ",", "timeout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ",", "scale", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Scale scales the specified services.
[ "Scale", "scales", "the", "specified", "services", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/project/project_scale.go#L12-L40
14,380
docker/libcompose
docker/service/convert.go
Filter
func Filter(vs []string, f func(string) bool) []string { r := make([]string, 0, len(vs)) for _, v := range vs { if f(v) { r = append(r, v) } } return r }
go
func Filter(vs []string, f func(string) bool) []string { r := make([]string, 0, len(vs)) for _, v := range vs { if f(v) { r = append(r, v) } } return r }
[ "func", "Filter", "(", "vs", "[", "]", "string", ",", "f", "func", "(", "string", ")", "bool", ")", "[", "]", "string", "{", "r", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "vs", ")", ")", "\n", "for", "_", ",", "v", ":=", "range", "vs", "{", "if", "f", "(", "v", ")", "{", "r", "=", "append", "(", "r", ",", "v", ")", "\n", "}", "\n", "}", "\n", "return", "r", "\n", "}" ]
// Filter filters the specified string slice with the specified function.
[ "Filter", "filters", "the", "specified", "string", "slice", "with", "the", "specified", "function", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/convert.go#L29-L37
14,381
docker/libcompose
docker/service/convert.go
ConvertToAPI
func ConvertToAPI(serviceConfig *config.ServiceConfig, ctx project.Context, clientFactory composeclient.Factory) (*ConfigWrapper, error) { config, hostConfig, err := Convert(serviceConfig, ctx, clientFactory) if err != nil { return nil, err } result := ConfigWrapper{ Config: config, HostConfig: hostConfig, } return &result, nil }
go
func ConvertToAPI(serviceConfig *config.ServiceConfig, ctx project.Context, clientFactory composeclient.Factory) (*ConfigWrapper, error) { config, hostConfig, err := Convert(serviceConfig, ctx, clientFactory) if err != nil { return nil, err } result := ConfigWrapper{ Config: config, HostConfig: hostConfig, } return &result, nil }
[ "func", "ConvertToAPI", "(", "serviceConfig", "*", "config", ".", "ServiceConfig", ",", "ctx", "project", ".", "Context", ",", "clientFactory", "composeclient", ".", "Factory", ")", "(", "*", "ConfigWrapper", ",", "error", ")", "{", "config", ",", "hostConfig", ",", "err", ":=", "Convert", "(", "serviceConfig", ",", "ctx", ",", "clientFactory", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "result", ":=", "ConfigWrapper", "{", "Config", ":", "config", ",", "HostConfig", ":", "hostConfig", ",", "}", "\n", "return", "&", "result", ",", "nil", "\n", "}" ]
// ConvertToAPI converts a service configuration to a docker API container configuration.
[ "ConvertToAPI", "converts", "a", "service", "configuration", "to", "a", "docker", "API", "container", "configuration", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/service/convert.go#L58-L69
14,382
docker/libcompose
project/project_port.go
Port
func (p *Project) Port(ctx context.Context, index int, protocol, serviceName, privatePort string) (string, error) { service, err := p.CreateService(serviceName) if err != nil { return "", err } containers, err := service.Containers(ctx) if err != nil { return "", err } if index < 1 || index > len(containers) { return "", fmt.Errorf("Invalid index %d", index) } return containers[index-1].Port(ctx, fmt.Sprintf("%s/%s", privatePort, protocol)) }
go
func (p *Project) Port(ctx context.Context, index int, protocol, serviceName, privatePort string) (string, error) { service, err := p.CreateService(serviceName) if err != nil { return "", err } containers, err := service.Containers(ctx) if err != nil { return "", err } if index < 1 || index > len(containers) { return "", fmt.Errorf("Invalid index %d", index) } return containers[index-1].Port(ctx, fmt.Sprintf("%s/%s", privatePort, protocol)) }
[ "func", "(", "p", "*", "Project", ")", "Port", "(", "ctx", "context", ".", "Context", ",", "index", "int", ",", "protocol", ",", "serviceName", ",", "privatePort", "string", ")", "(", "string", ",", "error", ")", "{", "service", ",", "err", ":=", "p", ".", "CreateService", "(", "serviceName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "containers", ",", "err", ":=", "service", ".", "Containers", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "index", "<", "1", "||", "index", ">", "len", "(", "containers", ")", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "index", ")", "\n", "}", "\n\n", "return", "containers", "[", "index", "-", "1", "]", ".", "Port", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "privatePort", ",", "protocol", ")", ")", "\n", "}" ]
// Port returns the public port for a port binding of the specified service.
[ "Port", "returns", "the", "public", "port", "for", "a", "port", "binding", "of", "the", "specified", "service", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/project/project_port.go#L10-L26
14,383
docker/libcompose
docker/network/network.go
Inspect
func (n *Network) Inspect(ctx context.Context) (types.NetworkResource, error) { return n.client.NetworkInspect(ctx, n.fullName(), types.NetworkInspectOptions{ Verbose: true, }) }
go
func (n *Network) Inspect(ctx context.Context) (types.NetworkResource, error) { return n.client.NetworkInspect(ctx, n.fullName(), types.NetworkInspectOptions{ Verbose: true, }) }
[ "func", "(", "n", "*", "Network", ")", "Inspect", "(", "ctx", "context", ".", "Context", ")", "(", "types", ".", "NetworkResource", ",", "error", ")", "{", "return", "n", ".", "client", ".", "NetworkInspect", "(", "ctx", ",", "n", ".", "fullName", "(", ")", ",", "types", ".", "NetworkInspectOptions", "{", "Verbose", ":", "true", ",", "}", ")", "\n", "}" ]
// Inspect inspect the current network
[ "Inspect", "inspect", "the", "current", "network" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/network/network.go#L37-L41
14,384
docker/libcompose
docker/network/network.go
EnsureItExists
func (n *Network) EnsureItExists(ctx context.Context) error { networkResource, err := n.Inspect(ctx) if n.external { if client.IsErrNotFound(err) { // FIXME(vdemeester) introduce some libcompose error type return fmt.Errorf("Network %s declared as external, but could not be found. Please create the network manually using docker network create %s and try again", n.fullName(), n.fullName()) } return err } if err != nil && client.IsErrNotFound(err) { return n.create(ctx) } if n.driver != "" && networkResource.Driver != n.driver { return fmt.Errorf("Network %q needs to be recreated - driver has changed", n.fullName()) } if len(n.driverOptions) != 0 && !reflect.DeepEqual(networkResource.Options, n.driverOptions) { return fmt.Errorf("Network %q needs to be recreated - options have changed", n.fullName()) } return err }
go
func (n *Network) EnsureItExists(ctx context.Context) error { networkResource, err := n.Inspect(ctx) if n.external { if client.IsErrNotFound(err) { // FIXME(vdemeester) introduce some libcompose error type return fmt.Errorf("Network %s declared as external, but could not be found. Please create the network manually using docker network create %s and try again", n.fullName(), n.fullName()) } return err } if err != nil && client.IsErrNotFound(err) { return n.create(ctx) } if n.driver != "" && networkResource.Driver != n.driver { return fmt.Errorf("Network %q needs to be recreated - driver has changed", n.fullName()) } if len(n.driverOptions) != 0 && !reflect.DeepEqual(networkResource.Options, n.driverOptions) { return fmt.Errorf("Network %q needs to be recreated - options have changed", n.fullName()) } return err }
[ "func", "(", "n", "*", "Network", ")", "EnsureItExists", "(", "ctx", "context", ".", "Context", ")", "error", "{", "networkResource", ",", "err", ":=", "n", ".", "Inspect", "(", "ctx", ")", "\n", "if", "n", ".", "external", "{", "if", "client", ".", "IsErrNotFound", "(", "err", ")", "{", "// FIXME(vdemeester) introduce some libcompose error type", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "n", ".", "fullName", "(", ")", ",", "n", ".", "fullName", "(", ")", ")", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "if", "err", "!=", "nil", "&&", "client", ".", "IsErrNotFound", "(", "err", ")", "{", "return", "n", ".", "create", "(", "ctx", ")", "\n", "}", "\n", "if", "n", ".", "driver", "!=", "\"", "\"", "&&", "networkResource", ".", "Driver", "!=", "n", ".", "driver", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "n", ".", "fullName", "(", ")", ")", "\n", "}", "\n", "if", "len", "(", "n", ".", "driverOptions", ")", "!=", "0", "&&", "!", "reflect", ".", "DeepEqual", "(", "networkResource", ".", "Options", ",", "n", ".", "driverOptions", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "n", ".", "fullName", "(", ")", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// EnsureItExists make sure the network exists and return an error if it does not exists // and cannot be created.
[ "EnsureItExists", "make", "sure", "the", "network", "exists", "and", "return", "an", "error", "if", "it", "does", "not", "exists", "and", "cannot", "be", "created", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/network/network.go#L55-L74
14,385
docker/libcompose
docker/network/network.go
NewNetwork
func NewNetwork(projectName, name string, config *config.NetworkConfig, client client.NetworkAPIClient) *Network { networkName := name if config.External.External { networkName = config.External.Name } return &Network{ client: client, name: networkName, projectName: projectName, driver: config.Driver, driverOptions: config.DriverOpts, external: config.External.External, ipam: config.Ipam, } }
go
func NewNetwork(projectName, name string, config *config.NetworkConfig, client client.NetworkAPIClient) *Network { networkName := name if config.External.External { networkName = config.External.Name } return &Network{ client: client, name: networkName, projectName: projectName, driver: config.Driver, driverOptions: config.DriverOpts, external: config.External.External, ipam: config.Ipam, } }
[ "func", "NewNetwork", "(", "projectName", ",", "name", "string", ",", "config", "*", "config", ".", "NetworkConfig", ",", "client", "client", ".", "NetworkAPIClient", ")", "*", "Network", "{", "networkName", ":=", "name", "\n", "if", "config", ".", "External", ".", "External", "{", "networkName", "=", "config", ".", "External", ".", "Name", "\n", "}", "\n", "return", "&", "Network", "{", "client", ":", "client", ",", "name", ":", "networkName", ",", "projectName", ":", "projectName", ",", "driver", ":", "config", ".", "Driver", ",", "driverOptions", ":", "config", ".", "DriverOpts", ",", "external", ":", "config", ".", "External", ".", "External", ",", "ipam", ":", "config", ".", "Ipam", ",", "}", "\n", "}" ]
// NewNetwork creates a new network from the specified name and config.
[ "NewNetwork", "creates", "a", "new", "network", "from", "the", "specified", "name", "and", "config", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/network/network.go#L103-L117
14,386
docker/libcompose
docker/network/network.go
Initialize
func (n *Networks) Initialize(ctx context.Context) error { if !n.networkEnabled { return nil } for _, network := range n.networks { err := network.EnsureItExists(ctx) if err != nil { return err } } return nil }
go
func (n *Networks) Initialize(ctx context.Context) error { if !n.networkEnabled { return nil } for _, network := range n.networks { err := network.EnsureItExists(ctx) if err != nil { return err } } return nil }
[ "func", "(", "n", "*", "Networks", ")", "Initialize", "(", "ctx", "context", ".", "Context", ")", "error", "{", "if", "!", "n", ".", "networkEnabled", "{", "return", "nil", "\n", "}", "\n", "for", "_", ",", "network", ":=", "range", "n", ".", "networks", "{", "err", ":=", "network", ".", "EnsureItExists", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Initialize make sure network exists if network is enabled
[ "Initialize", "make", "sure", "network", "exists", "if", "network", "is", "enabled" ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/network/network.go#L126-L137
14,387
docker/libcompose
docker/network/network.go
NetworksFromServices
func NetworksFromServices(cli client.NetworkAPIClient, projectName string, networkConfigs map[string]*config.NetworkConfig, services *config.ServiceConfigs, networkEnabled bool) (*Networks, error) { var err error networks := make([]*Network, 0, len(networkConfigs)) networkNames := map[string]*yaml.Network{} for _, serviceName := range services.Keys() { serviceConfig, _ := services.Get(serviceName) if serviceConfig.NetworkMode != "" || serviceConfig.Networks == nil || len(serviceConfig.Networks.Networks) == 0 { continue } for _, network := range serviceConfig.Networks.Networks { if network.Name != "default" { if _, ok := networkConfigs[network.Name]; !ok { return nil, fmt.Errorf(`Service "%s" uses an undefined network "%s"`, serviceName, network.Name) } } networkNames[network.Name] = network } } if len(networkConfigs) == 0 { network := NewNetwork(projectName, "default", &config.NetworkConfig{ Driver: "bridge", }, cli) networks = append(networks, network) } for name, config := range networkConfigs { network := NewNetwork(projectName, name, config, cli) networks = append(networks, network) } if len(networkNames) != len(networks) { unused := []string{} for name := range networkConfigs { if name == "default" { continue } if _, ok := networkNames[name]; !ok { unused = append(unused, name) } } if len(unused) != 0 { err = fmt.Errorf("Some networks were defined but are not used by any service: %v", strings.Join(unused, " ")) } } return &Networks{ networks: networks, networkEnabled: networkEnabled, }, err }
go
func NetworksFromServices(cli client.NetworkAPIClient, projectName string, networkConfigs map[string]*config.NetworkConfig, services *config.ServiceConfigs, networkEnabled bool) (*Networks, error) { var err error networks := make([]*Network, 0, len(networkConfigs)) networkNames := map[string]*yaml.Network{} for _, serviceName := range services.Keys() { serviceConfig, _ := services.Get(serviceName) if serviceConfig.NetworkMode != "" || serviceConfig.Networks == nil || len(serviceConfig.Networks.Networks) == 0 { continue } for _, network := range serviceConfig.Networks.Networks { if network.Name != "default" { if _, ok := networkConfigs[network.Name]; !ok { return nil, fmt.Errorf(`Service "%s" uses an undefined network "%s"`, serviceName, network.Name) } } networkNames[network.Name] = network } } if len(networkConfigs) == 0 { network := NewNetwork(projectName, "default", &config.NetworkConfig{ Driver: "bridge", }, cli) networks = append(networks, network) } for name, config := range networkConfigs { network := NewNetwork(projectName, name, config, cli) networks = append(networks, network) } if len(networkNames) != len(networks) { unused := []string{} for name := range networkConfigs { if name == "default" { continue } if _, ok := networkNames[name]; !ok { unused = append(unused, name) } } if len(unused) != 0 { err = fmt.Errorf("Some networks were defined but are not used by any service: %v", strings.Join(unused, " ")) } } return &Networks{ networks: networks, networkEnabled: networkEnabled, }, err }
[ "func", "NetworksFromServices", "(", "cli", "client", ".", "NetworkAPIClient", ",", "projectName", "string", ",", "networkConfigs", "map", "[", "string", "]", "*", "config", ".", "NetworkConfig", ",", "services", "*", "config", ".", "ServiceConfigs", ",", "networkEnabled", "bool", ")", "(", "*", "Networks", ",", "error", ")", "{", "var", "err", "error", "\n", "networks", ":=", "make", "(", "[", "]", "*", "Network", ",", "0", ",", "len", "(", "networkConfigs", ")", ")", "\n", "networkNames", ":=", "map", "[", "string", "]", "*", "yaml", ".", "Network", "{", "}", "\n", "for", "_", ",", "serviceName", ":=", "range", "services", ".", "Keys", "(", ")", "{", "serviceConfig", ",", "_", ":=", "services", ".", "Get", "(", "serviceName", ")", "\n", "if", "serviceConfig", ".", "NetworkMode", "!=", "\"", "\"", "||", "serviceConfig", ".", "Networks", "==", "nil", "||", "len", "(", "serviceConfig", ".", "Networks", ".", "Networks", ")", "==", "0", "{", "continue", "\n", "}", "\n", "for", "_", ",", "network", ":=", "range", "serviceConfig", ".", "Networks", ".", "Networks", "{", "if", "network", ".", "Name", "!=", "\"", "\"", "{", "if", "_", ",", "ok", ":=", "networkConfigs", "[", "network", ".", "Name", "]", ";", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "`Service \"%s\" uses an undefined network \"%s\"`", ",", "serviceName", ",", "network", ".", "Name", ")", "\n", "}", "\n", "}", "\n", "networkNames", "[", "network", ".", "Name", "]", "=", "network", "\n", "}", "\n", "}", "\n", "if", "len", "(", "networkConfigs", ")", "==", "0", "{", "network", ":=", "NewNetwork", "(", "projectName", ",", "\"", "\"", ",", "&", "config", ".", "NetworkConfig", "{", "Driver", ":", "\"", "\"", ",", "}", ",", "cli", ")", "\n", "networks", "=", "append", "(", "networks", ",", "network", ")", "\n", "}", "\n", "for", "name", ",", "config", ":=", "range", "networkConfigs", "{", "network", ":=", "NewNetwork", "(", "projectName", ",", "name", ",", "config", ",", "cli", ")", "\n", "networks", "=", "append", "(", "networks", ",", "network", ")", "\n", "}", "\n", "if", "len", "(", "networkNames", ")", "!=", "len", "(", "networks", ")", "{", "unused", ":=", "[", "]", "string", "{", "}", "\n", "for", "name", ":=", "range", "networkConfigs", "{", "if", "name", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "networkNames", "[", "name", "]", ";", "!", "ok", "{", "unused", "=", "append", "(", "unused", ",", "name", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "unused", ")", "!=", "0", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "unused", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "}", "\n", "return", "&", "Networks", "{", "networks", ":", "networks", ",", "networkEnabled", ":", "networkEnabled", ",", "}", ",", "err", "\n", "}" ]
// NetworksFromServices creates a new Networks struct based on networks configurations and // services configuration. If a network is defined but not used by any service, it will return // an error along the Networks.
[ "NetworksFromServices", "creates", "a", "new", "Networks", "struct", "based", "on", "networks", "configurations", "and", "services", "configuration", ".", "If", "a", "network", "is", "defined", "but", "not", "used", "by", "any", "service", "it", "will", "return", "an", "error", "along", "the", "Networks", "." ]
213509acef0fe8f2358f4c0bb977eb3f4889ea15
https://github.com/docker/libcompose/blob/213509acef0fe8f2358f4c0bb977eb3f4889ea15/docker/network/network.go#L156-L202
14,388
hjr265/redsync.go
redsync/mutex.go
NewMutex
func NewMutex(name string, addrs []net.Addr) (*Mutex, error) { if len(addrs) == 0 { panic("redsync: addrs is empty") } nodes := make([]Pool, len(addrs)) for i, addr := range addrs { dialTo := addr node := &redis.Pool{ MaxActive: 1, Wait: true, Dial: func() (redis.Conn, error) { return redis.Dial("tcp", dialTo.String()) }, } nodes[i] = Pool(node) } return NewMutexWithGenericPool(name, nodes) }
go
func NewMutex(name string, addrs []net.Addr) (*Mutex, error) { if len(addrs) == 0 { panic("redsync: addrs is empty") } nodes := make([]Pool, len(addrs)) for i, addr := range addrs { dialTo := addr node := &redis.Pool{ MaxActive: 1, Wait: true, Dial: func() (redis.Conn, error) { return redis.Dial("tcp", dialTo.String()) }, } nodes[i] = Pool(node) } return NewMutexWithGenericPool(name, nodes) }
[ "func", "NewMutex", "(", "name", "string", ",", "addrs", "[", "]", "net", ".", "Addr", ")", "(", "*", "Mutex", ",", "error", ")", "{", "if", "len", "(", "addrs", ")", "==", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "nodes", ":=", "make", "(", "[", "]", "Pool", ",", "len", "(", "addrs", ")", ")", "\n", "for", "i", ",", "addr", ":=", "range", "addrs", "{", "dialTo", ":=", "addr", "\n", "node", ":=", "&", "redis", ".", "Pool", "{", "MaxActive", ":", "1", ",", "Wait", ":", "true", ",", "Dial", ":", "func", "(", ")", "(", "redis", ".", "Conn", ",", "error", ")", "{", "return", "redis", ".", "Dial", "(", "\"", "\"", ",", "dialTo", ".", "String", "(", ")", ")", "\n", "}", ",", "}", "\n", "nodes", "[", "i", "]", "=", "Pool", "(", "node", ")", "\n", "}", "\n\n", "return", "NewMutexWithGenericPool", "(", "name", ",", "nodes", ")", "\n", "}" ]
// NewMutex returns a new Mutex on a named resource connected to the Redis instances at given addresses.
[ "NewMutex", "returns", "a", "new", "Mutex", "on", "a", "named", "resource", "connected", "to", "the", "Redis", "instances", "at", "given", "addresses", "." ]
688f6d364b799fa311a6de70b2bb9a4a669221da
https://github.com/hjr265/redsync.go/blob/688f6d364b799fa311a6de70b2bb9a4a669221da/redsync/mutex.go#L71-L90
14,389
hjr265/redsync.go
redsync/mutex.go
NewMutexWithPool
func NewMutexWithPool(name string, nodes []*redis.Pool) (*Mutex, error) { if len(nodes) == 0 { panic("redsync: nodes is empty") } genericNodes := make([]Pool, len(nodes)) for i, node := range nodes { genericNodes[i] = Pool(node) } return &Mutex{ Name: name, Quorum: len(genericNodes)/2 + 1, nodes: genericNodes, }, nil }
go
func NewMutexWithPool(name string, nodes []*redis.Pool) (*Mutex, error) { if len(nodes) == 0 { panic("redsync: nodes is empty") } genericNodes := make([]Pool, len(nodes)) for i, node := range nodes { genericNodes[i] = Pool(node) } return &Mutex{ Name: name, Quorum: len(genericNodes)/2 + 1, nodes: genericNodes, }, nil }
[ "func", "NewMutexWithPool", "(", "name", "string", ",", "nodes", "[", "]", "*", "redis", ".", "Pool", ")", "(", "*", "Mutex", ",", "error", ")", "{", "if", "len", "(", "nodes", ")", "==", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "genericNodes", ":=", "make", "(", "[", "]", "Pool", ",", "len", "(", "nodes", ")", ")", "\n", "for", "i", ",", "node", ":=", "range", "nodes", "{", "genericNodes", "[", "i", "]", "=", "Pool", "(", "node", ")", "\n", "}", "\n\n", "return", "&", "Mutex", "{", "Name", ":", "name", ",", "Quorum", ":", "len", "(", "genericNodes", ")", "/", "2", "+", "1", ",", "nodes", ":", "genericNodes", ",", "}", ",", "nil", "\n", "}" ]
// NewMutexWithPool returns a new Mutex on a named resource connected to the Redis instances at given redis Pools.
[ "NewMutexWithPool", "returns", "a", "new", "Mutex", "on", "a", "named", "resource", "connected", "to", "the", "Redis", "instances", "at", "given", "redis", "Pools", "." ]
688f6d364b799fa311a6de70b2bb9a4a669221da
https://github.com/hjr265/redsync.go/blob/688f6d364b799fa311a6de70b2bb9a4a669221da/redsync/mutex.go#L93-L108
14,390
hjr265/redsync.go
redsync/mutex.go
NewMutexWithGenericPool
func NewMutexWithGenericPool(name string, genericNodes []Pool) (*Mutex, error) { if len(genericNodes) == 0 { panic("redsync: genericNodes is empty") } return &Mutex{ Name: name, Quorum: len(genericNodes)/2 + 1, nodes: genericNodes, }, nil }
go
func NewMutexWithGenericPool(name string, genericNodes []Pool) (*Mutex, error) { if len(genericNodes) == 0 { panic("redsync: genericNodes is empty") } return &Mutex{ Name: name, Quorum: len(genericNodes)/2 + 1, nodes: genericNodes, }, nil }
[ "func", "NewMutexWithGenericPool", "(", "name", "string", ",", "genericNodes", "[", "]", "Pool", ")", "(", "*", "Mutex", ",", "error", ")", "{", "if", "len", "(", "genericNodes", ")", "==", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "&", "Mutex", "{", "Name", ":", "name", ",", "Quorum", ":", "len", "(", "genericNodes", ")", "/", "2", "+", "1", ",", "nodes", ":", "genericNodes", ",", "}", ",", "nil", "\n", "}" ]
// NewMutexWithGenericPool returns a new Mutex on a named resource connected to the Redis instances at given generic Pools. // different from NewMutexWithPool to maintain backwards compatibility
[ "NewMutexWithGenericPool", "returns", "a", "new", "Mutex", "on", "a", "named", "resource", "connected", "to", "the", "Redis", "instances", "at", "given", "generic", "Pools", ".", "different", "from", "NewMutexWithPool", "to", "maintain", "backwards", "compatibility" ]
688f6d364b799fa311a6de70b2bb9a4a669221da
https://github.com/hjr265/redsync.go/blob/688f6d364b799fa311a6de70b2bb9a4a669221da/redsync/mutex.go#L112-L122
14,391
hjr265/redsync.go
redsync/mutex.go
New
func New(addrs []net.Addr) *RedSync { pools := make([]Pool, len(addrs)) for i, addr := range addrs { dialTo := addr node := &redis.Pool{ MaxActive: 1, Wait: true, Dial: func() (redis.Conn, error) { return redis.Dial("tcp", dialTo.String()) }, } pools[i] = Pool(node) } return &RedSync{pools} }
go
func New(addrs []net.Addr) *RedSync { pools := make([]Pool, len(addrs)) for i, addr := range addrs { dialTo := addr node := &redis.Pool{ MaxActive: 1, Wait: true, Dial: func() (redis.Conn, error) { return redis.Dial("tcp", dialTo.String()) }, } pools[i] = Pool(node) } return &RedSync{pools} }
[ "func", "New", "(", "addrs", "[", "]", "net", ".", "Addr", ")", "*", "RedSync", "{", "pools", ":=", "make", "(", "[", "]", "Pool", ",", "len", "(", "addrs", ")", ")", "\n", "for", "i", ",", "addr", ":=", "range", "addrs", "{", "dialTo", ":=", "addr", "\n", "node", ":=", "&", "redis", ".", "Pool", "{", "MaxActive", ":", "1", ",", "Wait", ":", "true", ",", "Dial", ":", "func", "(", ")", "(", "redis", ".", "Conn", ",", "error", ")", "{", "return", "redis", ".", "Dial", "(", "\"", "\"", ",", "dialTo", ".", "String", "(", ")", ")", "\n", "}", ",", "}", "\n", "pools", "[", "i", "]", "=", "Pool", "(", "node", ")", "\n", "}", "\n\n", "return", "&", "RedSync", "{", "pools", "}", "\n", "}" ]
// New creates and returns a new RedSync instance from given network addresses.
[ "New", "creates", "and", "returns", "a", "new", "RedSync", "instance", "from", "given", "network", "addresses", "." ]
688f6d364b799fa311a6de70b2bb9a4a669221da
https://github.com/hjr265/redsync.go/blob/688f6d364b799fa311a6de70b2bb9a4a669221da/redsync/mutex.go#L130-L145
14,392
hjr265/redsync.go
redsync/mutex.go
NewWithGenericPool
func NewWithGenericPool(genericNodes []Pool) *RedSync { if len(genericNodes) == 0 { panic("redsync: genericNodes is empty") } return &RedSync{ pools: genericNodes, } }
go
func NewWithGenericPool(genericNodes []Pool) *RedSync { if len(genericNodes) == 0 { panic("redsync: genericNodes is empty") } return &RedSync{ pools: genericNodes, } }
[ "func", "NewWithGenericPool", "(", "genericNodes", "[", "]", "Pool", ")", "*", "RedSync", "{", "if", "len", "(", "genericNodes", ")", "==", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "&", "RedSync", "{", "pools", ":", "genericNodes", ",", "}", "\n", "}" ]
// NewWithGenericPool creates and returns a new RedSync instance from given generic Pools.
[ "NewWithGenericPool", "creates", "and", "returns", "a", "new", "RedSync", "instance", "from", "given", "generic", "Pools", "." ]
688f6d364b799fa311a6de70b2bb9a4a669221da
https://github.com/hjr265/redsync.go/blob/688f6d364b799fa311a6de70b2bb9a4a669221da/redsync/mutex.go#L148-L156
14,393
hjr265/redsync.go
redsync/mutex.go
NewMutex
func (r *RedSync) NewMutex(name string) *Mutex { return &Mutex{ Name: name, Quorum: len(r.pools)/2 + 1, nodes: r.pools, } }
go
func (r *RedSync) NewMutex(name string) *Mutex { return &Mutex{ Name: name, Quorum: len(r.pools)/2 + 1, nodes: r.pools, } }
[ "func", "(", "r", "*", "RedSync", ")", "NewMutex", "(", "name", "string", ")", "*", "Mutex", "{", "return", "&", "Mutex", "{", "Name", ":", "name", ",", "Quorum", ":", "len", "(", "r", ".", "pools", ")", "/", "2", "+", "1", ",", "nodes", ":", "r", ".", "pools", ",", "}", "\n", "}" ]
// NewMutex returns a new Mutex with the given name.
[ "NewMutex", "returns", "a", "new", "Mutex", "with", "the", "given", "name", "." ]
688f6d364b799fa311a6de70b2bb9a4a669221da
https://github.com/hjr265/redsync.go/blob/688f6d364b799fa311a6de70b2bb9a4a669221da/redsync/mutex.go#L159-L165
14,394
hjr265/redsync.go
redsync/mutex.go
Touch
func (m *Mutex) Touch() bool { m.nodem.Lock() defer m.nodem.Unlock() value := m.value if value == "" { panic("redsync: touch of unlocked mutex") } expiry := m.Expiry if expiry == 0 { expiry = DefaultExpiry } reset := int(expiry / time.Millisecond) n := 0 for _, node := range m.nodes { if node == nil { continue } conn := node.Get() reply, err := touchScript.Do(conn, m.Name, value, reset) conn.Close() if err != nil { continue } if reply != "OK" { continue } n++ } if n >= m.Quorum { return true } return false }
go
func (m *Mutex) Touch() bool { m.nodem.Lock() defer m.nodem.Unlock() value := m.value if value == "" { panic("redsync: touch of unlocked mutex") } expiry := m.Expiry if expiry == 0 { expiry = DefaultExpiry } reset := int(expiry / time.Millisecond) n := 0 for _, node := range m.nodes { if node == nil { continue } conn := node.Get() reply, err := touchScript.Do(conn, m.Name, value, reset) conn.Close() if err != nil { continue } if reply != "OK" { continue } n++ } if n >= m.Quorum { return true } return false }
[ "func", "(", "m", "*", "Mutex", ")", "Touch", "(", ")", "bool", "{", "m", ".", "nodem", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "nodem", ".", "Unlock", "(", ")", "\n\n", "value", ":=", "m", ".", "value", "\n", "if", "value", "==", "\"", "\"", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "expiry", ":=", "m", ".", "Expiry", "\n", "if", "expiry", "==", "0", "{", "expiry", "=", "DefaultExpiry", "\n", "}", "\n", "reset", ":=", "int", "(", "expiry", "/", "time", ".", "Millisecond", ")", "\n\n", "n", ":=", "0", "\n", "for", "_", ",", "node", ":=", "range", "m", ".", "nodes", "{", "if", "node", "==", "nil", "{", "continue", "\n", "}", "\n\n", "conn", ":=", "node", ".", "Get", "(", ")", "\n", "reply", ",", "err", ":=", "touchScript", ".", "Do", "(", "conn", ",", "m", ".", "Name", ",", "value", ",", "reset", ")", "\n", "conn", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "continue", "\n", "}", "\n", "if", "reply", "!=", "\"", "\"", "{", "continue", "\n", "}", "\n", "n", "++", "\n", "}", "\n", "if", "n", ">=", "m", ".", "Quorum", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Touch resets m's expiry to the expiry value. // It is a run-time error if m is not locked on entry to Touch. // It returns the status of the touch
[ "Touch", "resets", "m", "s", "expiry", "to", "the", "expiry", "value", ".", "It", "is", "a", "run", "-", "time", "error", "if", "m", "is", "not", "locked", "on", "entry", "to", "Touch", ".", "It", "returns", "the", "status", "of", "the", "touch" ]
688f6d364b799fa311a6de70b2bb9a4a669221da
https://github.com/hjr265/redsync.go/blob/688f6d364b799fa311a6de70b2bb9a4a669221da/redsync/mutex.go#L252-L288
14,395
hjr265/redsync.go
redsync/mutex.go
Unlock
func (m *Mutex) Unlock() bool { m.nodem.Lock() defer m.nodem.Unlock() value := m.value if value == "" { panic("redsync: unlock of unlocked mutex") } m.value = "" m.until = time.Unix(0, 0) n := 0 for _, node := range m.nodes { if node == nil { continue } conn := node.Get() status, err := delScript.Do(conn, m.Name, value) conn.Close() if err != nil { continue } if status == 0 { continue } n++ } if n >= m.Quorum { return true } return false }
go
func (m *Mutex) Unlock() bool { m.nodem.Lock() defer m.nodem.Unlock() value := m.value if value == "" { panic("redsync: unlock of unlocked mutex") } m.value = "" m.until = time.Unix(0, 0) n := 0 for _, node := range m.nodes { if node == nil { continue } conn := node.Get() status, err := delScript.Do(conn, m.Name, value) conn.Close() if err != nil { continue } if status == 0 { continue } n++ } if n >= m.Quorum { return true } return false }
[ "func", "(", "m", "*", "Mutex", ")", "Unlock", "(", ")", "bool", "{", "m", ".", "nodem", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "nodem", ".", "Unlock", "(", ")", "\n\n", "value", ":=", "m", ".", "value", "\n", "if", "value", "==", "\"", "\"", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "m", ".", "value", "=", "\"", "\"", "\n", "m", ".", "until", "=", "time", ".", "Unix", "(", "0", ",", "0", ")", "\n\n", "n", ":=", "0", "\n", "for", "_", ",", "node", ":=", "range", "m", ".", "nodes", "{", "if", "node", "==", "nil", "{", "continue", "\n", "}", "\n\n", "conn", ":=", "node", ".", "Get", "(", ")", "\n", "status", ",", "err", ":=", "delScript", ".", "Do", "(", "conn", ",", "m", ".", "Name", ",", "value", ")", "\n", "conn", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "continue", "\n", "}", "\n", "if", "status", "==", "0", "{", "continue", "\n", "}", "\n", "n", "++", "\n", "}", "\n", "if", "n", ">=", "m", ".", "Quorum", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Unlock unlocks m. // It is a run-time error if m is not locked on entry to Unlock. // It returns the status of the unlock
[ "Unlock", "unlocks", "m", ".", "It", "is", "a", "run", "-", "time", "error", "if", "m", "is", "not", "locked", "on", "entry", "to", "Unlock", ".", "It", "returns", "the", "status", "of", "the", "unlock" ]
688f6d364b799fa311a6de70b2bb9a4a669221da
https://github.com/hjr265/redsync.go/blob/688f6d364b799fa311a6de70b2bb9a4a669221da/redsync/mutex.go#L293-L326
14,396
ardielle/ardielle-go
rdl/equal.go
Equal
func Equal(val1 interface{}, val2 interface{}) bool { if val1 == nil || val2 == nil { return false } switch v1 := val1.(type) { case UUID: if v2, ok := val2.(UUID); ok { return v1.Equal(v2) } return false case Timestamp: if v2, ok := val2.(Timestamp); ok { return v1.Equal(v2) } return false case Array: if v2, ok := val2.(Array); ok { return v1.Equal(v2) } return false case Struct: if v2, ok := val2.(Struct); ok { return v1.Equal(v2) } return false case Symbol: if v2, ok := val2.(Symbol); ok { return v1 == v2 } return false case int, int32, int8, int16, int64, float32, float64, uint, uint8, uint16, uint32, uint64: return val1 == val2 case bool: return val1 == val2 case string: if v2, ok := val2.(string); ok { return v1 == v2 } return false case []byte: if v2, ok := val2.([]byte); ok { return bytes.Compare(v1, v2) == 0 } return false default: fmt.Println(val1) fmt.Println(val2) fmt.Println("fix Equal of these two types") panic("fix Equal of these two types") } }
go
func Equal(val1 interface{}, val2 interface{}) bool { if val1 == nil || val2 == nil { return false } switch v1 := val1.(type) { case UUID: if v2, ok := val2.(UUID); ok { return v1.Equal(v2) } return false case Timestamp: if v2, ok := val2.(Timestamp); ok { return v1.Equal(v2) } return false case Array: if v2, ok := val2.(Array); ok { return v1.Equal(v2) } return false case Struct: if v2, ok := val2.(Struct); ok { return v1.Equal(v2) } return false case Symbol: if v2, ok := val2.(Symbol); ok { return v1 == v2 } return false case int, int32, int8, int16, int64, float32, float64, uint, uint8, uint16, uint32, uint64: return val1 == val2 case bool: return val1 == val2 case string: if v2, ok := val2.(string); ok { return v1 == v2 } return false case []byte: if v2, ok := val2.([]byte); ok { return bytes.Compare(v1, v2) == 0 } return false default: fmt.Println(val1) fmt.Println(val2) fmt.Println("fix Equal of these two types") panic("fix Equal of these two types") } }
[ "func", "Equal", "(", "val1", "interface", "{", "}", ",", "val2", "interface", "{", "}", ")", "bool", "{", "if", "val1", "==", "nil", "||", "val2", "==", "nil", "{", "return", "false", "\n", "}", "\n", "switch", "v1", ":=", "val1", ".", "(", "type", ")", "{", "case", "UUID", ":", "if", "v2", ",", "ok", ":=", "val2", ".", "(", "UUID", ")", ";", "ok", "{", "return", "v1", ".", "Equal", "(", "v2", ")", "\n", "}", "\n", "return", "false", "\n", "case", "Timestamp", ":", "if", "v2", ",", "ok", ":=", "val2", ".", "(", "Timestamp", ")", ";", "ok", "{", "return", "v1", ".", "Equal", "(", "v2", ")", "\n", "}", "\n", "return", "false", "\n", "case", "Array", ":", "if", "v2", ",", "ok", ":=", "val2", ".", "(", "Array", ")", ";", "ok", "{", "return", "v1", ".", "Equal", "(", "v2", ")", "\n", "}", "\n", "return", "false", "\n", "case", "Struct", ":", "if", "v2", ",", "ok", ":=", "val2", ".", "(", "Struct", ")", ";", "ok", "{", "return", "v1", ".", "Equal", "(", "v2", ")", "\n", "}", "\n", "return", "false", "\n", "case", "Symbol", ":", "if", "v2", ",", "ok", ":=", "val2", ".", "(", "Symbol", ")", ";", "ok", "{", "return", "v1", "==", "v2", "\n", "}", "\n", "return", "false", "\n", "case", "int", ",", "int32", ",", "int8", ",", "int16", ",", "int64", ",", "float32", ",", "float64", ",", "uint", ",", "uint8", ",", "uint16", ",", "uint32", ",", "uint64", ":", "return", "val1", "==", "val2", "\n", "case", "bool", ":", "return", "val1", "==", "val2", "\n", "case", "string", ":", "if", "v2", ",", "ok", ":=", "val2", ".", "(", "string", ")", ";", "ok", "{", "return", "v1", "==", "v2", "\n", "}", "\n", "return", "false", "\n", "case", "[", "]", "byte", ":", "if", "v2", ",", "ok", ":=", "val2", ".", "(", "[", "]", "byte", ")", ";", "ok", "{", "return", "bytes", ".", "Compare", "(", "v1", ",", "v2", ")", "==", "0", "\n", "}", "\n", "return", "false", "\n", "default", ":", "fmt", ".", "Println", "(", "val1", ")", "\n", "fmt", ".", "Println", "(", "val2", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// //Equal - Return true if the two values are equivalent, in the RDL sense. //
[ "Equal", "-", "Return", "true", "if", "the", "two", "values", "are", "equivalent", "in", "the", "RDL", "sense", "." ]
c4ab435c6f1ae2ece59bdd174b5b27c4f9828cff
https://github.com/ardielle/ardielle-go/blob/c4ab435c6f1ae2ece59bdd174b5b27c4f9828cff/rdl/equal.go#L16-L66
14,397
ardielle/ardielle-go
rdl/codegen/generator.go
main
func main() { p := params{Timestamp: time.Now(), Name: "codegen"} for i := 0; i < numTypes; i++ { p.StringTypeNames = append(p.StringTypeNames, fmt.Sprintf("Test%03d", i)) } baseDir, err := os.Getwd() die(err) baseDir = filepath.Join(baseDir, "..") fmt.Printf("Generating test files in %v\n", filepath.Join(baseDir, "_gen")) apath := filepath.Join(baseDir, "_gen", "A") _ = os.MkdirAll(apath, 0755) instantiateTemplate(modelTemplate, p, filepath.Join(apath, "codegen_model.go")) instantiateTemplate(schemaTemplate, p, filepath.Join(apath, "codegen_schema.go")) instantiateTemplate(dataTemplate, p, filepath.Join(apath, "codegen_data.go")) }
go
func main() { p := params{Timestamp: time.Now(), Name: "codegen"} for i := 0; i < numTypes; i++ { p.StringTypeNames = append(p.StringTypeNames, fmt.Sprintf("Test%03d", i)) } baseDir, err := os.Getwd() die(err) baseDir = filepath.Join(baseDir, "..") fmt.Printf("Generating test files in %v\n", filepath.Join(baseDir, "_gen")) apath := filepath.Join(baseDir, "_gen", "A") _ = os.MkdirAll(apath, 0755) instantiateTemplate(modelTemplate, p, filepath.Join(apath, "codegen_model.go")) instantiateTemplate(schemaTemplate, p, filepath.Join(apath, "codegen_schema.go")) instantiateTemplate(dataTemplate, p, filepath.Join(apath, "codegen_data.go")) }
[ "func", "main", "(", ")", "{", "p", ":=", "params", "{", "Timestamp", ":", "time", ".", "Now", "(", ")", ",", "Name", ":", "\"", "\"", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "numTypes", ";", "i", "++", "{", "p", ".", "StringTypeNames", "=", "append", "(", "p", ".", "StringTypeNames", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "i", ")", ")", "\n", "}", "\n\n", "baseDir", ",", "err", ":=", "os", ".", "Getwd", "(", ")", "\n", "die", "(", "err", ")", "\n", "baseDir", "=", "filepath", ".", "Join", "(", "baseDir", ",", "\"", "\"", ")", "\n\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "filepath", ".", "Join", "(", "baseDir", ",", "\"", "\"", ")", ")", "\n", "apath", ":=", "filepath", ".", "Join", "(", "baseDir", ",", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "_", "=", "os", ".", "MkdirAll", "(", "apath", ",", "0755", ")", "\n\n", "instantiateTemplate", "(", "modelTemplate", ",", "p", ",", "filepath", ".", "Join", "(", "apath", ",", "\"", "\"", ")", ")", "\n", "instantiateTemplate", "(", "schemaTemplate", ",", "p", ",", "filepath", ".", "Join", "(", "apath", ",", "\"", "\"", ")", ")", "\n", "instantiateTemplate", "(", "dataTemplate", ",", "p", ",", "filepath", ".", "Join", "(", "apath", ",", "\"", "\"", ")", ")", "\n", "}" ]
// Quick example that demonstrates a benchmark between different implementations // of Validator
[ "Quick", "example", "that", "demonstrates", "a", "benchmark", "between", "different", "implementations", "of", "Validator" ]
c4ab435c6f1ae2ece59bdd174b5b27c4f9828cff
https://github.com/ardielle/ardielle-go/blob/c4ab435c6f1ae2ece59bdd174b5b27c4f9828cff/rdl/codegen/generator.go#L25-L43
14,398
ardielle/ardielle-go
gen/gomodel/goschema.go
GenerateGoSchema
func GenerateGoSchema(banner string, schema *rdl.Schema, outdir string, ns string, librdl string, prefixEnums bool) error { name := strings.ToLower(string(schema.Name)) if strings.HasSuffix(outdir, ".go") { name = filepath.Base(outdir) outdir = filepath.Dir(outdir) } else { name = name + "_schema.go" } err := os.MkdirAll(outdir, 0755) if err != nil { return err } filepath := outdir + "/" + name out, file, _, err := genutil.OutputWriter(filepath, "", ".go") if err != nil { return err } if file != nil { defer func() { file.Close() err := goFmt(filepath) if err != nil { fmt.Println("Warning: could not format go code:", err) } }() } rdlprefix := "rdl." if schema.Name == "rdl" { rdlprefix = "" } gen := &schemaGenerator{rdl.NewTypeRegistry(schema), schema, capitalize(string(schema.Name)), out, nil, banner, ns, librdl, rdlprefix, prefixEnums} gen.emit(GenerationHeader(banner)) gen.emit("\n\npackage " + GenerationPackage(gen.schema, gen.ns) + "\n\n") gen.emit("import (\n") gen.emit("\t\"log\"\n") gen.emit("\n") if gen.schema.Name != "rdl" { gen.emit("\trdl \"" + librdl + "\"\n") } gen.emit(")\n\n") gen.emit("var schema *" + rdlprefix + "Schema\n\n") gen.emit(fmt.Sprintf("func init() {\n\tsb := %sNewSchemaBuilder(%q)\n", rdlprefix, schema.Name)) if schema.Version != nil { gen.emit(fmt.Sprintf("\tsb.Version(%d)\n", *schema.Version)) } if schema.Namespace != "" { gen.emit(fmt.Sprintf("\tsb.Namespace(%q)\n", schema.Namespace)) } if schema.Comment != "" { gen.emit(fmt.Sprintf("\tsb.Comment(%q)\n", schema.Comment)) } gen.emit("\n") if gen.err == nil { for _, t := range schema.Types { gen.emitType(t) } } if gen.err == nil { for _, r := range schema.Resources { gen.emitResource(r) } } gen.emit("\tvar err error\n") gen.emit("\tschema, err = sb.BuildParanoid()\n") gen.emit("\tif err != nil {\n") gen.emit("\t log.Fatalf(\"rdl: schema build failed: %s\", err)") gen.emit("\t}\n") gen.emit("}\n\n") gen.emit(fmt.Sprintf("func %sSchema() *%sSchema {\n", capitalize(string(schema.Name)), rdlprefix)) gen.emit("\treturn schema\n") gen.emit("}\n") out.Flush() return gen.err }
go
func GenerateGoSchema(banner string, schema *rdl.Schema, outdir string, ns string, librdl string, prefixEnums bool) error { name := strings.ToLower(string(schema.Name)) if strings.HasSuffix(outdir, ".go") { name = filepath.Base(outdir) outdir = filepath.Dir(outdir) } else { name = name + "_schema.go" } err := os.MkdirAll(outdir, 0755) if err != nil { return err } filepath := outdir + "/" + name out, file, _, err := genutil.OutputWriter(filepath, "", ".go") if err != nil { return err } if file != nil { defer func() { file.Close() err := goFmt(filepath) if err != nil { fmt.Println("Warning: could not format go code:", err) } }() } rdlprefix := "rdl." if schema.Name == "rdl" { rdlprefix = "" } gen := &schemaGenerator{rdl.NewTypeRegistry(schema), schema, capitalize(string(schema.Name)), out, nil, banner, ns, librdl, rdlprefix, prefixEnums} gen.emit(GenerationHeader(banner)) gen.emit("\n\npackage " + GenerationPackage(gen.schema, gen.ns) + "\n\n") gen.emit("import (\n") gen.emit("\t\"log\"\n") gen.emit("\n") if gen.schema.Name != "rdl" { gen.emit("\trdl \"" + librdl + "\"\n") } gen.emit(")\n\n") gen.emit("var schema *" + rdlprefix + "Schema\n\n") gen.emit(fmt.Sprintf("func init() {\n\tsb := %sNewSchemaBuilder(%q)\n", rdlprefix, schema.Name)) if schema.Version != nil { gen.emit(fmt.Sprintf("\tsb.Version(%d)\n", *schema.Version)) } if schema.Namespace != "" { gen.emit(fmt.Sprintf("\tsb.Namespace(%q)\n", schema.Namespace)) } if schema.Comment != "" { gen.emit(fmt.Sprintf("\tsb.Comment(%q)\n", schema.Comment)) } gen.emit("\n") if gen.err == nil { for _, t := range schema.Types { gen.emitType(t) } } if gen.err == nil { for _, r := range schema.Resources { gen.emitResource(r) } } gen.emit("\tvar err error\n") gen.emit("\tschema, err = sb.BuildParanoid()\n") gen.emit("\tif err != nil {\n") gen.emit("\t log.Fatalf(\"rdl: schema build failed: %s\", err)") gen.emit("\t}\n") gen.emit("}\n\n") gen.emit(fmt.Sprintf("func %sSchema() *%sSchema {\n", capitalize(string(schema.Name)), rdlprefix)) gen.emit("\treturn schema\n") gen.emit("}\n") out.Flush() return gen.err }
[ "func", "GenerateGoSchema", "(", "banner", "string", ",", "schema", "*", "rdl", ".", "Schema", ",", "outdir", "string", ",", "ns", "string", ",", "librdl", "string", ",", "prefixEnums", "bool", ")", "error", "{", "name", ":=", "strings", ".", "ToLower", "(", "string", "(", "schema", ".", "Name", ")", ")", "\n", "if", "strings", ".", "HasSuffix", "(", "outdir", ",", "\"", "\"", ")", "{", "name", "=", "filepath", ".", "Base", "(", "outdir", ")", "\n", "outdir", "=", "filepath", ".", "Dir", "(", "outdir", ")", "\n", "}", "else", "{", "name", "=", "name", "+", "\"", "\"", "\n", "}", "\n", "err", ":=", "os", ".", "MkdirAll", "(", "outdir", ",", "0755", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "filepath", ":=", "outdir", "+", "\"", "\"", "+", "name", "\n", "out", ",", "file", ",", "_", ",", "err", ":=", "genutil", ".", "OutputWriter", "(", "filepath", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "file", "!=", "nil", "{", "defer", "func", "(", ")", "{", "file", ".", "Close", "(", ")", "\n", "err", ":=", "goFmt", "(", "filepath", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "(", ")", "\n", "}", "\n", "rdlprefix", ":=", "\"", "\"", "\n", "if", "schema", ".", "Name", "==", "\"", "\"", "{", "rdlprefix", "=", "\"", "\"", "\n", "}", "\n", "gen", ":=", "&", "schemaGenerator", "{", "rdl", ".", "NewTypeRegistry", "(", "schema", ")", ",", "schema", ",", "capitalize", "(", "string", "(", "schema", ".", "Name", ")", ")", ",", "out", ",", "nil", ",", "banner", ",", "ns", ",", "librdl", ",", "rdlprefix", ",", "prefixEnums", "}", "\n", "gen", ".", "emit", "(", "GenerationHeader", "(", "banner", ")", ")", "\n", "gen", ".", "emit", "(", "\"", "\\n", "\\n", "\"", "+", "GenerationPackage", "(", "gen", ".", "schema", ",", "gen", ".", "ns", ")", "+", "\"", "\\n", "\\n", "\"", ")", "\n", "gen", ".", "emit", "(", "\"", "\\n", "\"", ")", "\n", "gen", ".", "emit", "(", "\"", "\\t", "\\\"", "\\\"", "\\n", "\"", ")", "\n", "gen", ".", "emit", "(", "\"", "\\n", "\"", ")", "\n", "if", "gen", ".", "schema", ".", "Name", "!=", "\"", "\"", "{", "gen", ".", "emit", "(", "\"", "\\t", "\\\"", "\"", "+", "librdl", "+", "\"", "\\\"", "\\n", "\"", ")", "\n", "}", "\n", "gen", ".", "emit", "(", "\"", "\\n", "\\n", "\"", ")", "\n", "gen", ".", "emit", "(", "\"", "\"", "+", "rdlprefix", "+", "\"", "\\n", "\\n", "\"", ")", "\n", "gen", ".", "emit", "(", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\\t", "\\n", "\"", ",", "rdlprefix", ",", "schema", ".", "Name", ")", ")", "\n", "if", "schema", ".", "Version", "!=", "nil", "{", "gen", ".", "emit", "(", "fmt", ".", "Sprintf", "(", "\"", "\\t", "\\n", "\"", ",", "*", "schema", ".", "Version", ")", ")", "\n", "}", "\n", "if", "schema", ".", "Namespace", "!=", "\"", "\"", "{", "gen", ".", "emit", "(", "fmt", ".", "Sprintf", "(", "\"", "\\t", "\\n", "\"", ",", "schema", ".", "Namespace", ")", ")", "\n", "}", "\n", "if", "schema", ".", "Comment", "!=", "\"", "\"", "{", "gen", ".", "emit", "(", "fmt", ".", "Sprintf", "(", "\"", "\\t", "\\n", "\"", ",", "schema", ".", "Comment", ")", ")", "\n", "}", "\n", "gen", ".", "emit", "(", "\"", "\\n", "\"", ")", "\n", "if", "gen", ".", "err", "==", "nil", "{", "for", "_", ",", "t", ":=", "range", "schema", ".", "Types", "{", "gen", ".", "emitType", "(", "t", ")", "\n", "}", "\n", "}", "\n", "if", "gen", ".", "err", "==", "nil", "{", "for", "_", ",", "r", ":=", "range", "schema", ".", "Resources", "{", "gen", ".", "emitResource", "(", "r", ")", "\n", "}", "\n", "}", "\n", "gen", ".", "emit", "(", "\"", "\\t", "\\n", "\"", ")", "\n", "gen", ".", "emit", "(", "\"", "\\t", "\\n", "\"", ")", "\n", "gen", ".", "emit", "(", "\"", "\\t", "\\n", "\"", ")", "\n", "gen", ".", "emit", "(", "\"", "\\t", "\\\"", "\\\"", "\"", ")", "\n", "gen", ".", "emit", "(", "\"", "\\t", "\\n", "\"", ")", "\n", "gen", ".", "emit", "(", "\"", "\\n", "\\n", "\"", ")", "\n", "gen", ".", "emit", "(", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "capitalize", "(", "string", "(", "schema", ".", "Name", ")", ")", ",", "rdlprefix", ")", ")", "\n", "gen", ".", "emit", "(", "\"", "\\t", "\\n", "\"", ")", "\n", "gen", ".", "emit", "(", "\"", "\\n", "\"", ")", "\n", "out", ".", "Flush", "(", ")", "\n", "return", "gen", ".", "err", "\n", "}" ]
// GenerateGoSchema generates the code to regenerate the Schema
[ "GenerateGoSchema", "generates", "the", "code", "to", "regenerate", "the", "Schema" ]
c4ab435c6f1ae2ece59bdd174b5b27c4f9828cff
https://github.com/ardielle/ardielle-go/blob/c4ab435c6f1ae2ece59bdd174b5b27c4f9828cff/gen/gomodel/goschema.go#L32-L105
14,399
ardielle/ardielle-go
rdl/array.go
Equal
func (a Array) Equal(another Array) bool { if another == nil { return false } if len(a) != len(another) { return false } for i, v1 := range a { v2 := another[i] if !Equal(v1, v2) { return false } } return true }
go
func (a Array) Equal(another Array) bool { if another == nil { return false } if len(a) != len(another) { return false } for i, v1 := range a { v2 := another[i] if !Equal(v1, v2) { return false } } return true }
[ "func", "(", "a", "Array", ")", "Equal", "(", "another", "Array", ")", "bool", "{", "if", "another", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "len", "(", "a", ")", "!=", "len", "(", "another", ")", "{", "return", "false", "\n", "}", "\n", "for", "i", ",", "v1", ":=", "range", "a", "{", "v2", ":=", "another", "[", "i", "]", "\n", "if", "!", "Equal", "(", "v1", ",", "v2", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// // Equal - in RDL, arrays and structs can be compared. This Equal method does that. //
[ "Equal", "-", "in", "RDL", "arrays", "and", "structs", "can", "be", "compared", ".", "This", "Equal", "method", "does", "that", "." ]
c4ab435c6f1ae2ece59bdd174b5b27c4f9828cff
https://github.com/ardielle/ardielle-go/blob/c4ab435c6f1ae2ece59bdd174b5b27c4f9828cff/rdl/array.go#L14-L28