重构项目
This commit is contained in:
@@ -61,7 +61,7 @@ func (p *ProviderDummy) Branches(_ context.Context, owner, repo string) (map[str
|
||||
return branches, nil
|
||||
}
|
||||
|
||||
func (p *ProviderDummy) Open(_ context.Context, _ *http.Client, owner, repo, commit, path string, _ http.Header) (*http.Response, error) {
|
||||
func (p *ProviderDummy) Open(_ context.Context, owner, repo, commit, path string, _ http.Header) (*http.Response, error) {
|
||||
open, err := os.Open(filepath.Join(p.BaseDir, owner, repo, commit, path))
|
||||
if err != nil {
|
||||
return nil, errors.Join(err, os.ErrNotExist)
|
||||
|
||||
@@ -7,10 +7,12 @@ import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
"gopkg.d7z.net/gitea-pages/pkg"
|
||||
"gopkg.d7z.net/middleware/cache"
|
||||
"gopkg.d7z.net/middleware/kv"
|
||||
)
|
||||
|
||||
@@ -34,7 +36,10 @@ func NewTestServer(domain string) *TestServer {
|
||||
if err != nil {
|
||||
zap.S().Fatal(err)
|
||||
}
|
||||
|
||||
memoryCache, _ := cache.NewMemoryCache(cache.MemoryCacheConfig{
|
||||
MaxCapacity: 256,
|
||||
CleanupInt: time.Minute,
|
||||
})
|
||||
memoryKV, _ := kv.NewMemory("")
|
||||
server := pkg.NewPageServer(
|
||||
http.DefaultClient,
|
||||
@@ -44,6 +49,7 @@ func NewTestServer(domain string) *TestServer {
|
||||
memoryKV,
|
||||
memoryKV.Child("cache"),
|
||||
0,
|
||||
memoryCache,
|
||||
func(w http.ResponseWriter, r *http.Request, err error) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
http.Error(w, "page not found.", http.StatusNotFound)
|
||||
|
||||
Reference in New Issue
Block a user