Docker Swarm代码分析笔记(1)——main.go

main.go代码如下:

package main

import (
    _ "github.com/docker/docker/pkg/discovery/file"
    _ "github.com/docker/docker/pkg/discovery/kv"
    _ "github.com/docker/docker/pkg/discovery/nodes"
    _ "github.com/docker/swarm/discovery/token"

    "github.com/docker/swarm/cli"
)

func main() {
    cli.Run()
}

以下4行代码保证相应packageinit函数可以执行:

_ "github.com/docker/docker/pkg/discovery/file"
_ "github.com/docker/docker/pkg/discovery/kv"
_ "github.com/docker/docker/pkg/discovery/nodes"
_ "github.com/docker/swarm/discovery/token"

只有token这个packageswarm新实现的,其余filekvnodes都是docker现有的。

cli package利用github.com/codegangsta/cli这个project构建CLI程序。而cli.Run()函数则会执行swarm具体的commandcreatemanage等等)。