Skip to content

Commit

Permalink
Fix various golint errors and other cleanup
Browse files Browse the repository at this point in the history
Closes #98
  • Loading branch information
adkerr committed Feb 26, 2018
1 parent a221352 commit 5cbbed6
Show file tree
Hide file tree
Showing 168 changed files with 2,317 additions and 2,390 deletions.
2 changes: 1 addition & 1 deletion Makefile
@@ -1,4 +1,4 @@
# Copyright 2016 NetApp, Inc. All Rights Reserved.
# Copyright 2018 NetApp, Inc. All Rights Reserved.


GOOS ?= linux
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -4,6 +4,7 @@
[![GitHub last commit](https://img.shields.io/github/last-commit/netapp/trident.svg)]()
[![license](https://img.shields.io/github/license/netapp/trident.svg)](LICENSE)
[![Docs](https://readthedocs.org/projects/netapp-trident/badge/?version=latest)](https://netapp-trident.readthedocs.io)
[![Go Report Card](https://goreportcard.com/badge/github.com/netapp/trident)](https://goreportcard.com/report/github.com/netapp/trident)

Trident is a fully supported open source project maintained by [NetApp](https://www.netapp.com). It has been designed
from the ground up to help you meet the sophisticated persistence demands of your containerized applications.
Expand Down
16 changes: 9 additions & 7 deletions cli/api/rest.go
@@ -1,3 +1,5 @@
// Copyright 2018 NetApp, Inc. All Rights Reserved.

package api

import (
Expand All @@ -9,9 +11,9 @@ import (
"time"
)

const HTTP_TIMEOUT = time.Second * 30
const HTTPTimeout = time.Second * 30

func InvokeRestApi(method string, url string, requestBody []byte, debug bool) (*http.Response, []byte, error) {
func InvokeRESTAPI(method string, url string, requestBody []byte, debug bool) (*http.Response, []byte, error) {

var request *http.Request
var err error
Expand All @@ -28,10 +30,10 @@ func InvokeRestApi(method string, url string, requestBody []byte, debug bool) (*
request.Header.Set("Content-Type", "application/json")

if debug {
LogHttpRequest(request, requestBody)
LogHTTPRequest(request, requestBody)
}

client := &http.Client{Timeout: HTTP_TIMEOUT}
client := &http.Client{Timeout: HTTPTimeout}
response, err := client.Do(request)

responseBody := []byte{}
Expand All @@ -41,14 +43,14 @@ func InvokeRestApi(method string, url string, requestBody []byte, debug bool) (*
response.Body.Close()

if debug {
LogHttpResponse(response, responseBody)
LogHTTPResponse(response, responseBody)
}
}

return response, responseBody, err
}

func LogHttpRequest(request *http.Request, requestBody []byte) {
func LogHTTPRequest(request *http.Request, requestBody []byte) {
fmt.Fprint(os.Stdout, "--------------------------------------------------------------------------------\n")
fmt.Fprintf(os.Stdout, "Request Method: %s\n", request.Method)
fmt.Fprintf(os.Stdout, "Request URL: %v\n", request.URL)
Expand All @@ -60,7 +62,7 @@ func LogHttpRequest(request *http.Request, requestBody []byte) {
fmt.Fprint(os.Stdout, "................................................................................\n")
}

func LogHttpResponse(response *http.Response, responseBody []byte) {
func LogHTTPResponse(response *http.Response, responseBody []byte) {
fmt.Fprintf(os.Stdout, "Response status: %s\n", response.Status)
fmt.Fprintf(os.Stdout, "Response headers: %v\n", response.Header)
if responseBody == nil {
Expand Down
2 changes: 2 additions & 0 deletions cli/api/types.go
@@ -1,3 +1,5 @@
// Copyright 2018 NetApp, Inc. All Rights Reserved.

package api

import "github.com/netapp/trident/storage"
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/create.go
@@ -1,3 +1,5 @@
// Copyright 2018 NetApp, Inc. All Rights Reserved.

package cmd

import "github.com/spf13/cobra"
Expand Down
8 changes: 5 additions & 3 deletions cli/cmd/create_backend.go
@@ -1,3 +1,5 @@
// Copyright 2018 NetApp, Inc. All Rights Reserved.

package cmd

import (
Expand Down Expand Up @@ -36,7 +38,7 @@ var createBackendCmd = &cobra.Command{
return err
}

if OperatingMode == MODE_TUNNEL {
if OperatingMode == ModeTunnel {
command := []string{"create", "backend", "--base64", base64.StdEncoding.EncodeToString(jsonData)}
TunnelCommand(append(command, args...))
return nil
Expand All @@ -52,7 +54,7 @@ func getBackendCreateData() ([]byte, error) {
var rawData []byte

if b64Data == "" && filename == "" {
return nil, errors.New("no input file was specified.")
return nil, errors.New("no input file was specified")
}

// Read from file or stdin or b64 data
Expand Down Expand Up @@ -86,7 +88,7 @@ func backendCreate(postData []byte) error {
// Send the file to Trident
url := baseURL + "/backend"

response, responseBody, err := api.InvokeRestApi("POST", url, postData, Debug)
response, responseBody, err := api.InvokeRESTAPI("POST", url, postData, Debug)
if err != nil {
return err
} else if response.StatusCode != http.StatusCreated {
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/delete.go
@@ -1,3 +1,5 @@
// Copyright 2018 NetApp, Inc. All Rights Reserved.

package cmd

import "github.com/spf13/cobra"
Expand Down
10 changes: 6 additions & 4 deletions cli/cmd/delete_backend.go
@@ -1,3 +1,5 @@
// Copyright 2018 NetApp, Inc. All Rights Reserved.

package cmd

import (
Expand All @@ -21,7 +23,7 @@ var deleteBackendCmd = &cobra.Command{
Short: "Delete one or more storage backends from Trident",
Aliases: []string{"b", "backends"},
RunE: func(cmd *cobra.Command, args []string) error {
if OperatingMode == MODE_TUNNEL {
if OperatingMode == ModeTunnel {
command := []string{"delete", "backend"}
if AllBackends {
command = append(command, "--all")
Expand All @@ -44,7 +46,7 @@ func backendDelete(backendNames []string) error {
if AllBackends {
// Make sure --all isn't being used along with specific backends
if len(backendNames) > 0 {
return errors.New("cannot use --all switch and specify individual backends.")
return errors.New("cannot use --all switch and specify individual backends")
}

// Get list of backend names so we can delete them all
Expand All @@ -55,14 +57,14 @@ func backendDelete(backendNames []string) error {
} else {
// Not using --all, so make sure one or more backends were specified
if len(backendNames) == 0 {
return errors.New("backend name not specified.")
return errors.New("backend name not specified")
}
}

for _, backendName := range backendNames {
url := baseURL + "/backend/" + backendName

response, _, err := api.InvokeRestApi("DELETE", url, nil, Debug)
response, _, err := api.InvokeRESTAPI("DELETE", url, nil, Debug)
if err != nil {
return err
} else if response.StatusCode != http.StatusOK {
Expand Down
10 changes: 6 additions & 4 deletions cli/cmd/delete_storageclass.go
@@ -1,3 +1,5 @@
// Copyright 2018 NetApp, Inc. All Rights Reserved.

package cmd

import (
Expand All @@ -21,7 +23,7 @@ var deleteStorageClassCmd = &cobra.Command{
Short: "Delete one or more storage classes from Trident",
Aliases: []string{"sc", "storageclasses"},
RunE: func(cmd *cobra.Command, args []string) error {
if OperatingMode == MODE_TUNNEL {
if OperatingMode == ModeTunnel {
command := []string{"delete", "storageclass"}
if AllStorageClasses {
command = append(command, "--all")
Expand All @@ -44,7 +46,7 @@ func storageClassDelete(storageClassNames []string) error {
if AllStorageClasses {
// Make sure --all isn't being used along with specific storage classes
if len(storageClassNames) > 0 {
return errors.New("cannot use --all switch and specify individual storage classes.")
return errors.New("cannot use --all switch and specify individual storage classes")
}

// Get list of storage class names so we can delete them all
Expand All @@ -55,14 +57,14 @@ func storageClassDelete(storageClassNames []string) error {
} else {
// Not using --all, so make sure one or more storage classes were specified
if len(storageClassNames) == 0 {
return errors.New("storage class name not specified.")
return errors.New("storage class name not specified")
}
}

for _, storageClassName := range storageClassNames {
url := baseURL + "/storageclass/" + storageClassName

response, _, err := api.InvokeRestApi("DELETE", url, nil, Debug)
response, _, err := api.InvokeRESTAPI("DELETE", url, nil, Debug)
if err != nil {
return err
} else if response.StatusCode != http.StatusOK {
Expand Down
10 changes: 6 additions & 4 deletions cli/cmd/delete_volume.go
@@ -1,3 +1,5 @@
// Copyright 2018 NetApp, Inc. All Rights Reserved.

package cmd

import (
Expand All @@ -21,7 +23,7 @@ var deleteVolumeCmd = &cobra.Command{
Short: "Delete one or more storage volumes from Trident",
Aliases: []string{"b", "volumes"},
RunE: func(cmd *cobra.Command, args []string) error {
if OperatingMode == MODE_TUNNEL {
if OperatingMode == ModeTunnel {
command := []string{"delete", "volume"}
if AllVolumes {
command = append(command, "--all")
Expand All @@ -44,7 +46,7 @@ func volumeDelete(volumeNames []string) error {
if AllVolumes {
// Make sure --all isn't being used along with specific volumes
if len(volumeNames) > 0 {
return errors.New("cannot use --all switch and specify individual volumes.")
return errors.New("cannot use --all switch and specify individual volumes")
}

// Get list of volume names so we can delete them all
Expand All @@ -55,14 +57,14 @@ func volumeDelete(volumeNames []string) error {
} else {
// Not using --all, so make sure one or more volumes were specified
if len(volumeNames) == 0 {
return errors.New("volume name not specified.")
return errors.New("volume name not specified")
}
}

for _, volumeName := range volumeNames {
url := baseURL + "/volume/" + volumeName

response, _, err := api.InvokeRestApi("DELETE", url, nil, Debug)
response, _, err := api.InvokeRESTAPI("DELETE", url, nil, Debug)
if err != nil {
return err
} else if response.StatusCode != http.StatusOK {
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/get.go
@@ -1,3 +1,5 @@
// Copyright 2018 NetApp, Inc. All Rights Reserved.

package cmd

import (
Expand Down
14 changes: 8 additions & 6 deletions cli/cmd/get_backend.go
@@ -1,3 +1,5 @@
// Copyright 2018 NetApp, Inc. All Rights Reserved.

package cmd

import (
Expand All @@ -22,7 +24,7 @@ var getBackendCmd = &cobra.Command{
Short: "Get one or more storage backends from Trident",
Aliases: []string{"b", "backends"},
RunE: func(cmd *cobra.Command, args []string) error {
if OperatingMode == MODE_TUNNEL {
if OperatingMode == ModeTunnel {
command := []string{"get", "backend"}
TunnelCommand(append(command, args...))
return nil
Expand Down Expand Up @@ -68,7 +70,7 @@ func GetBackends(baseURL string) ([]string, error) {

url := baseURL + "/backend"

response, responseBody, err := api.InvokeRestApi("GET", url, nil, Debug)
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
if err != nil {
return nil, err
} else if response.StatusCode != http.StatusOK {
Expand All @@ -88,7 +90,7 @@ func GetBackend(baseURL, backendName string) (api.Backend, error) {

url := baseURL + "/backend/" + backendName

response, responseBody, err := api.InvokeRestApi("GET", url, nil, Debug)
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
if err != nil {
return api.Backend{}, err
} else if response.StatusCode != http.StatusOK {
Expand All @@ -106,11 +108,11 @@ func GetBackend(baseURL, backendName string) (api.Backend, error) {

func WriteBackends(backends []api.Backend) {
switch OutputFormat {
case FORMAT_JSON:
case FormatJSON:
WriteJSON(api.MultipleBackendResponse{backends})
case FORMAT_YAML:
case FormatYAML:
WriteYAML(api.MultipleBackendResponse{backends})
case FORMAT_NAME:
case FormatName:
writeBackendNames(backends)
default:
writeBackendTable(backends)
Expand Down
14 changes: 8 additions & 6 deletions cli/cmd/get_storageclass.go
@@ -1,3 +1,5 @@
// Copyright 2018 NetApp, Inc. All Rights Reserved.

package cmd

import (
Expand All @@ -21,7 +23,7 @@ var getStorageClassCmd = &cobra.Command{
Short: "Get one or more storage classes from Trident",
Aliases: []string{"sc", "storageclasses"},
RunE: func(cmd *cobra.Command, args []string) error {
if OperatingMode == MODE_TUNNEL {
if OperatingMode == ModeTunnel {
command := []string{"get", "storageclass"}
TunnelCommand(append(command, args...))
return nil
Expand Down Expand Up @@ -67,7 +69,7 @@ func GetStorageClasses(baseURL string) ([]string, error) {

url := baseURL + "/storageclass"

response, responseBody, err := api.InvokeRestApi("GET", url, nil, Debug)
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
if err != nil {
return nil, err
} else if response.StatusCode != http.StatusOK {
Expand All @@ -87,7 +89,7 @@ func GetStorageClass(baseURL, storageClassName string) (api.StorageClass, error)

url := baseURL + "/storageclass/" + storageClassName

response, responseBody, err := api.InvokeRestApi("GET", url, nil, Debug)
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
if err != nil {
return api.StorageClass{}, err
} else if response.StatusCode != http.StatusOK {
Expand All @@ -105,11 +107,11 @@ func GetStorageClass(baseURL, storageClassName string) (api.StorageClass, error)

func WriteStorageClasses(storageClasses []api.StorageClass) {
switch OutputFormat {
case FORMAT_JSON:
case FormatJSON:
WriteJSON(api.MultipleStorageClassResponse{storageClasses})
case FORMAT_YAML:
case FormatYAML:
WriteYAML(api.MultipleStorageClassResponse{storageClasses})
case FORMAT_NAME:
case FormatName:
writeStorageClassNames(storageClasses)
default:
writeStorageClassTable(storageClasses)
Expand Down
16 changes: 9 additions & 7 deletions cli/cmd/get_volume.go
@@ -1,3 +1,5 @@
// Copyright 2018 NetApp, Inc. All Rights Reserved.

package cmd

import (
Expand All @@ -24,7 +26,7 @@ var getVolumeCmd = &cobra.Command{
Short: "Get one or more volumes from Trident",
Aliases: []string{"v", "volumes"},
RunE: func(cmd *cobra.Command, args []string) error {
if OperatingMode == MODE_TUNNEL {
if OperatingMode == ModeTunnel {
command := []string{"get", "volume"}
TunnelCommand(append(command, args...))
return nil
Expand Down Expand Up @@ -70,7 +72,7 @@ func GetVolumes(baseURL string) ([]string, error) {

url := baseURL + "/volume"

response, responseBody, err := api.InvokeRestApi("GET", url, nil, Debug)
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
if err != nil {
return nil, err
} else if response.StatusCode != http.StatusOK {
Expand All @@ -90,7 +92,7 @@ func GetVolume(baseURL, volumeName string) (storage.VolumeExternal, error) {

url := baseURL + "/volume/" + volumeName

response, responseBody, err := api.InvokeRestApi("GET", url, nil, Debug)
response, responseBody, err := api.InvokeRESTAPI("GET", url, nil, Debug)
if err != nil {
return storage.VolumeExternal{}, err
} else if response.StatusCode != http.StatusOK {
Expand All @@ -108,13 +110,13 @@ func GetVolume(baseURL, volumeName string) (storage.VolumeExternal, error) {

func WriteVolumes(volumes []storage.VolumeExternal) {
switch OutputFormat {
case FORMAT_JSON:
case FormatJSON:
WriteJSON(api.MultipleVolumeResponse{volumes})
case FORMAT_YAML:
case FormatYAML:
WriteYAML(api.MultipleVolumeResponse{volumes})
case FORMAT_NAME:
case FormatName:
writeVolumeNames(volumes)
case FORMAT_WIDE:
case FormatWide:
writeWideVolumeTable(volumes)
default:
writeVolumeTable(volumes)
Expand Down

0 comments on commit 5cbbed6

Please sign in to comment.