Compare commits

...

8 Commits

@ -11,7 +11,7 @@ steps:
- git fetch --tags
- name: lint
image: golangci/golangci-lint:v1.39.0
image: golangci/golangci-lint:v1.41.1
commands:
- make install-tools
- make lint

@ -9,3 +9,6 @@ build:
lint:
except:
- PACKAGE_DIRECTORY_MATCH
- RPC_REQUEST_STANDARD_NAME
- RPC_RESPONSE_STANDARD_NAME
- RPC_REQUEST_RESPONSE_UNIQUE

@ -78,8 +78,8 @@ func init() {
}
// Defaults.
viper.SetDefault("box.hostname", "localhost")
viper.SetDefault("box.port", 9999)
viper.SetDefault("web.hostname", "localhost")
viper.SetDefault("web.port", 9999)
viper.SetDefault("mpd.hostname", "localhost")
viper.SetDefault("mpd.port", 6600)
viper.SetDefault("reader.dev", "/dev/hidraw0")
@ -97,8 +97,8 @@ func init() {
"debug.pprof": rootCmd.PersistentFlags().Lookup("pprof"),
"reader.dev": prepareCmd.Flags().Lookup("rfid-reader"),
"reader.ignore": runCmd.Flags().Lookup("ignore-reader"),
"box.hostname": timerCmd.Flags().Lookup("hostname"),
"box.port": timerCmd.Flags().Lookup("port"),
"web.hostname": timerCmd.Flags().Lookup("hostname"),
"web.port": timerCmd.Flags().Lookup("port"),
"timer.duration": timerCmd.Flags().Lookup("duration"),
} {
if err := viper.BindPFlag(k, v); err != nil {

@ -20,11 +20,11 @@ type Config struct {
Dev string `mapstructure:"Dev"`
} `mapstructure:"Reader"`
// Box is used to configure a webinterface.
Box struct {
// Web is used to configure the webinterface.
Web struct {
Hostname string `mapstructure:"Hostname"`
Port int `mapstructure:"Port"`
} `mapstructure:"Box"`
} `mapstructure:"Web"`
// MPD contains the connection details for the Music Player Daemon.
MPD struct {

@ -7,6 +7,7 @@ import (
"github.com/fhs/gompd/v2/mpd"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"go.xsfx.dev/schnutibox/internal/config"
"go.xsfx.dev/schnutibox/internal/metrics"
)
@ -28,7 +29,7 @@ func Conn() (*mpd.Client, error) {
default:
c, err := mpd.Dial("tcp", fmt.Sprintf("%s:%d", config.Cfg.MPD.Hostname, config.Cfg.MPD.Port))
if err != nil {
// log.Error().Err(err).Msg("could not connect")
log.Error().Err(err).Msg("could not connect")
time.Sleep(timeoutWait)

@ -64,7 +64,7 @@ func boxService(filename string, enable bool) error {
return fmt.Errorf("could not get service file: %w", err)
}
//nolint:gosec
//nolint:gosec,gomnd
if err := ioutil.WriteFile(filename, schnutiboxService, 0o644); err != nil {
return fmt.Errorf("could not write service file: %w", err)
}
@ -106,7 +106,7 @@ func ntp() error {
return fmt.Errorf("could not get ntp service file: %w", err)
}
// nolint:gosec
// nolint:gosec,gomnd
if err := ioutil.WriteFile("/etc/systemd/system/ntp.service", ntpService, 0o644); err != nil {
return fmt.Errorf("could not copy ntp service file: %w", err)
}
@ -397,7 +397,7 @@ func cmdlineTxt() error {
newLine := strings.TrimSuffix(string(oldLine), "\n") + " " + "fastboot" + " " + "noswap"
// Write.
// nolint:gosec
// nolint:gosec,gomnd
if err := ioutil.WriteFile("/boot/cmdline.txt", []byte(newLine), 0o644); err != nil {
return fmt.Errorf("could not write cmdline.txt: %w", err)
}
@ -617,7 +617,7 @@ func upmpdcli() error {
return fmt.Errorf("could not get upmpdcli.conf: %w", err)
}
// nolint:gosec
// nolint:gosec,gomnd
if err := ioutil.WriteFile("/etc/upmpdcli.conf", upmpdcliConf, 0o644); err != nil {
return fmt.Errorf("could not copy upmpdcli config: %w", err)
}

@ -65,7 +65,7 @@ func (r *RFID) Run() error {
}
go func() {
buf := make([]byte, 3)
buf := make([]byte, 3) // nolint:gomnd
rfid := ""

@ -14,6 +14,7 @@ import (
"google.golang.org/protobuf/types/known/durationpb"
)
// T is the global Timer object.
// nolint:gochecknoglobals
var T = &Timer{}
@ -38,7 +39,7 @@ func (t *Timer) Handle() {
Msg("timer is running")
if t.Req.Current.Seconds > 0 {
t.Req.Current.Seconds -= 1
t.Req.Current.Seconds--
return
}
@ -58,11 +59,10 @@ func (t *Timer) Handle() {
// Run is the command line interface for triggering the timer.
func Run(cmd *cobra.Command, args []string) {
conn, err := grpcclient.Conn(config.Cfg.Box.Hostname, config.Cfg.Box.Port)
conn, err := grpcclient.Conn(config.Cfg.Web.Hostname, config.Cfg.Web.Port)
if err != nil {
log.Fatal().Err(err).Msg("could not connect")
}
defer conn.Close()
c := api.NewTimerServiceClient(conn)
@ -70,8 +70,10 @@ func Run(cmd *cobra.Command, args []string) {
_, err = c.Create(context.Background(), &api.Timer{Duration: d})
if err != nil {
conn.Close()
log.Fatal().Err(err).Msg("could not create timer")
}
conn.Close()
log.Info().Msg("added timer")
}

@ -111,7 +111,7 @@ func gw(s *grpc.Server, conn string) *runtime.ServeMux {
func Run(command *cobra.Command, args []string) {
// Create host string for serving web.
lh := fmt.Sprintf("%s:%d", config.Cfg.Box.Hostname, config.Cfg.Box.Port)
lh := fmt.Sprintf("%s:%d", config.Cfg.Web.Hostname, config.Cfg.Web.Port)
// Create grpc server.
grpcServer := grpc.NewServer(

Loading…
Cancel
Save