From ab77f912563b99370093f8ce081eac3feefa0a36 Mon Sep 17 00:00:00 2001 From: ZeHuaiWang <874697675@qq.com> Date: Fri, 18 Oct 2019 15:39:58 +0800 Subject: [PATCH] Use golint (#4432) * Reduce code duplication and fix typo * fix apihandler.go * fix * fix * use golint if block ends with a return statement, so drop this else and outdent its block * use golint apihandler.go:1168:2: var sessionId should be sessionID * fix a space * fix * fix * use golint in backend/cert and backend/client * use golint * fix * fix --- src/app/backend/cert/api/types.go | 5 +++-- src/app/backend/cert/manager.go | 4 ++-- src/app/backend/client/api/types.go | 4 ++-- src/app/backend/client/verber.go | 5 ++--- src/app/backend/resource/deployment/common.go | 1 + src/app/backend/resource/deployment/detail.go | 2 ++ src/app/backend/resource/deployment/list.go | 4 ++-- src/app/backend/resource/deployment/newreplicasets.go | 2 +- 8 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/app/backend/cert/api/types.go b/src/app/backend/cert/api/types.go index e0e1ae4a3..8ca74cd08 100644 --- a/src/app/backend/cert/api/types.go +++ b/src/app/backend/cert/api/types.go @@ -17,9 +17,10 @@ package api import "crypto/tls" const ( - // Certificate file names that will be generated by Dashboard + // DashboardCertName is the certificate file names that will be generated by Dashboard DashboardCertName = "dashboard.crt" - DashboardKeyName = "dashboard.key" + // DashboardKeyName is the key file names that will be generated by Dashboard + DashboardKeyName = "dashboard.key" ) // Manager is responsible for generating and storing self-signed certificates that can be used by Dashboard diff --git a/src/app/backend/cert/manager.go b/src/app/backend/cert/manager.go index 59d54915e..c95e6f909 100644 --- a/src/app/backend/cert/manager.go +++ b/src/app/backend/cert/manager.go @@ -22,13 +22,13 @@ import ( certapi "github.com/kubernetes/dashboard/src/app/backend/cert/api" ) -// Implements cert/api/types.Manager interface. See Manager for more information. +// Manager is used to implement cert/api/types.Manager interface. See Manager for more information. type Manager struct { creator certapi.Creator certDir string } -// GenerateCertificates implements Manager interface. See Manager for more information. +// GetCertificates implements Manager interface. See Manager for more information. func (self *Manager) GetCertificates() (tls.Certificate, error) { if self.keyFileExists() && self.certFileExists() { log.Println("Certificates already exist. Returning.") diff --git a/src/app/backend/client/api/types.go b/src/app/backend/client/api/types.go index f15ca953a..89a277145 100644 --- a/src/app/backend/client/api/types.go +++ b/src/app/backend/client/api/types.go @@ -28,10 +28,10 @@ import ( ) const ( - // Resource information that are used as csrf token storage. Can be accessible by multiple dashboard replicas. + // CsrfTokenSecretName is the resource information that are used as csrf token storage. Can be accessible by multiple dashboard replicas. CsrfTokenSecretName = "kubernetes-dashboard-csrf" - // Name of the data var that holds the csrf token inside the secret. + // CsrfTokenSecretData is the name of the data var that holds the csrf token inside the secret. CsrfTokenSecretData = "csrf" ) diff --git a/src/app/backend/client/verber.go b/src/app/backend/client/verber.go index cf13e471e..4390439b9 100644 --- a/src/app/backend/client/verber.go +++ b/src/app/backend/client/verber.go @@ -96,10 +96,9 @@ func (verber *resourceVerber) getResourceSpecFromKind(kind string, namespaceSet if namespaceSet { err = errors.NewInvalid(fmt.Sprintf("Set namespace for not-namespaced resource kind: %s", kind)) return - } else { - err = errors.NewInvalid(fmt.Sprintf("Set no namespace for namespaced resource kind: %s", kind)) - return } + err = errors.NewInvalid(fmt.Sprintf("Set no namespace for namespaced resource kind: %s", kind)) + return } if client == nil { diff --git a/src/app/backend/resource/deployment/common.go b/src/app/backend/resource/deployment/common.go index 724023e9d..fbcb5924f 100644 --- a/src/app/backend/resource/deployment/common.go +++ b/src/app/backend/resource/deployment/common.go @@ -28,6 +28,7 @@ import ( type DeploymentCell apps.Deployment +// GetProperty is used to get property of the deployment func (self DeploymentCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { switch name { case dataselect.NameProperty: diff --git a/src/app/backend/resource/deployment/detail.go b/src/app/backend/resource/deployment/detail.go index 12c0c1903..29ce2ab55 100644 --- a/src/app/backend/resource/deployment/detail.go +++ b/src/app/backend/resource/deployment/detail.go @@ -31,6 +31,7 @@ type RollingUpdateStrategy struct { MaxUnavailable *intstr.IntOrString `json:"maxUnavailable"` } +// StatusInfo is the status information of the deployment type StatusInfo struct { // Total number of desired replicas on the deployment Replicas int32 `json:"replicas"` @@ -145,6 +146,7 @@ func GetDeploymentDetail(client client.Interface, namespace string, deploymentNa }, nil } +// GetStatusInfo is used to get the status information from the *apps.DeploymentStatus func GetStatusInfo(deploymentStatus *apps.DeploymentStatus) StatusInfo { return StatusInfo{ Replicas: deploymentStatus.Replicas, diff --git a/src/app/backend/resource/deployment/list.go b/src/app/backend/resource/deployment/list.go index f8759f56a..8cfc3fe79 100644 --- a/src/app/backend/resource/deployment/list.go +++ b/src/app/backend/resource/deployment/list.go @@ -28,7 +28,7 @@ import ( client "k8s.io/client-go/kubernetes" ) -// DeploymentListComponent contains a list of Deployments in the cluster. +// DeploymentList contains a list of Deployments in the cluster. type DeploymentList struct { ListMeta api.ListMeta `json:"listMeta"` CumulativeMetrics []metricapi.Metric `json:"cumulativeMetrics"` @@ -75,7 +75,7 @@ func GetDeploymentList(client client.Interface, nsQuery *common.NamespaceQuery, return GetDeploymentListFromChannels(channels, dsQuery, metricClient) } -// GetDeploymentList returns a list of all Deployments in the cluster +// GetDeploymentListFromChannels returns a list of all Deployments in the cluster // reading required resource list once from the channels. func GetDeploymentListFromChannels(channels *common.ResourceChannels, dsQuery *dataselect.DataSelectQuery, metricClient metricapi.MetricClient) (*DeploymentList, error) { diff --git a/src/app/backend/resource/deployment/newreplicasets.go b/src/app/backend/resource/deployment/newreplicasets.go index 4f834b811..fc63cf495 100644 --- a/src/app/backend/resource/deployment/newreplicasets.go +++ b/src/app/backend/resource/deployment/newreplicasets.go @@ -25,7 +25,7 @@ import ( "github.com/kubernetes/dashboard/src/app/backend/resource/replicaset" ) -//GetDeploymentOldReplicaSets returns old replica sets targeting Deployment with given name +// GetDeploymentNewReplicaSet returns old replica sets targeting Deployment with given name func GetDeploymentNewReplicaSet(client client.Interface, dsQuery *dataselect.DataSelectQuery, namespace string, deploymentName string) (*replicaset.ReplicaSet, error) { -- GitLab