initial commit

This commit is contained in:
Serge Zaitsev
2018-09-19 11:20:09 +02:00
parent 95a937ef2c
commit ce767e10ee
11 changed files with 918 additions and 1 deletions

41
pkg/store/mem.go Normal file
View File

@@ -0,0 +1,41 @@
package store
import (
"context"
"errors"
"sync"
"github.com/sixt/gomodproxy/pkg/vcs"
)
type memory struct {
sync.Mutex
cache []Snapshot
}
func Memory() Store { return &memory{} }
func (m *memory) Put(ctx context.Context, snapshot Snapshot) error {
m.Lock()
defer m.Unlock()
for _, item := range m.cache {
if item.Module == snapshot.Module && item.Version == snapshot.Version {
return nil
}
}
m.cache = append(m.cache, snapshot)
return nil
}
func (m *memory) Get(ctx context.Context, module string, version vcs.Version) (Snapshot, error) {
m.Lock()
defer m.Unlock()
for _, snapshot := range m.cache {
if snapshot.Module == module && snapshot.Version == version {
return snapshot, nil
}
}
return Snapshot{}, errors.New("not found")
}
func (m *memory) Close() error { return nil }