mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Tidy GetDockerOS() function
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
		
							parent
							
								
									9482da362c
								
							
						
					
					
						commit
						d8dcbf3ec3
					
				
					 4 changed files with 18 additions and 16 deletions
				
			
		| 
						 | 
				
			
			@ -21,6 +21,6 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, strea
 | 
			
		|||
		return types.ContainerStats{}, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	osType := GetDockerOS(resp.header.Get("Server"))
 | 
			
		||||
	osType := getDockerOS(resp.header.Get("Server"))
 | 
			
		||||
	return types.ContainerStats{Body: resp.body, OSType: osType}, err
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,6 @@ import (
 | 
			
		|||
	"io"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"net/url"
 | 
			
		||||
	"regexp"
 | 
			
		||||
	"strconv"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/net/context"
 | 
			
		||||
| 
						 | 
				
			
			@ -15,8 +14,6 @@ import (
 | 
			
		|||
	"github.com/docker/docker/api/types/container"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var headerRegexp = regexp.MustCompile(`\ADocker/.+\s\((.+)\)\z`)
 | 
			
		||||
 | 
			
		||||
// ImageBuild sends request to the daemon to build images.
 | 
			
		||||
// The Body in the response implement an io.ReadCloser and it's up to the caller to
 | 
			
		||||
// close it.
 | 
			
		||||
| 
						 | 
				
			
			@ -39,7 +36,7 @@ func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, optio
 | 
			
		|||
		return types.ImageBuildResponse{}, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	osType := GetDockerOS(serverResp.header.Get("Server"))
 | 
			
		||||
	osType := getDockerOS(serverResp.header.Get("Server"))
 | 
			
		||||
 | 
			
		||||
	return types.ImageBuildResponse{
 | 
			
		||||
		Body:   serverResp.body,
 | 
			
		||||
| 
						 | 
				
			
			@ -124,13 +121,3 @@ func (cli *Client) imageBuildOptionsToQuery(options types.ImageBuildOptions) (ur
 | 
			
		|||
 | 
			
		||||
	return query, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetDockerOS returns the operating system based on the server header from the daemon.
 | 
			
		||||
func GetDockerOS(serverHeader string) string {
 | 
			
		||||
	var osType string
 | 
			
		||||
	matches := headerRegexp.FindStringSubmatch(serverHeader)
 | 
			
		||||
	if len(matches) > 0 {
 | 
			
		||||
		osType = matches[1]
 | 
			
		||||
	}
 | 
			
		||||
	return osType
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -222,7 +222,7 @@ func TestGetDockerOS(t *testing.T) {
 | 
			
		|||
		"Foo/v1.22 (bar)":        "",
 | 
			
		||||
	}
 | 
			
		||||
	for header, os := range cases {
 | 
			
		||||
		g := GetDockerOS(header)
 | 
			
		||||
		g := getDockerOS(header)
 | 
			
		||||
		if g != os {
 | 
			
		||||
			t.Fatalf("Expected %s, got %s", os, g)
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										15
									
								
								client/utils.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								client/utils.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,15 @@
 | 
			
		|||
package client
 | 
			
		||||
 | 
			
		||||
import "regexp"
 | 
			
		||||
 | 
			
		||||
var headerRegexp = regexp.MustCompile(`\ADocker/.+\s\((.+)\)\z`)
 | 
			
		||||
 | 
			
		||||
// getDockerOS returns the operating system based on the server header from the daemon.
 | 
			
		||||
func getDockerOS(serverHeader string) string {
 | 
			
		||||
	var osType string
 | 
			
		||||
	matches := headerRegexp.FindStringSubmatch(serverHeader)
 | 
			
		||||
	if len(matches) > 0 {
 | 
			
		||||
		osType = matches[1]
 | 
			
		||||
	}
 | 
			
		||||
	return osType
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue