From 325c5cd47e308f11b7e64cb751da218897e5001b Mon Sep 17 00:00:00 2001 From: Yuki Yugui Sonoda Date: Tue, 8 Jul 2014 16:15:41 +0900 Subject: [PATCH] Fixes golint errors in pkg/client --- pkg/client/client.go | 66 ++++++++++++++++++++------------------ pkg/client/client_test.go | 4 +-- pkg/client/podinfo.go | 6 ++-- pkg/client/podinfo_test.go | 4 +-- pkg/client/request.go | 38 +++++++++++----------- 5 files changed, 61 insertions(+), 57 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 44dba849003..fa7856f1a62 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -75,7 +75,7 @@ type Client struct { Timeout time.Duration } -// Create a new client object. +// New creates a new client object. func New(host string, auth *AuthInfo) *Client { return &Client{ auth: auth, @@ -159,79 +159,81 @@ func (c *Client) rawRequest(method, path string, requestBody io.Reader, target i return body, err } -func (client *Client) makeURL(path string) string { - return client.host + "/api/v1beta1/" + path +func (c *Client) makeURL(path string) string { + return c.host + "/api/v1beta1/" + path } // ListPods takes a selector, and returns the list of pods that match that selector -func (client *Client) ListPods(selector labels.Selector) (result api.PodList, err error) { - err = client.Get().Path("pods").Selector(selector).Do().Into(&result) +func (c *Client) ListPods(selector labels.Selector) (result api.PodList, err error) { + err = c.Get().Path("pods").Selector(selector).Do().Into(&result) return } // GetPod takes the name of the pod, and returns the corresponding Pod object, and an error if it occurs -func (client *Client) GetPod(name string) (result api.Pod, err error) { - err = client.Get().Path("pods").Path(name).Do().Into(&result) +func (c *Client) GetPod(name string) (result api.Pod, err error) { + err = c.Get().Path("pods").Path(name).Do().Into(&result) return } // DeletePod takes the name of the pod, and returns an error if one occurs -func (client *Client) DeletePod(name string) error { - return client.Delete().Path("pods").Path(name).Do().Error() +func (c *Client) DeletePod(name string) error { + return c.Delete().Path("pods").Path(name).Do().Error() } // CreatePod takes the representation of a pod. Returns the server's representation of the pod, and an error, if it occurs -func (client *Client) CreatePod(pod api.Pod) (result api.Pod, err error) { - err = client.Post().Path("pods").Body(pod).Do().Into(&result) +func (c *Client) CreatePod(pod api.Pod) (result api.Pod, err error) { + err = c.Post().Path("pods").Body(pod).Do().Into(&result) return } // UpdatePod takes the representation of a pod to update. Returns the server's representation of the pod, and an error, if it occurs -func (client *Client) UpdatePod(pod api.Pod) (result api.Pod, err error) { - err = client.Put().Path("pods").Path(pod.ID).Body(pod).Do().Into(&result) +func (c *Client) UpdatePod(pod api.Pod) (result api.Pod, err error) { + err = c.Put().Path("pods").Path(pod.ID).Body(pod).Do().Into(&result) return } // GetReplicationController returns information about a particular replication controller -func (client *Client) GetReplicationController(name string) (result api.ReplicationController, err error) { - err = client.Get().Path("replicationControllers").Path(name).Do().Into(&result) +func (c *Client) GetReplicationController(name string) (result api.ReplicationController, err error) { + err = c.Get().Path("replicationControllers").Path(name).Do().Into(&result) return } // CreateReplicationController creates a new replication controller -func (client *Client) CreateReplicationController(controller api.ReplicationController) (result api.ReplicationController, err error) { - err = client.Post().Path("replicationControllers").Body(controller).Do().Into(&result) +func (c *Client) CreateReplicationController(controller api.ReplicationController) (result api.ReplicationController, err error) { + err = c.Post().Path("replicationControllers").Body(controller).Do().Into(&result) return } // UpdateReplicationController updates an existing replication controller -func (client *Client) UpdateReplicationController(controller api.ReplicationController) (result api.ReplicationController, err error) { - err = client.Put().Path("replicationControllers").Path(controller.ID).Body(controller).Do().Into(&result) +func (c *Client) UpdateReplicationController(controller api.ReplicationController) (result api.ReplicationController, err error) { + err = c.Put().Path("replicationControllers").Path(controller.ID).Body(controller).Do().Into(&result) return } -func (client *Client) DeleteReplicationController(name string) error { - return client.Delete().Path("replicationControllers").Path(name).Do().Error() +// DeleteReplicationController deletes an existing replication controller. +func (c *Client) DeleteReplicationController(name string) error { + return c.Delete().Path("replicationControllers").Path(name).Do().Error() } -// GetReplicationController returns information about a particular replication controller -func (client *Client) GetService(name string) (result api.Service, err error) { - err = client.Get().Path("services").Path(name).Do().Into(&result) +// GetService returns information about a particular service. +func (c *Client) GetService(name string) (result api.Service, err error) { + err = c.Get().Path("services").Path(name).Do().Into(&result) return } -// CreateReplicationController creates a new replication controller -func (client *Client) CreateService(svc api.Service) (result api.Service, err error) { - err = client.Post().Path("services").Body(svc).Do().Into(&result) +// CreateService creates a new service. +func (c *Client) CreateService(svc api.Service) (result api.Service, err error) { + err = c.Post().Path("services").Body(svc).Do().Into(&result) return } -// UpdateReplicationController updates an existing replication controller -func (client *Client) UpdateService(svc api.Service) (result api.Service, err error) { - err = client.Put().Path("services").Path(svc.ID).Body(svc).Do().Into(&result) +// UpdateService updates an existing service. +func (c *Client) UpdateService(svc api.Service) (result api.Service, err error) { + err = c.Put().Path("services").Path(svc.ID).Body(svc).Do().Into(&result) return } -func (client *Client) DeleteService(name string) error { - return client.Delete().Path("services").Path(name).Do().Error() +// DeleteService deletes an existing service. +func (c *Client) DeleteService(name string) error { + return c.Delete().Path("services").Path(name).Do().Error() } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 0fc4b172a4b..edc206acd65 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -31,7 +31,7 @@ import ( // TODO: Move this to a common place, it's needed in multiple tests. var apiPath = "/api/v1beta1" -func makeUrl(suffix string) string { +func makeURL(suffix string) string { return apiPath + suffix } @@ -326,7 +326,7 @@ func (c *testClient) Validate(t *testing.T, received interface{}, err error) { } requestBody := body(c.Request.Body, c.Request.RawBody) - c.handler.ValidateRequest(t, makeUrl(c.Request.Path), c.Request.Method, requestBody) + c.handler.ValidateRequest(t, makeURL(c.Request.Path), c.Request.Method, requestBody) for key, values := range c.Request.Query { validator, ok := c.QueryValidator[key] if !ok { diff --git a/pkg/client/podinfo.go b/pkg/client/podinfo.go index e216662f5fe..b55c8aed276 100644 --- a/pkg/client/podinfo.go +++ b/pkg/client/podinfo.go @@ -35,12 +35,13 @@ type PodInfoGetter interface { GetPodInfo(host, podID string) (api.PodInfo, error) } -// The default implementation, accesses the kubelet over HTTP +// HTTPPodInfoGetter is the default implementation of PodInfoGetter, accesses the kubelet over HTTP type HTTPPodInfoGetter struct { Client *http.Client Port uint } +// GetPodInfo gets information about the specified pod. func (c *HTTPPodInfoGetter) GetPodInfo(host, podID string) (api.PodInfo, error) { request, err := http.NewRequest( "GET", @@ -70,12 +71,13 @@ func (c *HTTPPodInfoGetter) GetPodInfo(host, podID string) (api.PodInfo, error) return info, nil } -// Useful for testing. +// FakePodInfoGetter is a fake implementation of PodInfoGetter. It is useful for testing. type FakePodInfoGetter struct { data api.PodInfo err error } +// GetPodInfo is a fake implementation of PodInfoGetter.GetPodInfo. func (c *FakePodInfoGetter) GetPodInfo(host, podID string) (api.PodInfo, error) { return c.data, c.err } diff --git a/pkg/client/podinfo_test.go b/pkg/client/podinfo_test.go index 7748b7b3996..88c0a4c565d 100644 --- a/pkg/client/podinfo_test.go +++ b/pkg/client/podinfo_test.go @@ -49,9 +49,9 @@ func TestHTTPPodInfoGetter(t *testing.T) { } testServer := httptest.NewServer(&fakeHandler) - hostUrl, err := url.Parse(testServer.URL) + hostURL, err := url.Parse(testServer.URL) expectNoError(t, err) - parts := strings.Split(hostUrl.Host, ":") + parts := strings.Split(hostURL.Host, ":") port, err := strconv.Atoi(parts[1]) expectNoError(t, err) diff --git a/pkg/client/request.go b/pkg/client/request.go index 16da594aec8..3715721de17 100644 --- a/pkg/client/request.go +++ b/pkg/client/request.go @@ -40,7 +40,7 @@ import ( // Do() // list, ok := resp.(api.PodList) -// Begin a request with a verb (GET, POST, PUT, DELETE) +// Verb begins a request with a verb (GET, POST, PUT, DELETE) func (c *Client) Verb(verb string) *Request { return &Request{ verb: verb, @@ -52,29 +52,29 @@ func (c *Client) Verb(verb string) *Request { } } -// Begin a POST request. +// Post begins a POST request. func (c *Client) Post() *Request { return c.Verb("POST") } -// Begin a PUT request. +// Put begins a PUT request. func (c *Client) Put() *Request { return c.Verb("PUT") } -// Begin a GET request. +// Get begins a GET request. func (c *Client) Get() *Request { return c.Verb("GET") } -// Begin a DELETE request. +// Delete begins a DELETE request. func (c *Client) Delete() *Request { return c.Verb("DELETE") } -// Make a request to do a single poll of the completion of the given operation. -func (c *Client) PollFor(operationId string) *Request { - return c.Get().Path("operations").Path(operationId).Sync(false).PollPeriod(0) +// PollFor makes a request to do a single poll of the completion of the given operation. +func (c *Client) PollFor(operationID string) *Request { + return c.Get().Path("operations").Path(operationID).Sync(false).PollPeriod(0) } // Request allows for building up a request to a server in a chained fashion. @@ -92,7 +92,7 @@ type Request struct { pollPeriod time.Duration } -// Append an item to the request path. You must call Path at least once. +// Path appends an item to the request path. You must call Path at least once. func (r *Request) Path(item string) *Request { if r.err != nil { return r @@ -101,7 +101,7 @@ func (r *Request) Path(item string) *Request { return r } -// Set sync/async call status. +// Sync sets sync/async call status. func (r *Request) Sync(sync bool) *Request { if r.err != nil { return r @@ -110,7 +110,7 @@ func (r *Request) Sync(sync bool) *Request { return r } -// Overwrite an existing path with the path parameter. +// AbsPath overwrites an existing path with the path parameter. func (r *Request) AbsPath(path string) *Request { if r.err != nil { return r @@ -119,7 +119,7 @@ func (r *Request) AbsPath(path string) *Request { return r } -// Parse the given string as a resource label selector. Optional. +// ParseSelector parses the given string as a resource label selector. Optional. func (r *Request) ParseSelector(item string) *Request { if r.err != nil { return r @@ -128,7 +128,7 @@ func (r *Request) ParseSelector(item string) *Request { return r } -// Use the given selector. +// Selector makes the request use the given selector. func (r *Request) Selector(s labels.Selector) *Request { if r.err != nil { return r @@ -137,7 +137,7 @@ func (r *Request) Selector(s labels.Selector) *Request { return r } -// Use the given duration as a timeout. Optional. +// Timeout makes the request use the given duration as a timeout. Optional. func (r *Request) Timeout(d time.Duration) *Request { if r.err != nil { return r @@ -146,7 +146,7 @@ func (r *Request) Timeout(d time.Duration) *Request { return r } -// Use obj as the body of the request. Optional. +// Body makes the request use obj as the body. Optional. // If obj is a string, try to read a file of that name. // If obj is a []byte, send it directly. // Otherwise, assume obj is an api type and marshall it correctly. @@ -190,13 +190,13 @@ func (r *Request) PollPeriod(d time.Duration) *Request { return r } -// Format and execute the request. Returns the API object received, or an error. +// Do formats and executes the request. Returns the API object received, or an error. func (r *Request) Do() Result { for { if r.err != nil { return Result{err: r.err} } - finalUrl := r.c.host + r.path + finalURL := r.c.host + r.path query := url.Values{} if r.selector != nil { query.Add("labels", r.selector.String()) @@ -207,8 +207,8 @@ func (r *Request) Do() Result { query.Add("timeout", r.timeout.String()) } } - finalUrl += "?" + query.Encode() - req, err := http.NewRequest(r.verb, finalUrl, r.body) + finalURL += "?" + query.Encode() + req, err := http.NewRequest(r.verb, finalURL, r.body) if err != nil { return Result{err: err} }