[Go language] learn go from Docker source

Source: Internet
Author: User
Tags goagent
This is a creation in Article, where the information may have evolved or changed.

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   "  ...) Func (S  *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)

Type Tagstorestruct{PathstringGraph*Graph repositories map[string]repository sync. Mutex//fixme:move push/pull-related fields//To a helper typePullingpool map[string]chanstruct{} pushingpool map[string]chanstruct{}}

Defines a structure with a type named Tagstore.

Store: = &tagstore{Path:abspath, Graph:graph, Repositories:make (map[string]repository), Pullingpool:make (map[string]chanstruct{}), Pushingpool:make (map[string]chanstruct{}),    }

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.