From 4be2f5e6e2484b79aab839fb76276a31cd5f60a4 Mon Sep 17 00:00:00 2001 From: Cyrille Nofficial Date: Sat, 20 Aug 2022 21:38:19 +0200 Subject: [PATCH] refactor: remove redounded naming --- pkg/steering/controller.go | 18 +++++++++--------- pkg/steering/controller_test.go | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/steering/controller.go b/pkg/steering/controller.go index 548920e..ba465ec 100644 --- a/pkg/steering/controller.go +++ b/pkg/steering/controller.go @@ -9,8 +9,8 @@ import ( "sync" ) -func NewController(client mqtt.Client, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic string, debug bool) *SteeringController { - return &SteeringController{ +func NewController(client mqtt.Client, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic string, debug bool) *Controller { + return &Controller{ client: client, steeringTopic: steeringTopic, driveModeTopic: driveModeTopic, @@ -21,7 +21,7 @@ func NewController(client mqtt.Client, steeringTopic, driveModeTopic, rcSteering } -type SteeringController struct { +type Controller struct { client mqtt.Client steeringTopic string @@ -34,7 +34,7 @@ type SteeringController struct { debug bool } -func (p *SteeringController) Start() error { +func (p *Controller) Start() error { if err := registerCallbacks(p); err != nil { zap.S().Errorf("unable to rgeister callbacks: %v", err) return err @@ -45,12 +45,12 @@ func (p *SteeringController) Start() error { return nil } -func (p *SteeringController) Stop() { +func (p *Controller) Stop() { close(p.cancel) service.StopService("throttle", p.client, p.driveModeTopic, p.rcSteeringTopic, p.tfSteeringTopic) } -func (p *SteeringController) onDriveMode(_ mqtt.Client, message mqtt.Message) { +func (p *Controller) onDriveMode(_ mqtt.Client, message mqtt.Message) { var msg events.DriveModeMessage err := proto.Unmarshal(message.Payload(), &msg) if err != nil { @@ -63,7 +63,7 @@ func (p *SteeringController) onDriveMode(_ mqtt.Client, message mqtt.Message) { p.driveMode = msg.GetDriveMode() } -func (p *SteeringController) onRCSteering(_ mqtt.Client, message mqtt.Message) { +func (p *Controller) onRCSteering(_ mqtt.Client, message mqtt.Message) { p.muDriveMode.RLock() defer p.muDriveMode.RUnlock() if p.debug { @@ -81,7 +81,7 @@ func (p *SteeringController) onRCSteering(_ mqtt.Client, message mqtt.Message) { publish(p.client, p.steeringTopic, &payload) } } -func (p *SteeringController) onTFSteering(_ mqtt.Client, message mqtt.Message) { +func (p *Controller) onTFSteering(_ mqtt.Client, message mqtt.Message) { p.muDriveMode.RLock() defer p.muDriveMode.RUnlock() if p.debug { @@ -100,7 +100,7 @@ func (p *SteeringController) onTFSteering(_ mqtt.Client, message mqtt.Message) { } } -var registerCallbacks = func(p *SteeringController) error { +var registerCallbacks = func(p *Controller) error { err := service.RegisterCallback(p.client, p.driveModeTopic, p.onDriveMode) if err != nil { return err diff --git a/pkg/steering/controller_test.go b/pkg/steering/controller_test.go index 8f11cca..f1bc38b 100644 --- a/pkg/steering/controller_test.go +++ b/pkg/steering/controller_test.go @@ -17,7 +17,7 @@ func TestDefaultSteering(t *testing.T) { registerCallbacks = oldRegister publish = oldPublish }() - registerCallbacks = func(p *SteeringController) error { + registerCallbacks = func(p *Controller) error { return nil } @@ -104,7 +104,7 @@ func TestDefaultSteering(t *testing.T) { if msg.GetSteering() != c.expectedSteering.GetSteering() { t.Errorf("bad msg value for mode %v: %v, wants %v", - c.driveMode, msg.GetSteering(), c.expectedSteering.GetSteering()) + c.driveMode.String(), msg.GetSteering(), c.expectedSteering.GetSteering()) } if msg.GetConfidence() != 1. { t.Errorf("bad throtlle confidence: %v, wants %v", msg.GetConfidence(), 1.)