Skip to content

Commit

Permalink
Address golangci-lint warnings in source code
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodangelis authored Mar 11, 2022
1 parent 6f12a53 commit 6153f25
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 36 deletions.
16 changes: 12 additions & 4 deletions cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ $ qrcp completion fish > ~/.config/fish/completions/qrcp.fish
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
cmd.Root().GenBashCompletion(os.Stdout)
if err := cmd.Root().GenBashCompletion(os.Stdout); err != nil {
panic(err)
}
case "zsh":
cmd.Root().GenZshCompletion(os.Stdout)
if err := cmd.Root().GenZshCompletion(os.Stdout); err != nil {
panic(err)
}
case "fish":
cmd.Root().GenFishCompletion(os.Stdout, true)
if err := cmd.Root().GenFishCompletion(os.Stdout, true); err != nil {
panic(err)
}
case "powershell":
cmd.Root().GenPowerShellCompletion(os.Stdout)
if err := cmd.Root().GenPowerShellCompletion(os.Stdout); err != nil {
panic(err)
}
}
},
}
12 changes: 7 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func chooseInterface(opts Options) (string, error) {
return "", errors.New("no interfaces found")
}

if len(interfaces) == 1 && opts.Interactive == false {
if len(interfaces) == 1 && !opts.Interactive {
for name := range interfaces {
fmt.Printf("only one interface found: %s, using this one\n", name)
return name, nil
Expand Down Expand Up @@ -134,7 +134,7 @@ func Wizard(path string, listAllInterfaces bool) error {
cfg.Interface = iface
// Ask for fully qualified domain name
validateFqdn := func(input string) error {
if input != "" && govalidator.IsDNSName(input) == false {
if input != "" && !govalidator.IsDNSName(input) {
return errors.New("invalid domain")
}
return nil
Expand All @@ -151,7 +151,7 @@ func Wizard(path string, listAllInterfaces bool) error {
validatePort := func(input string) error {
_, err := strconv.ParseUint(input, 10, 16)
if err != nil {
return errors.New("Invalid number")
return errors.New("invalid number")
}
return nil
}
Expand Down Expand Up @@ -311,7 +311,9 @@ func setConfigFile(path string) error {
// exists
var configDir = filepath.Join(xdg.ConfigHome, "qrcp")
if !pathExists(configDir) {
os.Mkdir(configDir, 0744)
if err := os.Mkdir(configDir, 0744); err != nil {
panic(err)
}
}
configFile = filepath.Join(configDir, "config.json")
return nil
Expand Down Expand Up @@ -348,7 +350,7 @@ func New(path string, opts Options) (Config, error) {
cfg.Interface = opts.Interface
}
if opts.FQDN != "" {
if govalidator.IsDNSName(opts.FQDN) == false {
if !govalidator.IsDNSName(opts.FQDN) {
return cfg, errors.New("invalid value for fully-qualified domain name")
}
cfg.FQDN = opts.FQDN
Expand Down
2 changes: 1 addition & 1 deletion logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

// Print prints its argument if the --quiet flag is not passed
func (l Logger) Print(args ...interface{}) {
if l.quiet == false {
if !l.quiet {
fmt.Println(args...)
}
}
Expand Down
12 changes: 8 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ func (s *Server) DisplayQR(url string) {
qrImg := qr.RenderImage(url)
http.HandleFunc(PATH, func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "image/jpeg")
jpeg.Encode(w, qrImg, nil)
if err := jpeg.Encode(w, qrImg, nil); err != nil {
panic(err)
}
})
openBrowser(s.BaseURL + PATH)
}
Expand All @@ -84,7 +86,9 @@ func (s Server) Wait() error {
log.Println(err)
}
if s.payload.DeleteAfterTransfer {
s.payload.Delete()
if err := s.payload.Delete(); err != nil {
panic(err)
}
}
return nil
}
Expand Down Expand Up @@ -156,7 +160,7 @@ func New(cfg *config.Config) (*Server, error) {
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
},
},
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler), 0),
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)),
}
// Create channel to send message to stop server
app.stopChannel = make(chan bool)
Expand Down Expand Up @@ -293,7 +297,7 @@ func New(cfg *config.Config) (*Server, error) {
// Set the value of the variable to the actually transferred files
htmlVariables.File = strings.Join(transferredFiles, ", ")
serveTemplate("done", pages.Done, w, htmlVariables)
if cfg.KeepAlive == false {
if !cfg.KeepAlive {
app.stopChannel <- true
}
case "GET":
Expand Down
8 changes: 6 additions & 2 deletions server/tcpkeepalivelistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ func (ln tcpKeepAliveListener) Accept() (net.Conn, error) {
if err != nil {
return nil, err
}
tc.SetKeepAlive(true)
tc.SetKeepAlivePeriod(3 * time.Minute)
if err := tc.SetKeepAlive(true); err != nil {
panic(err)
}
if err := tc.SetKeepAlivePeriod(3 * time.Minute); err != nil {
panic(err)
}
return tc, nil
}
2 changes: 1 addition & 1 deletion util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Interfaces(listAll bool) (map[string]string, error) {
}
var re = regexp.MustCompile(`^(veth|br\-|docker|lo|EHC|XHC|bridge|gif|stf|p2p|awdl|utun|tun|tap)`)
for _, iface := range ifaces {
if listAll == false && re.MatchString(iface.Name) {
if !listAll && re.MatchString(iface.Name) {
continue
}
if iface.Flags&net.FlagUp == 0 {
Expand Down
26 changes: 7 additions & 19 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"os/user"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -45,14 +44,18 @@ func ZipFiles(files []string) (string, error) {
if err := os.Rename(tmpfile.Name(), tmpfile.Name()+".zip"); err != nil {
return "", err
}
zip.Create(tmpfile.Name() + ".zip")
if err := zip.Create(tmpfile.Name() + ".zip"); err != nil {
return "", err
}
for _, filename := range files {
fileinfo, err := os.Stat(filename)
if err != nil {
return "", err
}
if fileinfo.IsDir() {
zip.AddAll(filename, true)
if err := zip.AddAll(filename, true); err != nil {
return "", err
}
} else {
file, err := os.Open(filename)
if err != nil {
Expand Down Expand Up @@ -138,26 +141,11 @@ func FindIP(iface net.Interface) (string, error) {
}
}
if ip == "" {
return "", errors.New("Unable to find an IP for this interface")
return "", errors.New("unable to find an IP for this interface")
}
return ip, nil
}

func filterInterfaces(ifaces []net.Interface) []net.Interface {
filtered := []net.Interface{}
var re = regexp.MustCompile(`^(veth|br\-|docker|lo|EHC|XHC|bridge|gif|stf|p2p|awdl|utun|tun|tap)`)
for _, iface := range ifaces {
if re.MatchString(iface.Name) {
continue
}
if iface.Flags&net.FlagUp == 0 {
continue
}
filtered = append(filtered, iface)
}
return filtered
}

// ReadFilenames from dir
func ReadFilenames(dir string) []string {
files, err := ioutil.ReadDir(dir)
Expand Down

0 comments on commit 6153f25

Please sign in to comment.