mirror of
https://github.com/moby/moby.git
synced 2026-08-08 09:01:44 +00:00
Lintify code with confidence=1
This commit is contained in:
@@ -81,12 +81,12 @@ func NewHTTPUserAgentDecorator(versions ...VersionInfo) HTTPRequestDecorator {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *HTTPUserAgentDecorator) ChangeRequest(req *http.Request) (newReq *http.Request, err error) {
|
||||
func (h *HTTPUserAgentDecorator) ChangeRequest(req *http.Request) (newReq *http.Request, err error) {
|
||||
if req == nil {
|
||||
return req, nil
|
||||
}
|
||||
|
||||
userAgent := appendVersions(req.UserAgent(), self.versions...)
|
||||
userAgent := appendVersions(req.UserAgent(), h.versions...)
|
||||
if len(userAgent) > 0 {
|
||||
req.Header.Set("User-Agent", userAgent)
|
||||
}
|
||||
@@ -97,11 +97,11 @@ type HTTPMetaHeadersDecorator struct {
|
||||
Headers map[string][]string
|
||||
}
|
||||
|
||||
func (self *HTTPMetaHeadersDecorator) ChangeRequest(req *http.Request) (newReq *http.Request, err error) {
|
||||
if self.Headers == nil {
|
||||
func (h *HTTPMetaHeadersDecorator) ChangeRequest(req *http.Request) (newReq *http.Request, err error) {
|
||||
if h.Headers == nil {
|
||||
return req, nil
|
||||
}
|
||||
for k, v := range self.Headers {
|
||||
for k, v := range h.Headers {
|
||||
req.Header[k] = v
|
||||
}
|
||||
return req, nil
|
||||
@@ -114,25 +114,25 @@ type HTTPRequestFactory struct {
|
||||
}
|
||||
|
||||
func NewHTTPRequestFactory(d ...HTTPRequestDecorator) *HTTPRequestFactory {
|
||||
ret := new(HTTPRequestFactory)
|
||||
ret.decorators = d
|
||||
return ret
|
||||
return &HTTPRequestFactory{
|
||||
decorators: d,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRequest() creates a new *http.Request,
|
||||
// applies all decorators in the HTTPRequestFactory on the request,
|
||||
// then applies decorators provided by d on the request.
|
||||
func (self *HTTPRequestFactory) NewRequest(method, urlStr string, body io.Reader, d ...HTTPRequestDecorator) (*http.Request, error) {
|
||||
func (h *HTTPRequestFactory) NewRequest(method, urlStr string, body io.Reader, d ...HTTPRequestDecorator) (*http.Request, error) {
|
||||
req, err := http.NewRequest(method, urlStr, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// By default, a nil factory should work.
|
||||
if self == nil {
|
||||
if h == nil {
|
||||
return req, nil
|
||||
}
|
||||
for _, dec := range self.decorators {
|
||||
for _, dec := range h.decorators {
|
||||
req, err = dec.ChangeRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1123,7 +1123,7 @@ func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error) {
|
||||
for len(processed) < len(graph.nodes) {
|
||||
// Use a temporary buffer for processed nodes, otherwise
|
||||
// nodes that depend on each other could end up in the same round.
|
||||
tmp_processed := []*DependencyNode{}
|
||||
tmpProcessed := []*DependencyNode{}
|
||||
for _, node := range graph.nodes {
|
||||
// If the node has more dependencies than what we have cleared,
|
||||
// it won't be valid for this round.
|
||||
@@ -1137,7 +1137,7 @@ func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error) {
|
||||
// It's not been processed yet and has 0 deps. Add it!
|
||||
// (this is a shortcut for what we're doing below)
|
||||
if node.Degree() == 0 {
|
||||
tmp_processed = append(tmp_processed, node)
|
||||
tmpProcessed = append(tmpProcessed, node)
|
||||
continue
|
||||
}
|
||||
// If at least one dep hasn't been processed yet, we can't
|
||||
@@ -1151,17 +1151,17 @@ func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error) {
|
||||
}
|
||||
// All deps have already been processed. Add it!
|
||||
if ok {
|
||||
tmp_processed = append(tmp_processed, node)
|
||||
tmpProcessed = append(tmpProcessed, node)
|
||||
}
|
||||
}
|
||||
Debugf("Round %d: found %d available nodes", len(result), len(tmp_processed))
|
||||
Debugf("Round %d: found %d available nodes", len(result), len(tmpProcessed))
|
||||
// If no progress has been made this round,
|
||||
// that means we have circular dependencies.
|
||||
if len(tmp_processed) == 0 {
|
||||
if len(tmpProcessed) == 0 {
|
||||
return nil, fmt.Errorf("Could not find a solution to this dependency graph")
|
||||
}
|
||||
round := []string{}
|
||||
for _, nd := range tmp_processed {
|
||||
for _, nd := range tmpProcessed {
|
||||
round = append(round, nd.id)
|
||||
processed[nd] = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user