update
This commit is contained in:
27
internal/hubmodule/golang/hooks.go
Normal file
27
internal/hubmodule/golang/hooks.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package golang
|
||||
|
||||
import "github.com/any-hub/any-hub/internal/proxy/hooks"
|
||||
|
||||
import "strings"
|
||||
|
||||
func init() {
|
||||
hooks.MustRegister("go", hooks.Hooks{
|
||||
CachePolicy: cachePolicy,
|
||||
})
|
||||
}
|
||||
|
||||
func cachePolicy(_ *hooks.RequestContext, locatorPath string, current hooks.CachePolicy) hooks.CachePolicy {
|
||||
if strings.Contains(locatorPath, "/@v/") &&
|
||||
(strings.HasSuffix(locatorPath, ".zip") ||
|
||||
strings.HasSuffix(locatorPath, ".mod") ||
|
||||
strings.HasSuffix(locatorPath, ".info")) {
|
||||
current.AllowCache = true
|
||||
current.AllowStore = true
|
||||
current.RequireRevalidate = false
|
||||
return current
|
||||
}
|
||||
current.AllowCache = true
|
||||
current.AllowStore = true
|
||||
current.RequireRevalidate = true
|
||||
return current
|
||||
}
|
||||
19
internal/hubmodule/golang/hooks_test.go
Normal file
19
internal/hubmodule/golang/hooks_test.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package golang
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/any-hub/any-hub/internal/proxy/hooks"
|
||||
)
|
||||
|
||||
func TestCachePolicyForModuleFiles(t *testing.T) {
|
||||
policy := cachePolicy(nil, "/example/@v/v1.0.0.zip", hooks.CachePolicy{})
|
||||
if !policy.AllowCache || policy.RequireRevalidate {
|
||||
t.Fatalf("expected immutable go artifacts to be cacheable without revalidate")
|
||||
}
|
||||
|
||||
policy = cachePolicy(nil, "/example/@latest", hooks.CachePolicy{})
|
||||
if !policy.RequireRevalidate {
|
||||
t.Fatalf("expected non-artifacts to require revalidate")
|
||||
}
|
||||
}
|
||||
28
internal/hubmodule/golang/module.go
Normal file
28
internal/hubmodule/golang/module.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package golang
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/any-hub/any-hub/internal/hubmodule"
|
||||
)
|
||||
|
||||
const goDefaultTTL = 30 * time.Minute
|
||||
|
||||
func init() {
|
||||
hubmodule.MustRegister(hubmodule.ModuleMetadata{
|
||||
Key: "go",
|
||||
Description: "Go module proxy with sumdb/cache defaults",
|
||||
MigrationState: hubmodule.MigrationStateBeta,
|
||||
SupportedProtocols: []string{
|
||||
"go",
|
||||
},
|
||||
CacheStrategy: hubmodule.CacheStrategyProfile{
|
||||
TTLHint: goDefaultTTL,
|
||||
ValidationMode: hubmodule.ValidationModeLastModified,
|
||||
DiskLayout: "raw_path",
|
||||
RequiresMetadataFile: false,
|
||||
SupportsStreamingWrite: true,
|
||||
},
|
||||
LocatorRewrite: hubmodule.DefaultLocatorRewrite("go"),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user