VOL-1900 lint warning fixes
Change-Id: Ibbe15bc887f0ed9e0de4d01b522f0a0429773b44
diff --git a/Makefile b/Makefile
index d21c2f3..960f5f2 100644
--- a/Makefile
+++ b/Makefile
@@ -227,7 +227,7 @@
sca: golangci_lint_tool_install
rm -rf ./sca-report
@mkdir -p ./sca-report
- $(GOLANGCI_LINT_TOOL) run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml
+ $(GOLANGCI_LINT_TOOL) run -E golint --out-format junit-xml ./cli/... 2>&1 | tee ./sca-report/sca-report.xml
test: go_junit_install gocover_cobertura_install local-lib-go
@mkdir -p ./tests/results
diff --git a/cli/main.go b/cli/main.go
index 9a9ebd5..b849991 100644
--- a/cli/main.go
+++ b/cli/main.go
@@ -23,15 +23,22 @@
"os/exec"
"github.com/opencord/voltha-go/cli/menu/mainmenu"
+ l "github.com/opencord/voltha-lib-go/v2/pkg/log"
"google.golang.org/grpc"
)
func main() {
// disable input buffering
- exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
+ err := exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
+ if err != nil {
+ l.Errorw("unable-to-configure-terminal-session-parameters-cbreak-and-min", l.Fields{"error": err})
+ }
// do not display entered characters on the screen
- exec.Command("stty", "-F", "/dev/tty", "-echo").Run()
+ err = exec.Command("stty", "-F", "/dev/tty", "-echo").Run()
+ if err != nil {
+ l.Errorw("unable-to-configure-terminal-session-parameter-echo", l.Fields{"error": err})
+ }
printHeader()
volthaAddress := flag.String("voltha_address", "localhost:6161", "IP/Hostname:Port for Voltha Core")
diff --git a/cli/menu/devicemenu/deviceMenu.go b/cli/menu/devicemenu/deviceMenu.go
index 134c46d..a392e95 100644
--- a/cli/menu/devicemenu/deviceMenu.go
+++ b/cli/menu/devicemenu/deviceMenu.go
@@ -29,7 +29,7 @@
*/
var (
Conn *grpc.ClientConn
- DeviceId *string
+ DeviceID *string
InputPrompt *string
Commands *[]string
)
@@ -37,10 +37,10 @@
/*
MainLoop - the loop which processes commands at the main level
*/
-func MainLoop(conn *grpc.ClientConn, deviceId string) {
+func MainLoop(conn *grpc.ClientConn, deviceID string) {
- DeviceId = &deviceId
- inputPrompt := fmt.Sprint("(" + color.LightRed("device "+deviceId) + ") ")
+ DeviceID = &deviceID
+ inputPrompt := fmt.Sprint("(" + color.LightRed("device "+deviceID) + ") ")
InputPrompt = &inputPrompt
funcTable := make(map[string]func(bool))
// inputPromptSize := len(inputPrompt)
@@ -52,7 +52,7 @@
funcTable["img_dnld_request"] = doImgDnldRequest
funcTable["perf_config"] = doPerfConfig
funcTable["save"] = doSave
- funcTable["eof"] = doEof
+ funcTable["eof"] = doEOF
funcTable["images"] = doImages
funcTable["img_dnld_status"] = doImgDnldStatus
funcTable["ports"] = doPorts
@@ -73,7 +73,7 @@
commands := make([]string, len(funcTable))
i := 0
- for key, _ := range funcTable {
+ for key := range funcTable {
commands[i] = key
i++
}
diff --git a/cli/menu/devicemenu/eof.go b/cli/menu/devicemenu/eof.go
index e4309bf..2c73b26 100644
--- a/cli/menu/devicemenu/eof.go
+++ b/cli/menu/devicemenu/eof.go
@@ -18,6 +18,6 @@
import "fmt"
-func doEof(enterPressed bool) {
- fmt.Println("doEof")
+func doEOF(enterPressed bool) {
+ fmt.Println("doEOF")
}
diff --git a/cli/menu/devicemenu/help.go b/cli/menu/devicemenu/help.go
index 6ebe8d9..8df6a20 100644
--- a/cli/menu/devicemenu/help.go
+++ b/cli/menu/devicemenu/help.go
@@ -22,6 +22,7 @@
"strings"
"github.com/opencord/voltha-go/cli/util"
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
)
func doHelp(enterPressed bool) {
@@ -29,7 +30,10 @@
var b = make([]byte, 1)
inputPrompt := *InputPrompt + "help "
for {
- os.Stdin.Read(b)
+ _, err := os.Stdin.Read(b)
+ if err != nil {
+ log.Errorw("unable-to-read-from-stdin-file", log.Fields{"error": err})
+ }
char := string(b)
if char == "\t" || char == "\n" || char == "?" {
if enterPressed {
diff --git a/cli/menu/devicemenu/show.go b/cli/menu/devicemenu/show.go
index c1680a8..fc56eed 100644
--- a/cli/menu/devicemenu/show.go
+++ b/cli/menu/devicemenu/show.go
@@ -28,8 +28,8 @@
func doShow(enterPressed bool) {
client := voltha.NewVolthaServiceClient(Conn)
- fmt.Println(*DeviceId)
- device, err := client.GetDevice(context.Background(), &common.ID{Id: *DeviceId})
+ fmt.Println(*DeviceID)
+ device, err := client.GetDevice(context.Background(), &common.ID{Id: *DeviceID})
if err != nil {
fmt.Println(err)
}
@@ -46,10 +46,10 @@
Type["value"] = device.Type
rows = append(rows, Type)
- parentId := make(map[string]string)
- parentId["field"] = "parent_id"
- parentId["value"] = device.ParentId
- rows = append(rows, parentId)
+ parentID := make(map[string]string)
+ parentID["field"] = "parent_id"
+ parentID["value"] = device.ParentId
+ rows = append(rows, parentID)
vlan := make(map[string]string)
vlan["field"] = "vlan"
@@ -62,20 +62,20 @@
rows = append(rows, adminState)
proxyAddress := device.GetProxyAddress()
- proxyDeviceId := make(map[string]string)
- proxyDeviceId["field"] = "proxy_address.device_id"
- proxyDeviceId["value"] = proxyAddress.DeviceId
- rows = append(rows, proxyDeviceId)
+ proxyDeviceID := make(map[string]string)
+ proxyDeviceID["field"] = "proxy_address.device_id"
+ proxyDeviceID["value"] = proxyAddress.DeviceId
+ rows = append(rows, proxyDeviceID)
proxyDeviceType := make(map[string]string)
proxyDeviceType["field"] = "proxy_address.device_type"
proxyDeviceType["value"] = proxyAddress.DeviceType
rows = append(rows, proxyDeviceType)
- proxyChannelId := make(map[string]string)
- proxyChannelId["field"] = "proxy_address.channel_id"
- proxyChannelId["value"] = strconv.FormatUint(uint64(proxyAddress.ChannelId), 10)
- rows = append(rows, proxyChannelId)
+ proxyChannelID := make(map[string]string)
+ proxyChannelID["field"] = "proxy_address.channel_id"
+ proxyChannelID["value"] = strconv.FormatUint(uint64(proxyAddress.ChannelId), 10)
+ rows = append(rows, proxyChannelID)
parentPortNumber := make(map[string]string)
parentPortNumber["field"] = "parent_port_no"
diff --git a/cli/menu/mainmenu/device.go b/cli/menu/mainmenu/device.go
index d2c4b15..23f71a5 100644
--- a/cli/menu/mainmenu/device.go
+++ b/cli/menu/mainmenu/device.go
@@ -25,6 +25,7 @@
"github.com/golang/protobuf/ptypes/empty"
"github.com/opencord/voltha-go/cli/menu/devicemenu"
"github.com/opencord/voltha-go/cli/util"
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-protos/v2/go/voltha"
)
@@ -36,19 +37,22 @@
if err != nil {
fmt.Println(err)
}
- deviceIds := []string{"exit", "quit"}
+ deviceIDs := []string{"exit", "quit"}
for i := 0; i < len(items); i++ {
- deviceIds = append(deviceIds, items[i].Id)
+ deviceIDs = append(deviceIDs, items[i].Id)
}
var b = make([]byte, 1)
input := ""
for {
- os.Stdin.Read(b)
+ _, err := os.Stdin.Read(b)
+ if err != nil {
+ log.Errorw("unable-to-read-from-stdin-file", log.Fields{"error": err})
+ }
char := string(b)
if char == "\t" || char == "\n" || char == "?" {
fmt.Println("")
- ret, prompt := util.Test(input, deviceIds)
+ ret, prompt := util.Test(input, deviceIDs)
if len(ret) == 1 {
input = ret[0]
if input == "quit" {
diff --git a/cli/util/menuProcessor.go b/cli/util/menuProcessor.go
index 52bf6bb..e0cfbc3 100644
--- a/cli/util/menuProcessor.go
+++ b/cli/util/menuProcessor.go
@@ -19,6 +19,8 @@
import (
"fmt"
"os"
+
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
)
/*
@@ -33,7 +35,10 @@
input := ""
fmt.Print(inputPrompt)
for {
- os.Stdin.Read(b)
+ _, err := os.Stdin.Read(b)
+ if err != nil {
+ log.Errorw("unable-to-read-from-stdin-file", log.Fields{"error": err})
+ }
char := string(b)
if char == "\t" || char == "\n" || char == "?" {
fmt.Println("")
diff --git a/cli/util/parseCmd.go b/cli/util/parseCmd.go
index 8f9d13d..aa78589 100644
--- a/cli/util/parseCmd.go
+++ b/cli/util/parseCmd.go
@@ -21,6 +21,7 @@
"strings"
)
+// Test makes a bunch on new commands available
func Test(chars string, values []string) ([]string, string) {
var ret []string
@@ -56,12 +57,14 @@
return ret, chars
}
+// Route will fetch information with respect to table fields
func Route(command string, table map[string]func(bool), enterPressed bool) {
cmd := table[command]
cmd(enterPressed)
}
+// Exit will come out of connected session
func Exit(notUsed bool) {
os.Exit(0)
}
diff --git a/cli/util/tableGen.go b/cli/util/tableGen.go
index 8ead5fd..7672eb5 100644
--- a/cli/util/tableGen.go
+++ b/cli/util/tableGen.go
@@ -21,6 +21,7 @@
"strings"
)
+// BuildTable populates input data in tabular format
func BuildTable(keys []string, rows []map[string]string) (string, error) {
var returnString string
fieldSizes := make(map[string]int)