Skip to content

Commit

Permalink
fix nil ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
Sianao committed Nov 26, 2024
1 parent b41b7ab commit 2d8ee4c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package cache
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
"io"
"log"
"net/http"
"os"
"path/filepath"

"github.com/redis/go-redis/v9"
)

const (
Expand Down Expand Up @@ -70,16 +71,24 @@ func (c *Redis) Upgrade(key string) {
log.Println(r)
}
}()
resp, _ := http.Get("https://" + key)
if c.Nil() {
return
}
resp, err := http.Get("https://" + key)
if err != nil {
log.Println("get err ", err)
return
}
if resp.StatusCode != 200 {
fmt.Println(resp.StatusCode)
}
os.MkdirAll(filepath.Dir("cache/"+key), os.ModePerm)
fd, _ := os.Create("cache/" + key)
io.Copy(fd, resp.Body)
resp.Body.Close()

c.db.HIncrBy(context.Background(), Old, key, 1)
c.c <- key
}()
c.c <- key

}

0 comments on commit 2d8ee4c

Please sign in to comment.