Added storage
This commit is contained in:
2
internal/services/actions/action.go
Normal file
2
internal/services/actions/action.go
Normal file
@@ -0,0 +1,2 @@
|
||||
package action
|
||||
|
7
internal/services/storage/models.go
Normal file
7
internal/services/storage/models.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package storage
|
||||
|
||||
type (
|
||||
Area struct {
|
||||
Path string
|
||||
}
|
||||
)
|
60
internal/services/storage/storage.go
Normal file
60
internal/services/storage/storage.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// The idea behind storage is that we have file dir, with a git repo.
|
||||
// This file repo can now take certain actions
|
||||
|
||||
type StorageConfig struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
func NewDefaultStorageConfig() (*StorageConfig, error) {
|
||||
tempDir, err := os.MkdirTemp(os.TempDir(), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &StorageConfig{
|
||||
Path: path.Join(tempDir, "kraken"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
cfg *StorageConfig
|
||||
}
|
||||
|
||||
func NewService(cfg *StorageConfig) *Service {
|
||||
return &Service{cfg: cfg}
|
||||
}
|
||||
|
||||
func (s *Service) getStoragePath(ctx context.Context) string {
|
||||
return path.Join(s.cfg.Path, "storage")
|
||||
}
|
||||
|
||||
func (s *Service) InitializeStorage(ctx context.Context) error {
|
||||
return os.MkdirAll(s.getStoragePath(ctx), 0755)
|
||||
}
|
||||
|
||||
func (s *Service) CleanupStorage(ctx context.Context) error {
|
||||
return os.RemoveAll(s.getStoragePath(ctx))
|
||||
}
|
||||
|
||||
func (s *Service) CreateArea(ctx context.Context) (*Area, error) {
|
||||
dir, err := os.MkdirTemp(s.getStoragePath(ctx), "*")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Area{
|
||||
Path: dir,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) RemoveArea(ctx context.Context, area *Area) error {
|
||||
return os.RemoveAll(area.Path)
|
||||
}
|
Reference in New Issue
Block a user