Skip to content

Commit

Permalink
feat: remove debug logs and actually check errs for json marshal
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Gleich <[email protected]>
  • Loading branch information
gleich committed Jul 27, 2024
1 parent f37541a commit 6d19a2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 0 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -76,8 +75,6 @@ func main() {
lumber.Success("init steam cache")
go steamCache.PeriodicUpdate(steam.FetchRecentlyPlayedGames, 5*time.Minute)

fmt.Println()
lumber.Info("STARTING SERVER")
err = http.ListenAndServe(":8000", r)
if err != nil {
lumber.Fatal(err, "failed to start router")
Expand Down
15 changes: 10 additions & 5 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ func (c *Cache[T]) Route() http.HandlerFunc {
func (c *Cache[T]) Update(data T) {
var updated bool
c.mutex.Lock()
lumber.Debug(c.Name)
old, _ := json.Marshal(c.data)
lumber.Debug("old cache:", string(old))
new, _ := json.Marshal(data)
lumber.Debug("new cache:", string(new))
old, err := json.Marshal(c.data)
if err != nil {
lumber.Error(err, "failed to json marshal old data")
return
}
new, err := json.Marshal(data)
if err != nil {
lumber.Error(err, "failed to json marshal new data")
return
}
if string(old) != string(new) {
c.data = data
c.updated = time.Now()
Expand Down

0 comments on commit 6d19a2c

Please sign in to comment.