Skip to content

Commit

Permalink
Merge pull request #202 from markusressel/feature/linting
Browse files Browse the repository at this point in the history
linting
  • Loading branch information
markusressel authored Mar 15, 2023
2 parents da70287 + b4f9298 commit 2926ab4
Show file tree
Hide file tree
Showing 31 changed files with 184 additions and 202 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,32 @@ jobs:
- name: Test
run: make test

- name: Run golangci-lint
uses: golangci/[email protected]
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.51.1

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --exclude-use-default
# --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true

- name: Build
run: make build

Expand Down
3 changes: 1 addition & 2 deletions cmd/curve/curve.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package curve

import (
"errors"
"fmt"
"github.com/markusressel/fan2go/internal/configuration"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -33,5 +32,5 @@ func getCurveConfig(id string, curves []configuration.CurveConfig) (*configurati
}
}

return nil, errors.New(fmt.Sprintf("No curve with id found: %s, options: %s", id, availableCurveIds))
return nil, fmt.Errorf("no curve with id found: %s, options: %s", id, availableCurveIds)
}
4 changes: 1 addition & 3 deletions cmd/curve/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ var curveCmd = &cobra.Command{
}
curveConfigsToPrint = append(curveConfigsToPrint, *curveConf)
} else {
for _, curveConfig := range configuration.CurrentConfig.Curves {
curveConfigsToPrint = append(curveConfigsToPrint, curveConfig)
}
curveConfigsToPrint = append(curveConfigsToPrint, configuration.CurrentConfig.Curves...)
}

for idx, curveConfig := range curveConfigsToPrint {
Expand Down
2 changes: 1 addition & 1 deletion cmd/fan/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var curveCmd = &cobra.Command{
}

for idx, fan := range fanList {
if &fanId != nil && fan.GetId() != fanId {
if fan.GetId() != fanId {
continue
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/fan/fan.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fan

import (
"errors"
"fmt"

"github.com/markusressel/fan2go/internal/configuration"
Expand Down Expand Up @@ -58,5 +57,5 @@ func getFan(id string) (fans.Fan, error) {
}
}

return nil, errors.New(fmt.Sprintf("No fan with id found: %s, options: %s", id, availableFanIds))
return nil, fmt.Errorf("no fan with id found: %s, options: %s", id, availableFanIds)
}
6 changes: 4 additions & 2 deletions cmd/fan/speed.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ var speedCmd = &cobra.Command{
}

if len(args) > 0 {
pwmValue, err := strconv.Atoi(args[0])
var pwmValue int
pwmValue, err = strconv.Atoi(args[0])
if err != nil {
return err
}
err = fan.SetPwm(pwmValue)
} else {
if pwm, err := fan.GetPwm(); err == nil {
var pwm int
if pwm, err = fan.GetPwm(); err == nil {
fmt.Printf("%d", pwm)
}
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"github.com/pterm/pterm/putils"
"os"

"github.com/markusressel/fan2go/cmd/config"
Expand Down Expand Up @@ -66,9 +67,9 @@ func setupUi() {
// Print a large text with the LetterStyle from the standard theme.
func printHeader() {
err := pterm.DefaultBigText.WithLetters(
pterm.NewLettersFromStringWithStyle("fan", pterm.NewStyle(pterm.FgLightBlue)),
pterm.NewLettersFromStringWithStyle("2", pterm.NewStyle(pterm.FgWhite)),
pterm.NewLettersFromStringWithStyle("go", pterm.NewStyle(pterm.FgLightBlue)),
putils.LettersFromStringWithStyle("fan", pterm.NewStyle(pterm.FgLightBlue)),
putils.LettersFromStringWithStyle("2", pterm.NewStyle(pterm.FgWhite)),
putils.LettersFromStringWithStyle("go", pterm.NewStyle(pterm.FgLightBlue)),
).Render()
if err != nil {
fmt.Println("fan2go")
Expand Down
7 changes: 3 additions & 4 deletions cmd/sensor/sensor.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sensor

import (
"errors"
"fmt"
"github.com/markusressel/fan2go/internal/configuration"
"github.com/markusressel/fan2go/internal/hwmon"
Expand Down Expand Up @@ -66,13 +65,13 @@ func getSensor(id string) (sensors.Sensor, error) {
for _, controller := range controllers {
matched, err := regexp.MatchString("(?i)"+config.HwMon.Platform, controller.Platform)
if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to match platform regex of %s (%s) against controller platform %s", config.ID, config.HwMon.Platform, controller.Platform))
return nil, fmt.Errorf("Failed to match platform regex of %s (%s) against controller platform %s", config.ID, config.HwMon.Platform, controller.Platform)
}
if matched {
sensor, exists := controller.Sensors[config.HwMon.Index]
if exists {
if len(sensor.Input) <= 0 {
return nil, errors.New(fmt.Sprintf("Unable to find temp input for sensor %s", id))
return nil, fmt.Errorf("unable to find temp input for sensor %s", id)
}
config.HwMon.TempInput = sensor.Input
break
Expand All @@ -90,5 +89,5 @@ func getSensor(id string) (sensors.Sensor, error) {
}
}

return nil, errors.New(fmt.Sprintf("No sensor with id found: %s, options: %s", id, availableSensorIds))
return nil, fmt.Errorf("no sensor with id found: %s, options: %s", id, availableSensorIds)
}
34 changes: 15 additions & 19 deletions internal/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ func RunDaemon() {
ui.Error("Error running profiling webserver: %v", http.ListenAndServe(address, mux))
}()

select {
case <-ctx.Done():
ui.Info("Stopping profiling webserver...")
return nil
}
<-ctx.Done()
ui.Info("Stopping profiling webserver...")
return nil
}, func(err error) {
if err != nil {
ui.Warning("Error stopping parca webserver: " + err.Error())
Expand All @@ -82,20 +80,18 @@ func RunDaemon() {

servers := createWebServer()

select {
case <-ctx.Done():
ui.Debug("Stopping all webservers...")
timeoutCtx, timeoutCancel := context.WithTimeout(ctx, 5*time.Second)
defer timeoutCancel()

for _, server := range servers {
err := server.Shutdown(timeoutCtx)
if err != nil {
return err
}
<-ctx.Done()
ui.Debug("Stopping all webservers...")
timeoutCtx, timeoutCancel := context.WithTimeout(ctx, 5*time.Second)
defer timeoutCancel()

for _, server := range servers {
err := server.Shutdown(timeoutCtx)
if err != nil {
return err
}
return nil
}
return nil
}, func(err error) {
if err != nil {
ui.Warning("Error stopping webservers: " + err.Error())
Expand Down Expand Up @@ -151,8 +147,8 @@ func RunDaemon() {
}
}
{
sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM, os.Kill)
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)

g.Add(func() error {
<-sig
Expand Down
Loading

0 comments on commit 2926ab4

Please sign in to comment.