From a29b8b291f47f36f4e3854ca9adff4aed97c126c Mon Sep 17 00:00:00 2001 From: Aleksey Lobanov Date: Sun, 27 Mar 2016 01:57:32 +0300 Subject: [PATCH] Fixed some golint warnings --- src/main.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main.go b/src/main.go index d51de68..bd2571f 100644 --- a/src/main.go +++ b/src/main.go @@ -16,12 +16,13 @@ import ( ) const ( - SLEEP_TIME = 3 * time.Second + SLEEP_TIME = 3 * time.Second // time between processing xinput output KEYBOARD_BUFER_SIZE = 10000 DATABASE_NAME = "file:gokeystat.db?cache=shared&mode=rwc" CAPTURE_TIME = 5 // time in seconds between capturing keyboard to db ) +// StatForTime stotres pressed keys and beginning time type StatForTime struct { time int64 keys map[uint8]int @@ -32,12 +33,12 @@ func (stat *StatForTime) Init() { stat.keys = make(map[uint8]int) } -// Return map from key numbers to key names like "F1", "Tab", "d" +// GetKeymap returns map from key numbers to key names like "F1", "Tab", "d" func GetKeymap() map[uint8]string { return GetKeymapFromOutput(GetKeymapOutput()) } -// Return output of utility that prints system keymap +// GetKeymapOutput returns output of utility that prints system keymap func GetKeymapOutput() []byte { cmd := exec.Command("xmodmap", "-pke") out, err := cmd.Output() @@ -47,7 +48,7 @@ func GetKeymapOutput() []byte { return out } -// Return map with keymap from text +// GetKeymapFromOutput returns map with keymap from text func GetKeymapFromOutput(buf []byte) map[uint8]string { const KEY_NUM_STRING_RE = "\\d+[ ]*=[ ]*\\S+" re := regexp.MustCompile(KEY_NUM_STRING_RE) @@ -62,7 +63,7 @@ func GetKeymapFromOutput(buf []byte) map[uint8]string { return keyMap } -// Extract pressed keys from bufer buf +// GetKeyNumsFromOutput extract pressed keys from bufer buf // It returns slice with key numbers in the same order func GetKeyNumsFromOutput(buf []byte) []uint8 { const KEY_NUM_STRING_RE = "press[ ]+(\\d+)" @@ -90,7 +91,7 @@ func GetKeyNumsFromKeyMap(keyMap map[uint8]string) []int { return res } -// Creates tables, inserts keymap to db +// InitDb creates tables, inserts keymap to db func InitDb(db *sql.DB, keyMap map[uint8]string) { keyNums := GetKeyNumsFromKeyMap(keyMap) @@ -172,7 +173,7 @@ func AddStatTimeToDb(db *sql.DB, statTime StatForTime, keyMap map[uint8]string) tx.Commit() } -// Returns slice with StatForTime objects that +// GetStatTimesFromDb returns slice with StatForTime objects that func GetStatTimesFromDb(db *sql.DB, fromTime int64, keyMap map[uint8]string) []StatForTime { sqlStmt := "select * from keylog where time > " + strconv.FormatInt(fromTime, 10) rows, err := db.Query(sqlStmt) @@ -190,7 +191,7 @@ func GetStatTimesFromDb(db *sql.DB, fromTime int64, keyMap map[uint8]string) []S result := make([]int64, len(cols)) dest := make([]interface{}, len(cols)) // A temporary interface{} slice - for i, _ := range rawResult { + for i := range rawResult { dest[i] = &rawResult[i] // Put pointers to each string in the interface slice } @@ -237,15 +238,15 @@ func GetStatTimesFromDb(db *sql.DB, fromTime int64, keyMap map[uint8]string) []S func main() { - keyboardId := flag.Int("id", -1, "Your keyboard id") + keyboardID := flag.Int("id", -1, "Your keyboard id") outputPath := flag.String("o", "", "Path to export file") flag.Parse() - log.Println("keyboardId =", *keyboardId, "outputPath =", *outputPath) + log.Println("keyboardID =", *keyboardID, "outputPath =", *outputPath) switch { - case *keyboardId == -1 && *outputPath == "": + case *keyboardID == -1 && *outputPath == "": flag.PrintDefaults() return - case *keyboardId != -1: + case *keyboardID != -1: // Opening database db, err := sql.Open("sqlite3", DATABASE_NAME) if err != nil { @@ -259,7 +260,7 @@ func main() { InitDb(db, keyMap) - cmd := exec.Command("xinput", "test", strconv.Itoa(*keyboardId)) + cmd := exec.Command("xinput", "test", strconv.Itoa(*keyboardID)) stdout, err := cmd.StdoutPipe() if err != nil {