From 1ee81d46ccffd42947b82998fb7ded0bfb8a20d3 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Thu, 9 May 2019 11:53:29 +0800 Subject: [PATCH 1/2] fix go vet report bugs --- cmd/climc/shell/snapshots.go | 4 ++-- pkg/cloudcommon/db/namevalidator.go | 3 --- pkg/compute/models/loadbalancerbackendgroups.go | 2 +- pkg/hostman/options/options.go | 4 ++-- pkg/hostman/storageman/disk_local.go | 3 +-- pkg/hostman/storageman/remotefile/remotefile.go | 4 +--- pkg/mcclient/modules/notify/mod_notification.go | 2 +- pkg/mcclient/options/loadbalanceracls.go | 2 +- pkg/mcclient/options/loadbalanceragents.go | 10 +++++----- pkg/mcclient/options/loadbalancerbackendgroups.go | 8 ++++---- pkg/mcclient/options/loadbalancerbackends.go | 6 +++--- pkg/mcclient/options/loadbalancercertificates.go | 6 +++--- pkg/mcclient/options/loadbalancerlistenerrules.go | 8 ++++---- pkg/mcclient/options/loadbalancerlisteners.go | 10 +++++----- pkg/mcclient/options/loadbalancers.go | 14 +++++++------- pkg/mcclient/options/servers.go | 2 +- pkg/util/aws/imageowners.go | 1 - pkg/util/aws/securitygroup.go | 2 +- pkg/util/azure/azure.go | 1 - pkg/util/azure/service.go | 2 +- pkg/util/esxi/host.go | 1 - pkg/util/esxi/shell/store.go | 6 +++--- pkg/util/huawei/obs/model.go | 2 +- 23 files changed, 47 insertions(+), 56 deletions(-) diff --git a/cmd/climc/shell/snapshots.go b/cmd/climc/shell/snapshots.go index 279767b0af..a633cb04b6 100644 --- a/cmd/climc/shell/snapshots.go +++ b/cmd/climc/shell/snapshots.go @@ -94,8 +94,8 @@ func init() { }) type SnapshotCreateOptions struct { - Disk string `help: "Id of disk to take snapshot" json:"disk" required:"true"` - NAME string `help: "Name of snapshot" json:"name"` + Disk string `help:"Id of disk to take snapshot" json:"disk" required:"true"` + NAME string `help:"Name of snapshot" json:"name"` } R(&SnapshotCreateOptions{}, "snapshot-create", "Create a snapshot", func(s *mcclient.ClientSession, args *SnapshotCreateOptions) error { params, err := options.StructToParams(args) diff --git a/pkg/cloudcommon/db/namevalidator.go b/pkg/cloudcommon/db/namevalidator.go index e3ec8a8763..ebb400c460 100644 --- a/pkg/cloudcommon/db/namevalidator.go +++ b/pkg/cloudcommon/db/namevalidator.go @@ -17,7 +17,6 @@ package db import ( "fmt" - "yunion.io/x/log" "yunion.io/x/pkg/util/stringutils" "yunion.io/x/onecloud/pkg/cloudcommon/consts" @@ -103,6 +102,4 @@ func GenerateName(manager IModelManager, ownerProjId string, hint string) (strin name = fmt.Sprintf(pattern, idx) idx += 1 } - log.Fatalln("here is not reachable!!!") - return "", nil } diff --git a/pkg/compute/models/loadbalancerbackendgroups.go b/pkg/compute/models/loadbalancerbackendgroups.go index 4fa64ef3ff..0c3fe4b441 100644 --- a/pkg/compute/models/loadbalancerbackendgroups.go +++ b/pkg/compute/models/loadbalancerbackendgroups.go @@ -174,7 +174,7 @@ func (man *SLoadbalancerBackendGroupManager) ValidateCreateData(ctx context.Cont func (lbbg *SLoadbalancerBackendGroup) GetLoadbalancer() *SLoadbalancer { lb, err := LoadbalancerManager.FetchById(lbbg.LoadbalancerId) if err != nil { - fmt.Errorf("failed to find loadbalancer for backendgroup %s", lbbg.Name) + log.Errorf("failed to find loadbalancer for backendgroup %s", lbbg.Name) return nil } return lb.(*SLoadbalancer) diff --git a/pkg/hostman/options/options.go b/pkg/hostman/options/options.go index 58fb49c013..c6c88766bb 100644 --- a/pkg/hostman/options/options.go +++ b/pkg/hostman/options/options.go @@ -21,7 +21,7 @@ type SHostOptions struct { HostType string `help:"Host server type, either hypervisor or kubelet" default:"hypervisor"` ListenInterface string `help:"Master address of host server"` - BridgeDriver string `help:"Bridge driver, bridge or openvswitch" default: "openvswitch"` + BridgeDriver string `help:"Bridge driver, bridge or openvswitch" default:"openvswitch"` Networks []string `help:"Network interface information"` Rack string `help:"Rack of host (optional)"` Slots string `help:"Slots of host (optional)"` @@ -42,7 +42,7 @@ type SHostOptions struct { EnableFallocateDisk bool `help:"Automatically allocate all spaces using fallocate"` EnableMonitor bool `help:"Enable monitor"` - ReportInterval int `help:"Report interval in seconds", default:"60"` + ReportInterval int `help:"Report interval in seconds" default:"60"` EnableTcBwlimit bool `help:"Enable linux tc bandwidth limit"` BwDownloadBandwidth int `help:"Default ingress bandwidth in mbit (0 disabled)" default:"10"` diff --git a/pkg/hostman/storageman/disk_local.go b/pkg/hostman/storageman/disk_local.go index 64a9cb486a..eec19dc0e4 100644 --- a/pkg/hostman/storageman/disk_local.go +++ b/pkg/hostman/storageman/disk_local.go @@ -271,8 +271,7 @@ func (d *SLocalDisk) CreateRaw(ctx context.Context, sizeMB int, diskFormat, fsFo } if err != nil { - log.Errorln(err) - fmt.Errorf("create_raw: Fail to create disk") + return nil, fmt.Errorf("create_raw: Fail to create disk: %s", err) } if options.HostOptions.EnableFallocateDisk { diff --git a/pkg/hostman/storageman/remotefile/remotefile.go b/pkg/hostman/storageman/remotefile/remotefile.go index 2cdca37718..24aa6639e9 100644 --- a/pkg/hostman/storageman/remotefile/remotefile.go +++ b/pkg/hostman/storageman/remotefile/remotefile.go @@ -33,7 +33,7 @@ import ( type SImageDesc struct { Name string `json:"name"` Format string `json:"format"` - Id string `json:"id:` + Id string `json:"id"` Chksum string `json:"chksum"` Path string `json:"path"` Size int64 `json:"size"` @@ -242,8 +242,6 @@ func (r *SRemoteFile) downloadInternal(getData bool, preChksum string) bool { return false } } - return false - } func (r *SRemoteFile) setProperties(header http.Header) { diff --git a/pkg/mcclient/modules/notify/mod_notification.go b/pkg/mcclient/modules/notify/mod_notification.go index 85bea0647b..f743701065 100644 --- a/pkg/mcclient/modules/notify/mod_notification.go +++ b/pkg/mcclient/modules/notify/mod_notification.go @@ -27,7 +27,7 @@ var ( type SNotifyMessage struct { Uid string `json:"uid,omitempty"` - Gid string `json:"uid,omitempty"` + Gid string `json:"gid,omitempty"` ContactType TNotifyChannel `json:"contact_type,omitempty"` Topic string `json:"topic,omitempty"` Priority TNotifyPriority `json:"priority,omitempty"` diff --git a/pkg/mcclient/options/loadbalanceracls.go b/pkg/mcclient/options/loadbalanceracls.go index 42040d5a1e..922a6b6978 100644 --- a/pkg/mcclient/options/loadbalanceracls.go +++ b/pkg/mcclient/options/loadbalanceracls.go @@ -77,7 +77,7 @@ type LoadbalancerAclCreateOptions struct { } type LoadbalancerAclGetOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerAclListOptions struct { diff --git a/pkg/mcclient/options/loadbalanceragents.go b/pkg/mcclient/options/loadbalanceragents.go index 78da126f55..30265b5c53 100644 --- a/pkg/mcclient/options/loadbalanceragents.go +++ b/pkg/mcclient/options/loadbalanceragents.go @@ -98,11 +98,11 @@ type LoadbalancerAgentListOptions struct { } type LoadbalancerAgentGetOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerAgentUpdateOptions struct { - ID string `json:-` + ID string `json:"-"` Name string HbTimeout *int @@ -117,11 +117,11 @@ type LoadbalancerAgentUpdateOptions struct { } type LoadbalancerAgentDeleteOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerAgentActionHbOptions struct { - ID string `json:-` + ID string `json:"-"` Version string IP string @@ -129,7 +129,7 @@ type LoadbalancerAgentActionHbOptions struct { } type LoadbalancerAgentActionPatchParamsOptions struct { - ID string `json:-` + ID string `json:"-"` LoadbalancerAgentParamsOptions } diff --git a/pkg/mcclient/options/loadbalancerbackendgroups.go b/pkg/mcclient/options/loadbalancerbackendgroups.go index 2a55bb5135..c5da872f44 100644 --- a/pkg/mcclient/options/loadbalancerbackendgroups.go +++ b/pkg/mcclient/options/loadbalancerbackendgroups.go @@ -109,20 +109,20 @@ func (opts *LoadbalancerBackendGroupCreateOptions) Params() (*jsonutils.JSONDict } type LoadbalancerBackendGroupGetOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerBackendGroupUpdateOptions struct { - ID string `json:-` + ID string `json:"-"` Name string } type LoadbalancerBackendGroupDeleteOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerBackendGroupIDOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerBackendGroupListOptions struct { diff --git a/pkg/mcclient/options/loadbalancerbackends.go b/pkg/mcclient/options/loadbalancerbackends.go index 188e53d684..20cbc145db 100644 --- a/pkg/mcclient/options/loadbalancerbackends.go +++ b/pkg/mcclient/options/loadbalancerbackends.go @@ -33,7 +33,7 @@ type LoadbalancerBackendListOptions struct { } type LoadbalancerBackendUpdateOptions struct { - ID string `json:-` + ID string `json:"-"` Name string Weight *int @@ -41,9 +41,9 @@ type LoadbalancerBackendUpdateOptions struct { } type LoadbalancerBackendGetOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerBackendDeleteOptions struct { - ID string `json:-` + ID string `json:"-"` } diff --git a/pkg/mcclient/options/loadbalancercertificates.go b/pkg/mcclient/options/loadbalancercertificates.go index e06571e20c..6647c2ac51 100644 --- a/pkg/mcclient/options/loadbalancercertificates.go +++ b/pkg/mcclient/options/loadbalancercertificates.go @@ -70,11 +70,11 @@ func (opts *LoadbalancerCertificateCreateOptions) Params() (*jsonutils.JSONDict, } type LoadbalancerCertificateGetOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerCertificateDeleteOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerCertificateListOptions struct { @@ -86,7 +86,7 @@ type LoadbalancerCertificateListOptions struct { } type LoadbalancerCertificateUpdateOptions struct { - ID string `json:-` + ID string `json:"-"` Name string Cert string `json:"-" help:"path to certificate file"` diff --git a/pkg/mcclient/options/loadbalancerlistenerrules.go b/pkg/mcclient/options/loadbalancerlistenerrules.go index 8f9fdad614..c5f41c51d0 100644 --- a/pkg/mcclient/options/loadbalancerlistenerrules.go +++ b/pkg/mcclient/options/loadbalancerlistenerrules.go @@ -32,21 +32,21 @@ type LoadbalancerListenerRuleListOptions struct { } type LoadbalancerListenerRuleUpdateOptions struct { - ID string `json:-` + ID string `json:"-"` Name string BackendGroup string } type LoadbalancerListenerRuleGetOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerListenerRuleDeleteOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerListenerRuleActionStatusOptions struct { - ID string `json:-` + ID string `json:"-"` Status string `choices:"enabled|disabled"` } diff --git a/pkg/mcclient/options/loadbalancerlisteners.go b/pkg/mcclient/options/loadbalancerlisteners.go index 41e0e5284e..4b840daef0 100644 --- a/pkg/mcclient/options/loadbalancerlisteners.go +++ b/pkg/mcclient/options/loadbalancerlisteners.go @@ -118,7 +118,7 @@ type LoadbalancerListenerListOptions struct { } type LoadbalancerListenerUpdateOptions struct { - ID string `json:-` + ID string `json:"-"` Name string BackendGroup string @@ -166,18 +166,18 @@ type LoadbalancerListenerUpdateOptions struct { } type LoadbalancerListenerGetOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerListenerDeleteOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerListenerActionStatusOptions struct { - ID string `json:-` + ID string `json:"-"` Status string `choices:"enabled|disabled"` } type LoadbalancerListenerActionSyncStatusOptions struct { - ID string `json:-` + ID string `json:"-"` } diff --git a/pkg/mcclient/options/loadbalancers.go b/pkg/mcclient/options/loadbalancers.go index 315b4f2da3..687681aef3 100644 --- a/pkg/mcclient/options/loadbalancers.go +++ b/pkg/mcclient/options/loadbalancers.go @@ -27,22 +27,22 @@ type LoadbalancerCreateOptions struct { } type LoadbalancerGetOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerUpdateOptions struct { - ID string `json:-` + ID string `json:"-"` Name string BackendGroup string } type LoadbalancerDeleteOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerPurgeOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerListOptions struct { @@ -56,14 +56,14 @@ type LoadbalancerListOptions struct { } type LoadbalancerActionStatusOptions struct { - ID string `json:-` + ID string `json:"-"` Status string `choices:"enabled|disabled"` } type LoadbalancerActionSyncStatusOptions struct { - ID string `json:-` + ID string `json:"-"` } type LoadbalancerIdOptions struct { - ID string `json:-` + ID string `json:"-"` } diff --git a/pkg/mcclient/options/servers.go b/pkg/mcclient/options/servers.go index 1147f10c19..48c68c2c7d 100644 --- a/pkg/mcclient/options/servers.go +++ b/pkg/mcclient/options/servers.go @@ -540,7 +540,7 @@ type ServerRestartOptions struct { type ServerMigrateOptions struct { ID string `help:"ID of server" json:"-"` PreferHost string `help:"Server migration prefer host id or name" json:"prefer_host"` - AutoStart *bool `help: "Server auto start after migrate" json:"auto_start"` + AutoStart *bool `help:"Server auto start after migrate" json:"auto_start"` RescueMode *bool `help:"Migrate server in rescue mode, all disk must store in shared storage; default false" json:"rescue_mode"` diff --git a/pkg/util/aws/imageowners.go b/pkg/util/aws/imageowners.go index 98e9027ad7..5099c17e70 100644 --- a/pkg/util/aws/imageowners.go +++ b/pkg/util/aws/imageowners.go @@ -145,7 +145,6 @@ var centos = SAWSImagePublisherInfo{ } else { return parts[1] } - return "" }, GetOSBuildID: func(image SImage) string { build := centosDatePattern.FindString(image.ImageName) diff --git a/pkg/util/aws/securitygroup.go b/pkg/util/aws/securitygroup.go index e70ab90958..72e70c4475 100644 --- a/pkg/util/aws/securitygroup.go +++ b/pkg/util/aws/securitygroup.go @@ -296,7 +296,7 @@ func (self *SRegion) GetSecurityGroupDetails(secGroupId string) (*SSecurityGroup s := ret.SecurityGroups[0] vpc, err := self.getVpc(*s.VpcId) if err != nil { - fmt.Errorf("vpc %s not found", *s.VpcId) + return nil, fmt.Errorf("vpc %s not found", *s.VpcId) } permissions := self.getSecRules(s.IpPermissions, s.IpPermissionsEgress) diff --git a/pkg/util/azure/azure.go b/pkg/util/azure/azure.go index 762bb8253a..819e406040 100644 --- a/pkg/util/azure/azure.go +++ b/pkg/util/azure/azure.go @@ -507,7 +507,6 @@ func recoverFromError(client *autorest.Client, domain, subscriptionId string, az default: return false } - return false } func jsonRequest(client *autorest.Client, method, domain, baseUrl string, subscriptionId string, body string) (jsonutils.JSONObject, error) { diff --git a/pkg/util/azure/service.go b/pkg/util/azure/service.go index 07627eab08..79385b1c0b 100644 --- a/pkg/util/azure/service.go +++ b/pkg/util/azure/service.go @@ -33,7 +33,7 @@ type ResourceType struct { ApiVersions []string `json:"apiVersions,omitempty"` Capabilities string `json:"capabilities,omitempty"` Locations []string `json:"locations,omitempty"` - ResourceType string `json:"locations,omitempty"` + ResourceType string `json:"resourceType,omitempty"` } func (self *SRegion) ListServices() ([]SService, error) { diff --git a/pkg/util/esxi/host.go b/pkg/util/esxi/host.go index 9b3cc2f57a..15a081cd52 100644 --- a/pkg/util/esxi/host.go +++ b/pkg/util/esxi/host.go @@ -106,7 +106,6 @@ func formatName(name string) string { } return name } - return name } func (self *SHost) GetName() string { diff --git a/pkg/util/esxi/shell/store.go b/pkg/util/esxi/shell/store.go index cb1b7f5477..5a7866723f 100644 --- a/pkg/util/esxi/shell/store.go +++ b/pkg/util/esxi/shell/store.go @@ -55,7 +55,7 @@ func init() { type DatastoreShowOptions struct { DATACENTER string `help:"Datacenter"` - DSID string `help:"Datastore ID""` + DSID string `help:"Datastore ID"` } shellutils.R(&DatastoreShowOptions{}, "ds-show", "Show details of a datastore", func(cli *esxi.SESXiClient, args *DatastoreShowOptions) error { ds, err := getDatastore(cli, args.DATACENTER, args.DSID) @@ -92,7 +92,7 @@ func init() { type DatastoreListDirOptions struct { DATACENTER string `help:"Datacenter"` - DSID string `help:"Datastore ID""` + DSID string `help:"Datastore ID"` DIR string `help:"directory"` } shellutils.R(&DatastoreListDirOptions{}, "ds-list-dir", "List directory of a datastore", func(cli *esxi.SESXiClient, args *DatastoreListDirOptions) error { @@ -195,7 +195,7 @@ func init() { type DatastoreDownloadOptions struct { DATACENTER string `help:"Datacenter"` - DSID string `help:"Datastore ID""` + DSID string `help:"Datastore ID"` DIR string `help:"directory"` LOCAL string `help:"local file"` } diff --git a/pkg/util/huawei/obs/model.go b/pkg/util/huawei/obs/model.go index f1f1c18389..a0cd599ae0 100644 --- a/pkg/util/huawei/obs/model.go +++ b/pkg/util/huawei/obs/model.go @@ -885,7 +885,7 @@ type ListPartsOutput struct { MaxParts int `xml:"MaxParts"` IsTruncated bool `xml:"IsTruncated"` StorageClass StorageClassType `xml:"StorageClass"` - Initiator Initiator `xml:"Initiator“` + Initiator Initiator `xml:"Initiator"` Owner Owner `xml:"Owner"` Parts []Part `xml:"Part"` } From a4a906cdb639e9264ebdb43f68c0ad6c0fcd672d Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Thu, 9 May 2019 12:02:29 +0800 Subject: [PATCH 2/2] Readme add go reporter --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b46d0b968d..df05aa86d9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # Yunion OneCloud [![CircleCI](https://circleci.com/gh/yunionio/onecloud.svg?style=svg)](https://circleci.com/gh/yunionio/onecloud) [![Build Status](https://travis-ci.org/yunionio/onecloud.svg?branch=master)](https://travis-ci.org/yunionio/onecloud) +[![Go Report Card](https://goreportcard.com/badge/github.com/yunionio/onecloud)](https://goreportcard.com/report/github.com/yunionio/onecloud) \ No newline at end of file