Skip to content

Commit

Permalink
fix incr err
Browse files Browse the repository at this point in the history
  • Loading branch information
Sianao committed Nov 26, 2024
1 parent 2d8ee4c commit 10902b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
8 changes: 5 additions & 3 deletions router/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package router

import (
"fmt"
"github.com/dustin/go-humanize"
"github.com/sianao/gitproxy/cache"
"net/http"
"strconv"
"strings"

"github.com/dustin/go-humanize"
"github.com/sianao/gitproxy/cache"

"github.com/gorilla/mux"
"github.com/sianao/gitproxy/moudule"
"github.com/sianao/gitproxy/service"
Expand Down Expand Up @@ -86,7 +87,7 @@ func NewRouter(c *cache.Redis) *mux.Router {
userBaisc[0], userBaisc[1], r.URL.Path)
path := fmt.Sprintf("raw.githubusercontent.com/%s/%s%s",
userBaisc[0], userBaisc[1], r.URL.Path)
c.Incr(path)

if c.Exists(path) {
r.URL.Path = path
http.FileServer(http.Dir("./cache/")).ServeHTTP(w, r)
Expand All @@ -102,6 +103,7 @@ func NewRouter(c *cache.Redis) *mux.Router {

return
}
c.Incr(path)
service.PacketProxy(w, r, address)

})
Expand Down
16 changes: 2 additions & 14 deletions service/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package service

import (
"fmt"
"github.com/dustin/go-humanize"
"io"
"net/http"
"strconv"

"github.com/dustin/go-humanize"
)

func PacketProxy(w http.ResponseWriter, r *http.Request, address string) {
Expand Down Expand Up @@ -35,16 +36,3 @@ func PacketProxy(w http.ResponseWriter, r *http.Request, address string) {
w.WriteHeader(resp.StatusCode)
io.Copy(w, resp.Body)
}

// // StatusCode is HTTP response code.
// StatusCode int
// // Latency is how much time the server cost to process a certain request.
// Latency time.Duration
// // ClientIP equals Context's ClientIP method.
// ClientIP string
// // Method is the HTTP method given to the request.
// Method string
// // Path is a path the client requests.
// Path string
// // ErrorMessage is set if error has occurred in processing the request.
// ErrorMessage string

0 comments on commit 10902b9

Please sign in to comment.