Skip to content

chore: format code about revive stuttering check #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ linters-settings:
- name: dot-imports
- name: errorf
- name: exported
arguments: ["disableStutteringCheck"] # TODO Temporarily disable stuttering check
- name: var-declaration
- name: blank-imports
- name: indent-error-flow
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/app/routes/namespace/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func handleCreateNamespace(c *gin.Context) {
common.Fail(c, err)
return
}
spec := &ns.NamespaceSpec{
spec := &ns.Spec{
Name: createNamespaceRequest.Name,
SkipAutoPropagation: createNamespaceRequest.SkipAutoPropagation,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/app/routes/overview/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func GetControllerManagerInfo() (*v1.KarmadaInfo, error) {
}

// GetMemberClusterInfo returns the status of member clusters.
func GetMemberClusterInfo(ds *dataselect.DataSelectQuery) (*v1.MemberClusterStatus, error) {
func GetMemberClusterInfo(ds *dataselect.Query) (*v1.MemberClusterStatus, error) {
karmadaClient := client.InClusterKarmadaClient()
result, err := cluster.GetClusterList(karmadaClient, ds)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/api/app/types/common/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func parseSortPathParameter(request *gin.Context) *dataselect.SortQuery {
return dataselect.NewSortQuery(strings.Split(request.Query("sortBy"), ","))
}

// ParseDataSelectPathParameter parses query parameters of the request and returns a DataSelectQuery object
func ParseDataSelectPathParameter(request *gin.Context) *dataselect.DataSelectQuery {
// ParseDataSelectPathParameter parses query parameters of the request and returns a Query object
func ParseDataSelectPathParameter(request *gin.Context) *dataselect.Query {
paginationQuery := parsePaginationPathParameter(request)
sortQuery := parseSortPathParameter(request)
filterQuery := parseFilterPathParameter(request)
Expand Down
2 changes: 1 addition & 1 deletion hack/verify-staticcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ else
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VER}
fi

if golangci-lint run --enable-only goimports,gci,whitespace,misspell,staticcheck,govet,errcheck,gosimple,ineffassign,unused,gocyclo,gosec,revive; then
if golangci-lint run; then
echo 'Congratulations! All Go source files have passed staticcheck.'
else
echo # print one empty line, separate from warning messages.
Expand Down
16 changes: 8 additions & 8 deletions pkg/dataselect/dataselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type DataSelector struct {
// GenericDataList hold generic data cells that are being selected.
GenericDataList []DataCell
// DataSelectQuery holds instructions for data select.
DataSelectQuery *DataSelectQuery
DataSelectQuery *Query
}

// Implementation of sort.Interface so that we can use built-in sort function (sort.Sort) for sorting SelectableData
Expand Down Expand Up @@ -74,13 +74,13 @@ func (s DataSelector) Less(i, j int) bool {
return false
}

// Sort sorts the data inside as instructed by DataSelectQuery and returns itself to allow method chaining.
// Sort sorts the data inside as instructed by Query and returns itself to allow method chaining.
func (s *DataSelector) Sort() *DataSelector {
sort.Sort(*s)
return s
}

// Filter the data inside as instructed by DataSelectQuery and returns itself to allow method chaining.
// Filter the data inside as instructed by Query and returns itself to allow method chaining.
func (s *DataSelector) Filter() *DataSelector {
filteredList := []DataCell{}

Expand All @@ -102,7 +102,7 @@ func (s *DataSelector) Filter() *DataSelector {
return s
}

// Paginate paginates the data inside as instructed by DataSelectQuery and returns itself to allow method chaining.
// Paginate paginates the data inside as instructed by Query and returns itself to allow method chaining.
func (s *DataSelector) Paginate() *DataSelector {
pQuery := s.DataSelectQuery.PaginationQuery
dataList := s.GenericDataList
Expand All @@ -122,17 +122,17 @@ func (s *DataSelector) Paginate() *DataSelector {
return s
}

// GenericDataSelect takes a list of GenericDataCells and DataSelectQuery and returns selected data as instructed by dsQuery.
func GenericDataSelect(dataList []DataCell, dsQuery *DataSelectQuery) []DataCell {
// GenericDataSelect takes a list of GenericDataCells and Query and returns selected data as instructed by dsQuery.
func GenericDataSelect(dataList []DataCell, dsQuery *Query) []DataCell {
SelectableData := DataSelector{
GenericDataList: dataList,
DataSelectQuery: dsQuery,
}
return SelectableData.Sort().Paginate().GenericDataList
}

// GenericDataSelectWithFilter takes a list of GenericDataCells and DataSelectQuery and returns selected data as instructed by dsQuery.
func GenericDataSelectWithFilter(dataList []DataCell, dsQuery *DataSelectQuery) ([]DataCell, int) {
// GenericDataSelectWithFilter takes a list of GenericDataCells and Query and returns selected data as instructed by dsQuery.
func GenericDataSelectWithFilter(dataList []DataCell, dsQuery *Query) ([]DataCell, int) {
SelectableData := DataSelector{
GenericDataList: dataList,
DataSelectQuery: dsQuery,
Expand Down
4 changes: 2 additions & 2 deletions pkg/dataselect/dataselect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestSort(t *testing.T) {
for _, testCase := range testCases {
selectableData := DataSelector{
GenericDataList: getDataCellList(),
DataSelectQuery: &DataSelectQuery{SortQuery: testCase.SortQuery},
DataSelectQuery: &Query{SortQuery: testCase.SortQuery},
}
sortedData := fromCells(selectableData.Sort().GenericDataList)
order := getOrder(sortedData)
Expand Down Expand Up @@ -210,7 +210,7 @@ func TestPagination(t *testing.T) {
for _, testCase := range testCases {
selectableData := DataSelector{
GenericDataList: getDataCellList(),
DataSelectQuery: &DataSelectQuery{PaginationQuery: testCase.PaginationQuery},
DataSelectQuery: &Query{PaginationQuery: testCase.PaginationQuery},
}
paginatedData := fromCells(selectableData.Paginate().GenericDataList)
order := getOrder(paginatedData)
Expand Down
10 changes: 5 additions & 5 deletions pkg/dataselect/dataselectquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

package dataselect

// DataSelectQuery is options for GenericDataSelect which takes []GenericDataCell and returns selected data.
// Query is options for GenericDataSelect which takes []GenericDataCell and returns selected data.
// Can be extended to include any kind of selection - for example filtering.
// Currently included only Pagination and Sort options.
type DataSelectQuery struct {
type Query struct {
// PaginationQuery holds options for pagination of data select.
PaginationQuery *PaginationQuery
// SortQuery holds options for sort functionality of data select.
Expand Down Expand Up @@ -72,9 +72,9 @@ var NoFilter = &FilterQuery{
// NoDataSelect is an option for no data select (same data will be returned).
var NoDataSelect = NewDataSelectQuery(NoPagination, NoSort, NoFilter)

// NewDataSelectQuery creates DataSelectQuery object from simpler data select queries.
func NewDataSelectQuery(paginationQuery *PaginationQuery, sortQuery *SortQuery, filterQuery *FilterQuery) *DataSelectQuery {
return &DataSelectQuery{
// NewDataSelectQuery creates Query object from simpler data select queries.
func NewDataSelectQuery(paginationQuery *PaginationQuery, sortQuery *SortQuery, filterQuery *FilterQuery) *Query {
return &Query{
PaginationQuery: paginationQuery,
SortQuery: sortQuery,
FilterQuery: filterQuery,
Expand Down
26 changes: 13 additions & 13 deletions pkg/resource/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ import (

// Cluster the definition of a cluster.
type Cluster struct {
ObjectMeta types.ObjectMeta `json:"objectMeta"`
TypeMeta types.TypeMeta `json:"typeMeta"`
Ready metav1.ConditionStatus `json:"ready"`
KubernetesVersion string `json:"kubernetesVersion,omitempty"`
SyncMode v1alpha1.ClusterSyncMode `json:"syncMode"`
NodeSummary *v1alpha1.NodeSummary `json:"nodeSummary,omitempty"`
AllocatedResources ClusterAllocatedResources `json:"allocatedResources"`
ObjectMeta types.ObjectMeta `json:"objectMeta"`
TypeMeta types.TypeMeta `json:"typeMeta"`
Ready metav1.ConditionStatus `json:"ready"`
KubernetesVersion string `json:"kubernetesVersion,omitempty"`
SyncMode v1alpha1.ClusterSyncMode `json:"syncMode"`
NodeSummary *v1alpha1.NodeSummary `json:"nodeSummary,omitempty"`
AllocatedResources AllocatedResources `json:"allocatedResources"`
}

// ClusterList contains a list of clusters.
type ClusterList struct {
// List contains a list of clusters.
type List struct {
ListMeta types.ListMeta `json:"listMeta"`
Clusters []Cluster `json:"clusters"`
// List of non-critical errors, that occurred during resource retrieval.
Errors []error `json:"errors"`
}

// GetClusterList returns a list of all Nodes in the cluster.
func GetClusterList(client karmadaclientset.Interface, dsQuery *dataselect.DataSelectQuery) (*ClusterList, error) {
func GetClusterList(client karmadaclientset.Interface, dsQuery *dataselect.Query) (*List, error) {
clusters, err := client.ClusterV1alpha1().Clusters().List(context.TODO(), helpers.ListEverything)
nonCriticalErrors, criticalError := errors.ExtractErrors(err)
if criticalError != nil {
Expand All @@ -59,8 +59,8 @@ func GetClusterList(client karmadaclientset.Interface, dsQuery *dataselect.DataS
return toClusterList(client, clusters.Items, nonCriticalErrors, dsQuery), nil
}

func toClusterList(_ karmadaclientset.Interface, clusters []v1alpha1.Cluster, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *ClusterList {
clusterList := &ClusterList{
func toClusterList(_ karmadaclientset.Interface, clusters []v1alpha1.Cluster, nonCriticalErrors []error, dsQuery *dataselect.Query) *List {
clusterList := &List{
Clusters: make([]Cluster, 0),
ListMeta: types.ListMeta{TotalItems: len(clusters)},
Errors: nonCriticalErrors,
Expand All @@ -78,7 +78,7 @@ func toClusterList(_ karmadaclientset.Interface, clusters []v1alpha1.Cluster, no
}

func toCluster(cluster *v1alpha1.Cluster) Cluster {
allocatedResources, err := getclusterAllocatedResources(cluster)
allocatedResources, err := getAllocatedResources(cluster)
if err != nil {
log.Printf("Couldn't get allocated resources of %s cluster: %s\n", cluster.Name, err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/resource/cluster/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"github.com/karmada-io/dashboard/pkg/dataselect"
)

// ClusterCell is a cell representation of Cluster object.
type ClusterCell v1alpha1.Cluster
// Cell is a cell representation of Cluster object.
type Cell v1alpha1.Cluster

// GetProperty returns value of a given property.
func (c ClusterCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
switch name {
case dataselect.NameProperty:
return dataselect.StdComparableString(c.ObjectMeta.Name)
Expand All @@ -43,15 +43,15 @@ func (c ClusterCell) GetProperty(name dataselect.PropertyName) dataselect.Compar
func toCells(std []v1alpha1.Cluster) []dataselect.DataCell {
cells := make([]dataselect.DataCell, len(std))
for i := range std {
cells[i] = ClusterCell(std[i])
cells[i] = Cell(std[i])
}
return cells
}

func fromCells(cells []dataselect.DataCell) []v1alpha1.Cluster {
std := make([]v1alpha1.Cluster, len(cells))
for i := range std {
std[i] = v1alpha1.Cluster(cells[i].(ClusterCell))
std[i] = v1alpha1.Cluster(cells[i].(Cell))
}
return std
}
18 changes: 9 additions & 9 deletions pkg/resource/cluster/detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ClusterAllocatedResources is the resource summary of a cluster.
type ClusterAllocatedResources struct {
// AllocatedResources is the resource summary of a cluster.
type AllocatedResources struct {
// CPUCapacity is specified node CPU capacity in milicores.
CPUCapacity int64 `json:"cpuCapacity"`
CPUFraction float64 `json:"cpuFraction"`
Expand All @@ -48,9 +48,9 @@ type ClusterAllocatedResources struct {
PodFraction float64 `json:"podFraction"`
}

func getclusterAllocatedResources(cluster *v1alpha1.Cluster) (ClusterAllocatedResources, error) {
func getAllocatedResources(cluster *v1alpha1.Cluster) (AllocatedResources, error) {
if cluster.Status.ResourceSummary == nil {
return ClusterAllocatedResources{}, nil
return AllocatedResources{}, nil
}
allocatableCPU := cluster.Status.ResourceSummary.Allocatable.Cpu()
allocatedCPU := cluster.Status.ResourceSummary.Allocated.Cpu()
Expand Down Expand Up @@ -78,7 +78,7 @@ func getclusterAllocatedResources(cluster *v1alpha1.Cluster) (ClusterAllocatedRe
if podCapacity > 0 {
podFraction = float64(allocatedPod.Value()) / float64(podCapacity) * 100
}
return ClusterAllocatedResources{
return AllocatedResources{
CPUCapacity: allocatableCPU.Value(),
CPUFraction: cpuFraction,
MemoryCapacity: allocatedMemory.Value(),
Expand All @@ -89,20 +89,20 @@ func getclusterAllocatedResources(cluster *v1alpha1.Cluster) (ClusterAllocatedRe
}, nil
}

// ClusterDetail is the detailed information of a cluster.
type ClusterDetail struct {
// Detail is the detailed information of a cluster.
type Detail struct {
Cluster `json:",inline"`
Taints []corev1.Taint `json:"taints,omitempty"`
}

// GetClusterDetail gets details of cluster.
func GetClusterDetail(client karmadaclientset.Interface, clusterName string) (*ClusterDetail, error) {
func GetClusterDetail(client karmadaclientset.Interface, clusterName string) (*Detail, error) {
log.Printf("Getting details of %s cluster", clusterName)
cluster, err := client.ClusterV1alpha1().Clusters().Get(context.TODO(), clusterName, metav1.GetOptions{})
if err != nil {
return nil, err
}
return &ClusterDetail{
return &Detail{
Cluster: toCluster(cluster),
Taints: cluster.Spec.Taints,
}, nil
Expand Down
10 changes: 5 additions & 5 deletions pkg/resource/clusteroverridepolicy/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"github.com/karmada-io/dashboard/pkg/dataselect"
)

// ClusterOverridePolicyCell wraps v1alpha1.ClusterOverridePolicy for data selection.
type ClusterOverridePolicyCell v1alpha1.ClusterOverridePolicy
// Cell wraps v1alpha1.ClusterOverridePolicy for data selection.
type Cell v1alpha1.ClusterOverridePolicy

// GetProperty returns a property of the cluster override policy cell.
func (c ClusterOverridePolicyCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
switch name {
case dataselect.NameProperty:
return dataselect.StdComparableString(c.ObjectMeta.Name)
Expand All @@ -41,15 +41,15 @@ func (c ClusterOverridePolicyCell) GetProperty(name dataselect.PropertyName) dat
func toCells(std []v1alpha1.ClusterOverridePolicy) []dataselect.DataCell {
cells := make([]dataselect.DataCell, len(std))
for i := range std {
cells[i] = ClusterOverridePolicyCell(std[i])
cells[i] = Cell(std[i])
}
return cells
}

func fromCells(cells []dataselect.DataCell) []v1alpha1.ClusterOverridePolicy {
std := make([]v1alpha1.ClusterOverridePolicy, len(cells))
for i := range std {
std[i] = v1alpha1.ClusterOverridePolicy(cells[i].(ClusterOverridePolicyCell))
std[i] = v1alpha1.ClusterOverridePolicy(cells[i].(Cell))
}
return std
}
10 changes: 5 additions & 5 deletions pkg/resource/clusteroverridepolicy/detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"github.com/karmada-io/dashboard/pkg/common/errors"
)

// ClusterOverridePolicyDetail contains clusterPropagationPolicy details and non-critical errors.
type ClusterOverridePolicyDetail struct {
// Detail contains clusterPropagationPolicy details and non-critical errors.
type Detail struct {
// Extends list item structure.
ClusterOverridePolicy `json:",inline"`

Expand All @@ -36,7 +36,7 @@ type ClusterOverridePolicyDetail struct {
}

// GetClusterOverridePolicyDetail gets clusterPropagationPolicy details.
func GetClusterOverridePolicyDetail(client karmadaclientset.Interface, name string) (*ClusterOverridePolicyDetail, error) {
func GetClusterOverridePolicyDetail(client karmadaclientset.Interface, name string) (*Detail, error) {
overridepolicyData, err := client.PolicyV1alpha1().ClusterOverridePolicies().Get(context.TODO(), name, metaV1.GetOptions{})
if err != nil {
return nil, err
Expand All @@ -51,8 +51,8 @@ func GetClusterOverridePolicyDetail(client karmadaclientset.Interface, name stri
return &propagationpolicy, nil
}

func toOverridePolicyDetail(clusterOverridepolicy *v1alpha1.ClusterOverridePolicy, nonCriticalErrors []error) ClusterOverridePolicyDetail {
return ClusterOverridePolicyDetail{
func toOverridePolicyDetail(clusterOverridepolicy *v1alpha1.ClusterOverridePolicy, nonCriticalErrors []error) Detail {
return Detail{
ClusterOverridePolicy: toClusterOverridePolicy(clusterOverridepolicy),
Errors: nonCriticalErrors,
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/resource/clusteroverridepolicy/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"github.com/karmada-io/dashboard/pkg/dataselect"
)

// ClusterOverridePolicyList contains a list of overriders in the karmada control-plane.
type ClusterOverridePolicyList struct {
// List contains a list of overriders in the karmada control-plane.
type List struct {
ListMeta types.ListMeta `json:"listMeta"`

// Unordered list of clusterOverridePolicies.
Expand All @@ -49,7 +49,7 @@ type ClusterOverridePolicy struct {
}

// GetClusterOverridePolicyList returns a list of all overiders in the karmada control-plance.
func GetClusterOverridePolicyList(client karmadaclientset.Interface, dsQuery *dataselect.DataSelectQuery) (*ClusterOverridePolicyList, error) {
func GetClusterOverridePolicyList(client karmadaclientset.Interface, dsQuery *dataselect.Query) (*List, error) {
clusterOverridePolicies, err := client.PolicyV1alpha1().ClusterOverridePolicies().List(context.TODO(), helpers.ListEverything)
nonCriticalErrors, criticalError := errors.ExtractErrors(err)
if criticalError != nil {
Expand All @@ -59,8 +59,8 @@ func GetClusterOverridePolicyList(client karmadaclientset.Interface, dsQuery *da
return toClusterOverridePolicyList(clusterOverridePolicies.Items, nonCriticalErrors, dsQuery), nil
}

func toClusterOverridePolicyList(clusterOverridePolicies []v1alpha1.ClusterOverridePolicy, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *ClusterOverridePolicyList {
overridepolicyList := &ClusterOverridePolicyList{
func toClusterOverridePolicyList(clusterOverridePolicies []v1alpha1.ClusterOverridePolicy, nonCriticalErrors []error, dsQuery *dataselect.Query) *List {
overridepolicyList := &List{
ClusterOverridePolicies: make([]ClusterOverridePolicy, 0),
ListMeta: types.ListMeta{TotalItems: len(clusterOverridePolicies)},
}
Expand Down
Loading