Skip to content

Commit

Permalink
remove deprecated cache
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan13888 <29968201+Nathan13888@users.noreply.github.com>
  • Loading branch information
Nathan13888 committed Jul 19, 2023
1 parent 157b101 commit 0b6fc10
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 129 deletions.
31 changes: 1 addition & 30 deletions badges.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strconv"

"github.com/rs/zerolog/log"
)
Expand Down Expand Up @@ -103,36 +101,9 @@ func getErrorBadge() []byte {
}

func updateCounter(useCache bool, hash string) string {
if !useCache {
// return updateCountAPI(hash)
return updateRedis(hash)
}
// look up cache
return updateCachedCount(hash) // note that this will return the CountAPI count if hash does not exist
return updateRedis(hash)
}

func updateRedis(hash string) string {
return QueryHash(hash)
}

// DEPRECATED:
func updateCountAPI(hash string) string {
url := "https://api.countapi.xyz/hit/visitor-badge/" + hash
res, err := http.Get(url)
// TODO: fix header content check
// cont := res.Header.Get("Content-Type")
// if cont != "application/json" {
// log.Fatal("Did not receive expected JSON response. Received: " + cont)
// }
if err != nil {
logError(err)
}
defer res.Body.Close()

var obj CountAPIResponse
decoder := json.NewDecoder(res.Body)
decoder.DisallowUnknownFields()
decoder.Decode(&obj)

return strconv.Itoa(obj.Value)
}
96 changes: 0 additions & 96 deletions cache.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.15
require (
github.com/allegro/bigcache v1.2.1
github.com/gorilla/mux v1.8.0
github.com/redis/go-redis/v9 v9.0.5 // indirect
github.com/redis/go-redis/v9 v9.0.5
github.com/rs/zerolog v1.26.0
github.com/stretchr/testify v1.7.0 // indirect
)
2 changes: 0 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func main() {
r.Use(loggingMiddleware)

log.Info().Msg("Configuring cache")
initCache()
startTime = time.Now()

// Run our server in a goroutine so that it doesn't block.
Expand Down Expand Up @@ -226,7 +225,6 @@ func getPing(w http.ResponseWriter, r *http.Request) {
func getStatus(w http.ResponseWriter, r *http.Request) {
// TODO: include redis
res := StatusResponse{
CachedHashes: cache.Len(),
ProcessedRequests: processedBadges,
Uptime: int64(time.Since(startTime).Seconds()),
CodeRepository: "https://github.com/Nathan13888/VisitorBadgeReloaded",
Expand Down

0 comments on commit 0b6fc10

Please sign in to comment.