Skip to content

Commit

Permalink
minor linter warning fixes (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn authored May 27, 2022
1 parent 90205c3 commit 8465f6c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
27 changes: 14 additions & 13 deletions cmd/wifiqr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
pskDesc = "network key (password)"
)

var version string = "develop"
var version = "develop"

// generateCode creates a WiFi QR code.
func generateCode(ssid, key string, encoding wifiqr.EncryptionProtocol, hidden bool) (*qrcode.QRCode, error) {
Expand All @@ -39,7 +39,7 @@ func validateAndGetFilename(filename string) string {
const pngExt = ".png"

if filepath.Ext(filename) != pngExt {
filename = filename + pngExt
filename += pngExt
}

return filename
Expand Down Expand Up @@ -77,7 +77,7 @@ func getInput(prompt string, validate func(string) error) (string, error) {

// inputValidator is a generic function for getting user input if the value is empty.
func inputValidator(value, prompt string, validate func(string) error) (string, error) {
var err error = nil
var err error

if value == "" {
value, err = getInput(prompt, validate)
Expand Down Expand Up @@ -134,15 +134,15 @@ func validateEncryption(protocol string) (wifiqr.EncryptionProtocol, error) {
},
}

_, enc, err := prompt.Run()
_, enc, _ := prompt.Run()

return wifiqr.NewEncryptionProtocol(enc)
}

// process generates the QR code given the parameters and can be
// considered to be a layer below that of the CLI.
func process(ssid, protocolIn, output string, pixels int, key string, keySet bool, hidden bool) int {
var err error = nil
var err error

ssid, err = validateSSID(ssid)
if err != nil {
Expand Down Expand Up @@ -207,14 +207,15 @@ the command line, the user will be prompted for the information.`,

rootCmd.Flags().StringVarP(&ssid, "ssid", "i", "", "Wireless network name")
rootCmd.Flags().StringVarP(&key, optionKey, "k", "", "Wireless password (pre-shared key / PSK)")
rootCmd.Flags().StringVarP(&protocolIn, "protocol", "p", wifiqr.WPA2.String(), "Wireless network encryption protocol ("+
strings.Join([]string{
wifiqr.WPA2.String(),
wifiqr.WPA.String(),
wifiqr.WEP.String(),
wifiqr.NONE.String(),
}, ", ")+
").")
rootCmd.Flags().StringVarP(&protocolIn, "protocol", "p", wifiqr.WPA2.String(),
"Wireless network encryption protocol ("+
strings.Join([]string{
wifiqr.WPA2.String(),
wifiqr.WPA.String(),
wifiqr.WEP.String(),
wifiqr.NONE.String(),
}, ", ")+
").")
rootCmd.Flags().BoolVarP(&hidden, "hidden", "", false, "Hidden SSID")
rootCmd.Flags().StringVarP(&output, "output", "o", "", "PNG file for output (default stdout)")
rootCmd.Flags().IntVarP(&pixels, "size", "s", 256, "Image width and height in pixels")
Expand Down
6 changes: 4 additions & 2 deletions cmd/wifiqr/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func Test_generateCode(t *testing.T) {
encoding: wifiqr.WPA2,
hidden: false,
},
want: [32]byte{117, 113, 240, 31, 70, 131, 178, 237, 61, 56, 190, 135, 145, 86, 173, 81, 244, 78, 103, 173, 103, 188, 82, 70, 79, 180, 149, 217, 5, 113, 227, 25},
want: [32]byte{117, 113, 240, 31, 70, 131, 178, 237, 61, 56, 190, 135, 145, 86, 173, 81,
244, 78, 103, 173, 103, 188, 82, 70, 79, 180, 149, 217, 5, 113, 227, 25},
wantErr: false,
},
{
Expand Down Expand Up @@ -79,7 +80,8 @@ func Test_generateCode(t *testing.T) {
} else {
hash := sha256.Sum256(data)
if tt.want != hash {
t.Errorf("generateCode() png data does not match wanted hash, got: %v, want %v", byteString(hash), byteString(tt.want))
t.Errorf("generateCode() png data does not match wanted hash, got: %v, want %v",
byteString(hash), byteString(tt.want))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion wifiqr.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func escapeString(s string) string {
// https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11

for _, c := range []byte{'\\', ';', ',', '"', ':'} {
s = strings.Replace(s, string(c), `\`+string(c), -1)
s = strings.ReplaceAll(s, string(c), `\`+string(c))
}

return s
Expand Down

0 comments on commit 8465f6c

Please sign in to comment.