diff --git a/core/th7/th7.go b/core/th7/th7.go index 36e2b00..99eb928 100644 --- a/core/th7/th7.go +++ b/core/th7/th7.go @@ -52,11 +52,11 @@ func (t *TH7Adapter) GetChannel(id int) (core.Channel, error) { return core.Channel{}, errors.New("specified channel not configured") } -func (t *TH7Adapter) GetChannels() ([]core.Channel, error) { +func (t *TH7Adapter) GetChannels() []core.Channel { t.mu.Lock() defer t.mu.Unlock() - return t.data, nil + return t.data } func (t *TH7Adapter) GetVref() float64 { diff --git a/db/logging.go b/db/logging.go index 2b3c2ab..6bcdc29 100644 --- a/db/logging.go +++ b/db/logging.go @@ -11,14 +11,11 @@ func startLoggingProcess(db ports.DBPort, core ports.CorePort, dur time.Duration // wait 10 seconds to not log start up values that can be noisy time.Sleep(10 * time.Second) - for true { + for { - val, err := core.GetChannels() - if err != nil { - fmt.Printf("Error encountered while getting values: %v\n", err) - } + val := core.GetChannels() - err = db.Save(val) + err := db.Save(val) if err != nil { fmt.Printf("Error encountered while saving values: %v\n", err) } diff --git a/db/sqlite3.go b/db/sqlite3.go index 5c4cdbc..995c086 100644 --- a/db/sqlite3.go +++ b/db/sqlite3.go @@ -51,7 +51,6 @@ func NewSQLite3Adapter(dbInfo map[string]interface{}) (*SQLite3Adapter, error) { func (ad *SQLite3Adapter) Close() { ad.db.Close() - return } func (ad *SQLite3Adapter) Save([]core.Channel) error { diff --git a/ports/core.go b/ports/core.go index 870e527..4912acd 100644 --- a/ports/core.go +++ b/ports/core.go @@ -4,7 +4,7 @@ import "th7/data/core" type CorePort interface { GetChannel(int) (core.Channel, error) - GetChannels() ([]core.Channel, error) + GetChannels() []core.Channel GetVref() float64 GetVadj() float64 GetPivdd() float64 diff --git a/web/gin.go b/web/gin.go index f590f51..bbe4be8 100644 --- a/web/gin.go +++ b/web/gin.go @@ -17,15 +17,8 @@ type GinAdapter struct { func (g GinAdapter) registerEndpoints() { g.router.GET("/channels", func(c *gin.Context) { - channels, err := g.corePort.GetChannels() - if err != nil { - c.JSON(http.StatusInternalServerError, gin.H{ - "error": err, - }) - } else { - c.JSON(http.StatusOK, channels) - } - + channels := g.corePort.GetChannels() + c.JSON(http.StatusOK, channels) }) g.router.GET("/channel/:id", func(c *gin.Context) {