diff --git a/handlers/auth.go b/handlers/auth.go index 22bbbc7..4568182 100644 --- a/handlers/auth.go +++ b/handlers/auth.go @@ -127,7 +127,6 @@ func (h *Handler) handleGoogleCallback(c *gin.Context) { user.Email, }) - // Sign and get the complete encoded token as a string using the secret tokenString, err := token.SignedString(h.config.Secret) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("could not sign token: %v", err)}) diff --git a/handlers/handlers_test.go b/handlers/handlers_test.go index c76de94..ea86238 100644 --- a/handlers/handlers_test.go +++ b/handlers/handlers_test.go @@ -87,8 +87,7 @@ func TestCreateEntry(t *testing.T) { return } var parsed URLUtil - err = json.Unmarshal(respBody, &parsed) - if err != nil { + if err = json.Unmarshal(respBody, &parsed); err != nil { t.Fatalf("could not unmarshal data: %v", err) } t.Run("test if shorted URL is correct", func(t *testing.T) { @@ -114,8 +113,7 @@ func TestHandleInfo(t *testing.T) { } respBody := createEntryWithJSON(t, reqBody, "application/json; charset=utf-8", http.StatusOK) var parsed URLUtil - err = json.Unmarshal(respBody, &parsed) - if err != nil { + if err = json.Unmarshal(respBody, &parsed); err != nil { t.Fatalf("could not unmarshal data: %v", err) } body, err := json.Marshal(struct { @@ -134,8 +132,7 @@ func TestHandleInfo(t *testing.T) { t.Errorf("expected status %d; got %d", http.StatusOK, resp.StatusCode) } var entry store.Entry - err = json.NewDecoder(resp.Body).Decode(&entry) - if err != nil { + if err = json.NewDecoder(resp.Body).Decode(&entry); err != nil { t.Fatalf("could not unmarshal data: %v", err) } if entry.URL != testURL { diff --git a/handlers/public.go b/handlers/public.go index 9682587..5e2a22b 100644 --- a/handlers/public.go +++ b/handlers/public.go @@ -54,8 +54,7 @@ func (h *Handler) handleAccess(c *gin.Context) { // handleCreate handles requests to create an entry func (h *Handler) handleCreate(c *gin.Context) { var data URLUtil - err := c.ShouldBind(&data) - if err != nil { + if err := c.ShouldBind(&data); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } diff --git a/main.go b/main.go index 86f91d0..518eb70 100644 --- a/main.go +++ b/main.go @@ -24,8 +24,7 @@ func main() { } func initShortener() (func(), error) { - err := config.Preload() - if err != nil { + if err := config.Preload(); err != nil { return nil, errors.Wrap(err, "could not get config") } conf := config.Get() @@ -38,14 +37,12 @@ func initShortener() (func(), error) { return nil, errors.Wrap(err, "could not create handlers") } go func() { - err := handler.Listen() - if err != nil { + if err := handler.Listen(); err != nil { log.Fatalf("could not listen to http handlers: %v", err) } }() return func() { - err = handler.CloseStore() - if err != nil { + if err = handler.CloseStore(); err != nil { log.Printf("failed to stop the handlers: %v", err) } }, nil diff --git a/store/store.go b/store/store.go index 3e0cdf8..8f343d4 100644 --- a/store/store.go +++ b/store/store.go @@ -70,8 +70,7 @@ func (s *Store) GetEntryByID(id string) (*Entry, error) { return nil, err } var entry *Entry - err = json.Unmarshal(raw, &entry) - return entry, err + return entry, json.Unmarshal(raw, &entry) } // IncreaseVisitCounter increments the visit counter of an entry @@ -88,8 +87,7 @@ func (s *Store) IncreaseVisitCounter(id string) error { } err = s.db.Update(func(tx *bolt.Tx) error { bucket := tx.Bucket(s.bucketName) - err := bucket.Put([]byte(id), raw) - if err != nil { + if err := bucket.Put([]byte(id), raw); err != nil { return errors.Wrap(err, "could not put data into bucket") } return nil diff --git a/store/store_test.go b/store/store_test.go index 0fcc470..e81743d 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -106,8 +106,7 @@ func TestIncreaseVisitCounter(t *testing.T) { if err != nil { t.Fatalf("could not get entry by id: %v", err) } - err = store.IncreaseVisitCounter(id) - if err != nil { + if err = store.IncreaseVisitCounter(id); err != nil { t.Fatalf("could not increase visit counter %v", err) } entryAfterInc, err := store.GetEntryByID(id) @@ -117,8 +116,7 @@ func TestIncreaseVisitCounter(t *testing.T) { if entryBeforeInc.VisitCount+1 != entryAfterInc.VisitCount { t.Fatalf("the increasement was not successful, the visit count is not correct") } - err = store.IncreaseVisitCounter("") - if err != ErrIDIsEmpty { + if err = store.IncreaseVisitCounter(""); err != ErrIDIsEmpty { t.Fatalf("could not get expected '%v' error: %v", ErrIDIsEmpty, err) } } diff --git a/store/util.go b/store/util.go index 483b2e0..c974f40 100644 --- a/store/util.go +++ b/store/util.go @@ -30,8 +30,7 @@ func (s *Store) createEntryRaw(key, value []byte) error { if raw != nil { return errors.New("entry value is not empty") } - err := bucket.Put(key, value) - if err != nil { + if err := bucket.Put(key, value); err != nil { return errors.Wrap(err, "could not put data into bucket") } return nil