feat: add tarballs caching

This commit is contained in:
 Ilya Atamas
2019-04-23 15:36:51 +03:00
parent d04603f529
commit 18338eb0d7
4 changed files with 31 additions and 24 deletions

View File

@@ -2,6 +2,7 @@ package proxy
import (
"net/http"
"strings"
"time"
ginzap "github.com/gin-contrib/zap"
@@ -32,14 +33,7 @@ func (proxy Proxy) Server(options ServerOptions) *http.Server {
}
func (proxy Proxy) getPackageHandler(c *gin.Context) {
var name string
if c.Param("name") != "" {
name = c.Param("scope") + "/" + c.Param("name")
} else {
name = c.Param("scope")
}
pkg, err := proxy.GetMetadata(name, c.Request.URL.Path, c.Request)
pkg, err := proxy.GetCachedPath(c.Request.URL.Path, c.Request)
if err != nil {
c.AbortWithError(500, err)
@@ -49,8 +43,20 @@ func (proxy Proxy) getPackageHandler(c *gin.Context) {
}
}
func (proxy Proxy) getTarballHabdler(c *gin.Context) {
pkg, err := proxy.GetCachedPath(c.Request.URL.Path, c.Request)
if err != nil {
c.AbortWithError(500, err)
} else {
c.Data(200, "application/json", pkg)
}
}
func (proxy Proxy) noRouteHandler(c *gin.Context) {
if c.Request.URL.Path == "/" {
if strings.Contains(c.Request.URL.Path, ".tgz") {
proxy.getTarballHabdler(c)
} else if c.Request.URL.Path == "/" {
err := proxy.Database.Health()
if err != nil {