github.com/liuzhiyi/docker@v1.5.0/registry/httpfactory.go (about)

     1  package registry
     2  
     3  import (
     4  	"runtime"
     5  
     6  	"github.com/docker/docker/dockerversion"
     7  	"github.com/docker/docker/pkg/parsers/kernel"
     8  	"github.com/docker/docker/utils"
     9  )
    10  
    11  func HTTPRequestFactory(metaHeaders map[string][]string) *utils.HTTPRequestFactory {
    12  	// FIXME: this replicates the 'info' job.
    13  	httpVersion := make([]utils.VersionInfo, 0, 4)
    14  	httpVersion = append(httpVersion, &simpleVersionInfo{"docker", dockerversion.VERSION})
    15  	httpVersion = append(httpVersion, &simpleVersionInfo{"go", runtime.Version()})
    16  	httpVersion = append(httpVersion, &simpleVersionInfo{"git-commit", dockerversion.GITCOMMIT})
    17  	if kernelVersion, err := kernel.GetKernelVersion(); err == nil {
    18  		httpVersion = append(httpVersion, &simpleVersionInfo{"kernel", kernelVersion.String()})
    19  	}
    20  	httpVersion = append(httpVersion, &simpleVersionInfo{"os", runtime.GOOS})
    21  	httpVersion = append(httpVersion, &simpleVersionInfo{"arch", runtime.GOARCH})
    22  	ud := utils.NewHTTPUserAgentDecorator(httpVersion...)
    23  	md := &utils.HTTPMetaHeadersDecorator{
    24  		Headers: metaHeaders,
    25  	}
    26  	factory := utils.NewHTTPRequestFactory(ud, md)
    27  	return factory
    28  }
    29  
    30  // simpleVersionInfo is a simple implementation of
    31  // the interface VersionInfo, which is used
    32  // to provide version information for some product,
    33  // component, etc. It stores the product name and the version
    34  // in string and returns them on calls to Name() and Version().
    35  type simpleVersionInfo struct {
    36  	name    string
    37  	version string
    38  }
    39  
    40  func (v *simpleVersionInfo) Name() string {
    41  	return v.name
    42  }
    43  
    44  func (v *simpleVersionInfo) Version() string {
    45  	return v.version
    46  }