Docker has been very hot lately, and-go, the development language of Docker, has been mentioned again.
Docker has been used for some time, but for the source code, especially its development language go has been smattering.
Recently you are ready to use your free time to learn about go from the Docker source code, while the implementation of Docker also hopes to improve one level.
Interested can discuss and study together.
Preparatory work:
1. Docker source code Https://github.com/docker/docker (version 1.1.2)
2. Install Development tools Liteide, this is the official go language IDE
3. Go Language official website http://golang.org/(now This has been wall, if want to visit, can through VPN or goagent to realize, online can search many about goagent configuration, this does not elaborate)
Docker command
Docker pull xxx//Download the image command.
The corresponding go file
Docker/graph/pull.go
Explain the code
Import ( ..... " Github.com/docker/docker/engine " *tagstore) Cmdpull (Job *engine. JOB) engine. Status {
(s *tagstore) This means defining a method for type Tagstore, named Cmdpull.
Job *engine. The JOB is the input parameter of the method, and the type is engine. Job
Engine. Status is the return parameter of the method, and the type is engine. Status
The above is designed to 3 types, but Tagstore is used directly, while job and status are obtained by means of the engine.
Because the Tagstore is in the same package as the current method, it is the package graph
And the job and status are under the package engine (DOCKER/ENGINE/JOB.GO), so with the packet name, and the need to import the corresponding file through the Imports
Tagstore definition of this structure (DOCKER/GRAPH/TAGS.GO)
struct { path string graph *graph repositories map[string ]repository sync. Mutex // fixme:move push/pull-related fields// to a helper Type pullingpool map[stringstruct{} pushingpool map[string struct{}}
Defines a structure with a type named Tagstore.
Store: = &tagstore{ path: abspath, graph: graph, repositories:make (map[ String]repository), pullingpool: Make (map[stringstruct{}), Pushingpool: Make (map[stringstruct{}), }
Declare and define (using ": =") A variable of type Tagstore, and the variable name is store.
Review:
1. Explain the definition of the function
2. Explains the definition and initialization of a struct
This is the first to say so much, because of energy and time is limited, so the basic use of what to write, not as many tutorials as detailed.
There is no understanding of the place also need to find their own information, you can also comment directly to discuss together.